Basic Usage
Function Signature
Sync Variant
For signals that need to beSend + Sync (e.g., used across threads):
Reading Signals
Subscribing Read
Reading a signal subscribes the current component to updates:Non-subscribing Read
Usepeek() to read without subscribing:
Writing Signals
Basic Writes
Mutable Access
Copy Semantics
Signals implementCopy, making them easy to use in closures:
Automatic Dependency Tracking
Components only rerender when signals they read change:Working with Complex Types
Nested Data
Collections
Common Patterns
Toggle Boolean
Computed Values
For derived state, useuse_memo instead of manually computing:
Async Updates
Type Aliases
Important Notes
- Signals should only be created inside hooks or initialization closures
- Creating signals in component bodies on every render will leak memory
- Signals are owned by the component scope and dropped with it
- Reading a signal in an effect subscribes the effect to that signal
- Use
peek()to read without subscribing when needed
Related
- use_effect - Run side effects when signals change
- context - Share signals across component boundaries
- global-state - Application-wide signals
- stores - Fine-grained reactivity for nested data