I'm coding a countdown with Expo
.
I'm using functional components
, so my state
is handled via React's useState
hook.
let [state, setState] = useState({
secondsLeft: 25,
started: false,
});
If I press a Button
it does fire this function:
let onPressHandler = (): void => {
if(!state.started) {
setState({...state, started: true});
setInterval(()=> {
setState({...state, secondsLeft: state.secondsLeft - 1});
console.log(state.secondsLeft);
}, 1000);
}
}
Problem is that each 1000 ms Expo refreshes the app instead of updating the state.
Can you help me, please?