When you want to create a signal outside of a component context. This can be used globally, in a store, or any other way your purpose needs.
There are two ways to read a global signal within a component:
ReactiveText (recommended) for fine-grained reactivityuseRead hook for manual consumptioncreateSignal works just like useSignal on a non-component scale.
The easiest way to read the state of primitive-based signal is the ReactiveText
component which provided fine-grained reactivity control.
When you don't care about fine-grained reactivity, you can use the useRead hook.
With Cerberus Signals, how you set the state no longer matters. You are free to use mutation or immutability. Both results will yield the same high performant and reliable reactivity.
In this example we utilize the createComputed primitive to create a reactive
signal which provides a computational value. This is similar to the native React
useMemo hook.
When storing Objects or Arrays (any non-Primitiva value) in a signal, we recommend using immutable updates when setting new values. Doing so will ensure the best performance outcome since the graph uses strict equality (!==) to detect changes.
You can create global stores to read and manage state across your entire application, or simply devote to a single feature (this is how the Data Grid is designed).
This allows you to have an "multi-signal" and action based solution that will both improve React rendering performance and code scalability.
createSignal accepts the following options:
| Params | Required | Description |
|---|---|---|
initialValue | false | The initial value to set for the accessor. |
createSignal returns a SignalTuple<T> Array of the following values:
| Index | Type | Description |
|---|---|---|
| 0 | Accessor<T> | A function that returns the latest value when called. |
| 1 | Setter<T> | A function to update the signal value. |
Render Count:
10
Render Count:
1