5 ms·
Slightly dismissive, but I agree the setInterval function was a little misleadingly contrived. The transition to functional components was to reduce the coupli
by MiddleMan5 5y ago
Slightly dismissive, but I agree the setInterval function was a little misleadingly contrived.
The transition to functional components was to reduce the coupling between abstract functionality and DOM-related lifecycle events.
React hooks are mostly about expressing where and when you want to memoize a value, with the default being not to.
Once you learn what to look out for, and properly designing and review codebases at scale, these trivial issues don't happen all that often. Additionally, being able to specify memoization parameters explicitly brings extra flexibility and some additional design patterns.
- stupidcar 5y agoWhat are you talking about? The setInterval example is completely idiomatic React hooks. It is literally given in the React docs: https://reactjs.org/docs/hooks-faq.html#what-can-i-do-if-my-effect-dependencies-change-too-often https://reactjs.org/docs/hooks-faq.html#what-can-i-do-if-my-...
- MiddleMan5 5y agoReading it now, the language I used was inappropriate. You're correct, the stated problem is common with registering and triggering self-repeating and timed loops. That was really my point, don't do that.