Created
April 2, 2021 06:16
-
-
Save corocoto/4330c3521094417417b06a24433c534e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Next `useEffect` hooks will be working the same | |
useEffect(() => { | |
const id = setInterval(() => { | |
setCount(count + 1) | |
}, 1000) | |
return () => clearInterval(id) | |
}, [count]) | |
useEffect(() => { | |
const id = setInterval(() => { | |
// Когда мы передаем функцию, React вызывает её с | |
// актуальным стейтом и всякий раз в этом случае она же и становится актуальным стэйтом. | |
setCount(count => count + 1) | |
}, 1000) | |
return () => clearInterval(id) | |
}, []); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment