react web game : 지뢰찾기 - 타이머

This commit is contained in:
haerong22
2021-03-24 22:04:53 +09:00
parent ed5dc9f01c
commit a3af80205c

View File

@@ -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 />