Hooks — toast, preferences, currency, environment, offline queue
Every hook here is live: fire a toast and watch the store, type a preference and reload the page. A hook demonstrated only in a code block is a hook nobody has seen work.
useToast — transient notification state
A store, not a renderer. It returns the live toasts array and you render it — so the SDK never imposes a toast position or animation on an app that wants its own. Fire one and watch the array below change.
No active toasts. The array is empty — not null, and not an error.
usePreference — durable user settings
Reads and writes one keyed preference. Pass saveFn and it also syncs to your backend, debounced by debounceMs. Type below, reload the page, and the value survives.
useCurrency
Formats through Intl in the active locale and configured currency. toFixed(2) with a hardcoded symbol is wrong in most locales — the separator, the symbol and its position all move.
| format(0) | $0.00 |
| format(9.5) | $9.50 |
| format(1234.5) | $1,234.50 |
| format(1234567.891) | $1,234,567.89 |
| format(-42) | -$42.00 |
useEnvironment
Which tier the app is running in. Use it to gate destructive affordances and to label non-production clearly — an operator who cannot tell prod from dev will eventually act on the wrong one.
- NEXT_PUBLIC_BRAND = martlet
useOfflineQueue — work that survives a dropped link
Queues actions while offline and replays them on reconnect. The important property is that a failed send is held, not discarded — an action that silently vanishes because the network blinked is the worst kind of data loss, because nobody is told.
Throttle to offline in devtools, enqueue a few, then restore the connection.