use_signal
Creates a new Signal. Signals are a Copy state management solution with automatic dependency tracking.Signature
Parameters
Initialization function that returns the initial value for the signal. This function is only called once when the component is first created.
Returns
A copyable signal handle that can be used to read and write the state value. The signal automatically tracks dependencies and triggers re-renders when the value changes.
Description
Signals provide automatic dependency tracking for reactive state management. When you read from a signal inside a component, that component automatically subscribes to updates. When the signal’s value changes, only the components that read from it will re-render. Because signals implementCopy, they can be used in async blocks and closures without explicit cloning.
This hook should only be called inside component functions or other hooks. Calling it outside of the component lifecycle will cause memory leaks.
Example
Basic counter with automatic dependency tracking:Related
use_signal_sync- Create aSend + Syncsignal for use across threadsuse_effect- Run side effects when signals changeuse_memo- Compute derived values from signals