News for hackers. Stuff that matters.
Re:Making SetInterval Declarative with React Hooks by panic on Monday February 04, 2019 @02:17AM (#19074537)
Resetting the interval when the delay changes is probably not what you want either -- quickly changing the delay (even a little bit) won't give the timer a chance to fire. It would be better to compute a deadline internally, then move the deadline forward or backward according to how much the delay changed since the last call.
Re:Making SetInterval Declarative with React Hooks by danabramov on Monday February 04, 2019 @06:21AM (#19075431)
Good thing something like useInterval() can abstract these implementation details away so it can be made more precise with time. :-)
Re:Making SetInterval Declarative with React Hooks by zurfyx on Monday February 04, 2019 @03:21AM (#19074756)
A setInterval/setTimeout can only be cleared (clearInterval/clearTimeout). Modifications have to pushed through clear -> set.