Skip to content

useRafState

Category
Export Size
209 B
Last Changed
5 days ago

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>>
]

Source

Source · Demo · react-use

Contributors

hairyf

Changelog

v0.1.6 on
60016 - fix(shared): use the in-vocabulary Animation category for useRafState (#928)
81ad2 - feat(shared): add useRafState (#928)

Released under the MIT License. v0.1.8