useRafState
Updates state inside requestAnimationFrame.
Usage
import { useRafState } from "@siberiacancode/reactuse";
const [value, setValue] = useRafState(0);Example
const [value, setValue] = useRafState(0);
return <button onClick={() => setValue(value + 1)}>Value: {value}</button>;initialValue:
const [value, setValue] = useRafState(() => 0);Notes
- Hook uses the requestAnimationFrame API.
Type Declarations
export type UseRafStateReturn<Value> = [Value, (value: Value) => void];
export declare const useRafState: <Value>(
initialValue: (() => Value) | Value
) => readonly [Value, (value: Value) => void];