Signals >> Hooks
Signals are a more efficient alternative to React hooks. Signals are objects with a .value
property that allows for updating the value without triggering a complete re-render. This performance improvement is achieved by passing the signal object's reference instead of the actual value. Unlike hooks, signals can be used inside or outside components.
Computed Signals
@preact/signals also provides the computed(fn)
function. This function can be used to compute a signal based on the values of other signals. Computed signals automatically update their values based on changes in other signals, and they are read only.
Global State Management
Signals created using signal()
and computed()
functions are globally accessible when exported from a function. These signals can be modified from any component. To create signals locally within a particular component, useSignal
and useComputed
hooks can be used.
More on Signals