Skip to content

useOptimistic ​

Category
Utilities

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

NameTypeDefaultNote
stateState-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

Contributors ​

Source • Demo