custom hooks and dependency arrays in useEffect
I have been practicing creating custom hooks and I encountered this challenge on react.dev. it requires to create a custom hook that displays a number that increments every second.
I have written the useEffect with an empty dependency and without dependency, the component renders the same amount of times.
my question would be, why, when there is an empty dependency array, the count works and the component re-renders?
is it due to the setInterval function?
I am trying to understand how setInterval works inside useEffect, although useEffect runs only once, the setInterval forces the component to re-render. 🤔
2
2 comments
Mioara Cenusa
7
custom hooks and dependency arrays in useEffect
Developer Pro
skool.com/developerpro
Learn how to code. Make money. Have fun. Enjoy life.
Leaderboard (30-day)
Powered by