With Cerberus Signals, you can create global (signal-based) stores that manage data and actions in a single place. Sometimes, you may want this scoped to an application or component instance.
For this use case, we have the createStoreContext primitive.
This primitive will create both a Provider and getter hook heavily typed to the store data passed in.
In this demo we have a global store that manages signals. We then generate the context
APIs and pass the MyStore type so we obtain strict type accountability.
In our main component we use the StoreProvider and pass our store to the
createStore prop.
In the child component we utilize the useStore hook to gain access to the store.
Note
Remember that anytime you want to read a signal from a primitive - you need to either use ReactiveText or useRead to subscribe to the signal.
createStoreContext doesn't accepts the following props:
| Property | Type | Description |
|---|---|---|
name | string | Optional. The name of the store to assign as the context display name. |
createStoreContext returns an Object with two properties:
| Property | Type | Description |
|---|---|---|
StoreProvider | ElementType | The React Context Provider for the store. |
useStore | () => T | A function to get the store context. |
Selected: