Overview
onError(fn) registers an error handler on the current component host. When the outer function or template throws during render, every registered handler receives the error. Use it to report (e.g. Sentry) and to flip local atoms that drive fallback UI.
onPaint(fn) runs after each paint of the current component and its children — on initial mount and on every subsequent update. Safe for layout reads (getBoundingClientRect, scroll position) and imperative post-paint work. If fn returns a function, that cleanup runs before the next paint or on unmount.
Both hooks are lifecycle registrations: call them once in the outer function. They are not substitutes for reactive rendering — keep templates pure and push side effects into these hooks.
onError vs onPaint
|
API
|
Fires when
|
Typical use
|
|---|---|---|
onError(fn)
| Render/setup throw |
Report errors; set atoms for fallback UI. Handler returns void.
|
onPaint(fn)
| After every paint | Measure layout, sync imperative DOM, start paint-tied animations. Optional cleanup return. |
onError — component error boundary
onError catches errors thrown during this component's render or setup. Use the handler to update atoms that drive fallback UI (as shown) and/or report the error.
onPaint — read DOM after paint
onPaint runs after every paint of the component subtree. Use it for layout measurements or post-paint imperative work. Guard reactive writes so you don't loop.