set
Method to update the state value in a Signify instance.
Description
The set
method allows you to update the state value either by providing a new value directly or by using a callback function that receives the current state and allows you to modify it. The update will trigger re-renders in components that use this state.
Input/Output
Input | Type | Description |
---|---|---|
value | T | TSetterCallback<T> | New value or callback function to update state |
Output | Type | Description |
---|---|---|
Returns | void | No return value |
Callback Function Type
Parameter | Type | Description |
---|---|---|
params | { value: T } | Object containing the current state value |
Example
typescript
import { signify } from 'react-signify';
const sCounter = signify(0);
// Direct value update
sCounter.set(5);
// Update using callback
sCounter.set((pre) => {
pre.value += 1;
});
// Update object state
const sUser = signify({ name: 'John', age: 25 });
sUser.set((pre) => {
pre.value.age = 26;
});