Hooks reference¶
The adapters delegate to the bundled React dispatcher. Hook ordering rules, render purity and dependency identity still matter. Use them at the top level of a component or custom hook.
| Hook | Result / behavior | Important boundary |
|---|---|---|
use_state(initial) |
(value, setter) |
A callable initializer is lazy; a callable setter argument is an updater. |
use_reducer(reducer, initial, initializer=None) |
(state, dispatch) |
Reducer receives previous state and action. |
use_context(context) |
Provider value | Create a stable context outside individual renders. |
use_ref(initial=None) |
Mutable .current |
Ref mutation does not schedule a render. |
use_effect(effect, dependencies=None) |
Post-commit effect | Return None or cleanup, not a coroutine. |
use_layout_effect(effect, dependencies=None) |
Layout-phase effect | Keep work short; browser layout APIs are not present during SSR. |
use_insertion_effect(effect, dependencies=None) |
Insertion-phase effect | Intended for style-insertion integrations. |
use_memo(factory, dependencies) |
Cached result | Cache identity is not a correctness mechanism. |
use_callback(fn, dependencies) |
Callable wrapper | Wrapper exposes stable React identity in dependencies. |
use_id() |
Matching component ID | Use for DOM associations, not record keys. |
use_imperative_handle(ref, factory, dependencies=None) |
Custom ref handle | Commonly paired with a forwarded ref. |
use_sync_external_store(subscribe, get_snapshot, get_server_snapshot=None) |
Current snapshot | Subscribe returns cleanup; unchanged snapshots must remain stable. |
use_transition() |
(pending, start) |
The start callback should do initial transition work synchronously. |
use_deferred_value(value, initial=...) |
Deferred value | Optional initial value is omitted unless supplied. |
use_optimistic(value, reducer=None) |
(optimistic, dispatch) |
Dispatch within an action/transition. |
use_action_state(action, initial, permalink=None) |
(state, dispatch, pending) |
Browser-local async action, not server-function transport. |
use_effect_event(fn) |
Effect event callback | Invoke only from effect logic. |
use_debug_value(value, formatter=None) |
DevTools debug value | DevTools behavior is not fully verified by this alpha suite. |
use(promise_or_context) |
Resolved/context value | Use stable resource promise holders for Python async data. |
use_form_status() |
Browser form status proxy | Must be read by a descendant of the form. |
Dependency arrays¶
None omits the array, [] is an empty array and a sequence lists dependencies.
Object entries preserve Python identity. Include every reactive value used by
the hook rather than mutating an object to avoid a dependency change.
Python async transitions¶
Calling an async def creates a coroutine; its body starts later. If the first
optimistic update is inside that coroutine, it may run after the synchronous
transition context has ended. Use this shape:
def save():
add_optimistic(1)
async def finish():
await send_request()
start_transition(lambda: set_base(lambda previous: previous + 1))
return finish()
# In a component's event handler:
html.button("Save", on_click=lambda: transition(save))
The action function does the initial update before returning the awaitable. The conformance example includes this scenario with a deterministic delay.
See effects, context and refs, forms and async data for usage.