Creates a stateful value with an associated side-effect that runs whenever the state is updated.
The type of the state value.
The initial value of the state.
A function to run with the new and (optionally) previous value after each update.
A tuple containing a getter and a setter for the state.
const [getCount, setCount] = createState(0, (value, prev) => { console.log('Count changed from', prev, 'to', value);});setCount(1); // Logs: Count changed from 0 to 1console.log(getCount()); // 1 Copy
const [getCount, setCount] = createState(0, (value, prev) => { console.log('Count changed from', prev, 'to', value);});setCount(1); // Logs: Count changed from 0 to 1console.log(getCount()); // 1
Creates a stateful value with an associated side-effect that runs whenever the state is updated.