Appearance
useRafState
State updates coalesced into an animation frame.
Demo
Usage
tsx
import { useRafState } from '@reause/shared'
const [state, setRafState] = useRafState(0)
// three calls inside one frame: a single re-render, with `state === 3`
setRafState(1)
setRafState(2)
setRafState(3)Type Declarations
ts
export function useRafState<S>(initialState: S | (() => S)): [
S,
Dispatch<SetStateAction<S>>
]