useOptimistic ​
Hook that allows get optimistic value before its update
utilities
test coverage
Last changed: last month
Installation ​
Library
CLI
Manual
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 |
Returns
UseOptimisticReturn<State>
Type declaration ​
typescript
export type UseOptimisticReturn<State> = [
State,
(optimisticValue: State, promise: Promise<any>) => void
];
Source ​
Source • DemoContributors ​
D
M