React hooks useEffect with a condition timer

Viewed 121

Is the below code correct when useEffect has a condition setTimout?

useEffect(() => {
    if (condition) {
        const timer = setTimeout(() => {
            func1()
        }, 1000)
        return () => {
            clearTimeout(timer)
        }
    }
    func2()
    return () => {}
}, [])
0 Answers
Related