New to React (I've only read about it) so I may be wrong (and if I am, I'd like to know why) but I don't think you need the changeTime function in your hooks example, you can call setTime directly which would reduce it even further. Is it just a question of code style?
If setTime() is added to useEffect() then it'll have to be added as a dependence also. This could trigger useEffect many times if setTime() is used else where and create an endless loop.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
New to React (I've only read about it) so I may be wrong (and if I am, I'd like to know why) but I don't think you need the changeTime function in your hooks example, you can call setTime directly which would reduce it even further. Is it just a question of code style?
useEffect(() => {
const tick = setInterval(() => {
setTime(new Date())
}, 1000)
return () => clearInterval(tick)
})
It's good practice to decouple your code
If setTime() is added to useEffect() then it'll have to be added as a dependence also. This could trigger useEffect many times if setTime() is used else where and create an endless loop.