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, {
5
5
6
6
/**
7
7
* 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.
9
11
*
10
12
* ```ts
11
13
* const [value, setValue] = useDebouncedState('test', 500)
@@ -17,10 +19,11 @@ import useDebouncedCallback, {
17
19
* @param delayOrOptions The milliseconds delay before a new value is set, or options object
18
20
*/
19
21
export default function useDebouncedState < T > (
20
- initialState : T ,
22
+ initialState : T | ( ( ) => T ) ,
21
23
delayOrOptions : number | UseDebouncedCallbackOptions ,
22
24
) : [ T , Dispatch < SetStateAction < T > > ] {
23
25
const [ state , setState ] = useState ( initialState )
26
+
24
27
const debouncedSetState = useDebouncedCallback < Dispatch < SetStateAction < T > > > (
25
28
setState ,
26
29
delayOrOptions ,
You can’t perform that action at this time.
0 commit comments