useOptimistic ​
Hook that allows get optimistic value before its update
typescript
import { useOptimistic } from '@siberiacancode/reactuse';
Usage ​
typescript
const [optimisticValue, updateOptimistic] = useOptimistic<number>(count, (currentState, optimisticValue) => currentState + optimisticValue);
Demo ​
Api ​
Parameters
Name | Type | Default | Note |
---|---|---|---|
state | State | - | The value to be returned initially and whenever no action is pending |
update | (currentState: State, optimisticValue: State) => State | - | A pure function that takes the current state and the optimistic value passed to updateOptimistic and returns the resulting optimistic state |