Overview
ThefromActorRef function subscribes to an existing actor and returns a tracked accessor function for its snapshot. It integrates with SolidJS’s reactivity system for fine-grained updates.
Basic Usage
Reactive Actor Reference
You can pass either a static actor ref or an accessor function:Granular Reactivity
The snapshot accessor integrates with SolidJS’s reactivity system:Undefined Handling
The accessor can returnundefined if the actor doesn’t exist:
Selecting Specific Values
Derive specific values from the snapshot:Multiple Snapshots
Subscribe to multiple actors:With Effects
UsecreateEffect to react to snapshot changes:
Comparison with useActor
useActor when you need the full tuple. Use fromActorRef when:
- You already have an actor ref
- You’re working with spawned/child actors
- You need more control over subscriptions
TypeScript
The function is fully typed:Implementation Details
ThefromActorRef function:
- Creates a memo to track the actor ref (if passed as accessor)
- Uses
createImmutableto create a tracked snapshot store - Uses
createEffectto subscribe to actor changes - Updates the store with new snapshots
- Handles actor switching by resubscribing
- Automatically unsubscribes on cleanup via
onCleanup - Returns an accessor function for the current snapshot
Related
useActor
Create and manage actors with tracked snapshots
Solid Integration
Back to Solid integration overview