Derived signals
Edit this pageDerived signals are functions that rely on one or more signals to produce a value.
These functions are not executed immediately, but instead are only called when the values they rely on are changed. When the underlying signal is changed, the function will be called again to produce a new value.
In the above example, the double
function relies on the count
signal to produce a value.
When the count
signal is changed, the double
function will be called again to produce a new value.
These dependent functions gain reactivity from the signal they access, ensuring that changes in the underlying data propagate throughout your application. It is important to note that these functions do not store a value themselves; instead, they can update any effects or components that depend on them. If included within a component's body, these derived signals will trigger an update when necessary.
While you can create derived values in this manner, Solid created the createMemo
primitive.
Learn more about memos.