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.
createStoreContext doesn't accept any parameters and is essentially just a factory.
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: