As your app grows you may find the need for a single-source of truth for managing signals in a scalable way. In Cerberus Signals you can achieve this by creating a store.
A store is simply a function that contains mutliple signals and actions which manage those signals. There are no restrictions for what a store is.
A store can use any primitive API in it. This means the potential is limitless for whatever you wish to achieve in a high-performant way that doesn't involve React controlling the scenario.
To create a global store, simply create a function that returns an Object. It can be anything and use any Cerberus Signals Primitive API within it.
To create a store that uses unique instances on a React app/component level, use
the createStoreContext API.
Depending on the complexity and use case of your store, React may "get in the way" of your signal management when using stores within a component.
If you intend on using a store within a component you must follow one of the two designs to ensure React doesn't corrupt your hard work via the render cycles:
If you have a store that can be called on the global scope (outside of a component), then you are good to go. Utilize useRead for iteration and ReactiveText for reading.
If a store must live within a component, then you will need to take precautions to ensure React does not corrupt your store state via wrapping your store in useMemo.
Note
Wrapping your store in useMemo is only required if you are using the useRead hook to obtain the reactive value from a store. If your component is only calling actions or utilizing the ReactiveText component, then it is unneccessary (as shown in the demos in the prior sections).
Since stores are essentially a primitive that contain primitives, you will need
to utilize the ReactiveText or useRead APIs in order to obtain the reactive
values within the scope of any component.
When calling a store within a component and reading a value with useRead you must wrap your store in useMemo to ensure React does not corrupt the signal state.
Selected:
Multiplied: 0