react web game : 지뢰찾기 - 타이머
This commit is contained in:
@@ -263,7 +263,12 @@ const reducer = (state, action) => {
|
||||
tableData,
|
||||
};
|
||||
}
|
||||
|
||||
case INCREMENT_TIMER: {
|
||||
return {
|
||||
...state,
|
||||
timer: state.timer + 1,
|
||||
};
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
@@ -278,6 +283,18 @@ const MineSearch = () => {
|
||||
[tableData, halted]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
let timer;
|
||||
if (!halted) {
|
||||
timer = setInterval(() => {
|
||||
dispatch({ type: INCREMENT_TIMER });
|
||||
}, 1000);
|
||||
}
|
||||
return () => {
|
||||
clearInterval(timer);
|
||||
};
|
||||
}, [halted]);
|
||||
|
||||
return (
|
||||
<TableContext.Provider value={value}>
|
||||
<Form />
|
||||
|
||||
Reference in New Issue
Block a user