3 ms·
Also the id must be hold using useRef(). That's the whole problem with hooks: when things are easy, they are nice. When things are complicated, unfortunately,
by BiteCode_dev 5y ago
Also the id must be hold using useRef().
That's the whole problem with hooks: when things are easy, they are nice. When things are complicated, unfortunately, they look easy, and you start to think you understand what's going on. But most people, me included, don't.
- tuan 5y agoI don't think you need to hold id using useRef(). The cleanup callback holds the id from the same render, so it will clean up the correct interval.
- jitl 5y ago> When things are complicated, unfortunately, they look easy, and you start to think you understand what's going on. But most people, me included, don't. That’s fair. The other side of the coin is that class components have their own kinds of failure modes. I have fixed a lot of buggy class components that simply forget that props change - they do some kind of effect-y thing using the first props during didMount, and then never respond to prop changes aside from `render()`. With hook components, the linter will get mad about that sort of thing. In either case there’s gotchas, but I like that useEffect helps people avoid leaking and think about changing props.