UseDebouncedState
Debounce value changes with minimal renders
Usage
Code EditorCopyimport { useDebouncedState } from '@erudilabs/alma'
const [value, setValue] = useDebouncedState('', 200);
Debounced state:
Code EditorCopy<> <TextInput name="debounced-state-demo-input" label="Enter value to see debounce effect" defaultValue={value} onChange={(event) => setValue(event.currentTarget.value)} /> <div className="mt-4"> <p>Debounced value: {value}</p> </div> </>
Definition
Code EditorCopyfunction useDebouncedState<T = any>( defaultValue: T, wait: number, ): readonly [T, (newValue: T) => void];