useEffect useState Timer

PHOTO EMBED

Thu Jul 01 2021 09:18:14 GMT+0000 (Coordinated Universal Time)

Saved by @Sensei_p #commandline

    useEffect(() => {
        if(timeRemaining > 0) {
            setTimeout(() => {
                setTimeRemaining(time => time - 1)
            }, 1000)
        }
    }, [timeRemaining])
content_copyCOPY

Is triggered onClick and continues to fire due to the dependancy array watching the state variable.