Skip to content

useOptimistic ​

utilities
test coverage
Last changed: last month

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

Source ​

Source • Demo

Contributors ​

Avatardebabin
AvatarMichael Mironychev

Released under the MIT License.