primitives
primitives¶
Signal-based reactive primitives and async Resource helper.
create_signal(value)
¶
Create a reactive signal. Returns (getter, setter).
Works inside or outside components. Inside a stateful component the signal is captured by the render function's closure and persists naturally (no cursor system needed).
Example::
count, set_count = create_signal(0)
print(count()) # 0
set_count(5)
print(count()) # 5
create_effect(fn)
¶
Create an auto-tracking reactive effect.
The effect runs immediately and re-runs whenever any signal read
inside fn changes. on_cleanup may be called inside fn to
register per-run cleanup (runs before re-execution and on disposal).
Inside a component, the effect is automatically disposed on unmount.
create_memo(fn)
¶
Create an auto-tracking computed value. Returns a getter function.
Re-computes only when signals read inside fn change. Inside a component, the underlying computation is disposed on unmount.
Example::
doubled = create_memo(lambda: count() * 2)
print(doubled()) # reactive read
on_mount(fn)
¶
Register a callback to run once after the component mounts.
Must be called during a component's setup phase (the body of a
@component function, before the return).
on_cleanup(fn)
¶
Register a cleanup callback.
- Inside
create_effect: runs before each re-execution and on disposal. - Inside a component's setup phase: runs when the component unmounts.
get_props()
¶
Return a reactive getter for the current component's props.
Useful in stateful components that need to react to parent prop changes::
props = get_props()
create_effect(lambda: print("query changed:", props()["query"]))