I need the auto re-rendering every 6s and I defined the component like the following.
const KioskPage = () => {
const [time, setTime] = useState(Date.now())
useEffect(() => {
timeInterval = setInterval(() => setTime(Date.now()), 60000)
return () => {
clearInterval(timeInterval)
}
}, [])
}
but I got the notification :
Assignments to the 'timeInterval' variable from inside React Hook useEffect will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside useEffect react-hooks/exhaustive-deps
Why this happen? and How can I fix this issue?
Regards