Overview
onInterval and onTimeout wrap setInterval / setTimeout and clear themselves when the component unmounts — no manual clearInterval / clearTimeout.
Both must be called in the outer (setup) function. Handlers may return a per-tick cleanup that runs before the next fire and on unmount.
Timer hooks
|
API
|
Behavior
|
Cleanup
|
|---|---|---|
onInterval(fn, ms)
| Repeats every ms | Interval cleared on unmount; optional per-tick cleanup. |
onTimeout(fn, ms)
| Fires once after ms | Cancelled on unmount if not yet fired. |
onInterval — live clock
onInterval schedules a repeating callback at the given millisecond interval. The interval is automatically cleared when the component unmounts.
onTimeout — delayed message
onTimeout fires a callback once after the given delay. If the component unmounts before the timer fires, the timeout is automatically cancelled.