File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed
Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,9 @@ import useDebouncedCallback, {
55
66/**
77 * Similar to `useState`, except the setter function is debounced by
8- * the specified delay.
8+ * the specified delay. Unlike `useState`, the returned setter is not "pure" having
9+ * the side effect of scheduling an update in a timeout, which makes it unsafe to call
10+ * inside of the component render phase.
911 *
1012 * ```ts
1113 * const [value, setValue] = useDebouncedState('test', 500)
@@ -17,10 +19,11 @@ import useDebouncedCallback, {
1719 * @param delayOrOptions The milliseconds delay before a new value is set, or options object
1820 */
1921export default function useDebouncedState < T > (
20- initialState : T ,
22+ initialState : T | ( ( ) => T ) ,
2123 delayOrOptions : number | UseDebouncedCallbackOptions ,
2224) : [ T , Dispatch < SetStateAction < T > > ] {
2325 const [ state , setState ] = useState ( initialState )
26+
2427 const debouncedSetState = useDebouncedCallback < Dispatch < SetStateAction < T > > > (
2528 setState ,
2629 delayOrOptions ,
You can’t perform that action at this time.
0 commit comments