Making SetInterval Declarative with React Hooks
Unlike the class version, there is no complexity gap for “upgrading” the Hook example to have a dynamically adjusted delay:
When Hook sees a different delay, it sets up the interval again. Hooks let us apply the same declarative approach to effects:
We don’t set the interval, but specify whether it is set and with what delay. For example, we can have a of one interval be controlled by another:
Hooks take some getting used to — and especially at the boundary of imperative and declarative code.
Source: overreacted.io