Skip to content

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

InputTypeDescription
valueT | TSetterCallback<T>New value or callback function to update state
OutputTypeDescription
ReturnsvoidNo return value

Callback Function Type

ParameterTypeDescription
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;
});

Released under the MIT License.