Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F100919595
useDebouncedState.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Feb 3, 23:10
Size
679 B
Mime Type
text/x-java
Expires
Wed, Feb 5, 23:10 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
24053972
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
useDebouncedState.js
View Options
import
{
useState
}
from
'react'
;
import
useDebouncedCallback
from
'./useDebouncedCallback'
;
/**
* Similar to `useState`, except the setter function is debounced by
* the specified delay.
*
* ```ts
* const [value, setValue] = useDebouncedState('test', 500)
*
* setValue('test2')
* ```
*
* @param initialState initial state value
* @param delay The milliseconds delay before a new value is set
*/
export
default
function
useDebouncedState
(
initialState
,
delay
)
{
var
_useState
=
useState
(
initialState
),
state
=
_useState
[
0
],
setState
=
_useState
[
1
];
var
debouncedSetState
=
useDebouncedCallback
(
setState
,
delay
);
return
[
state
,
debouncedSetState
];
}
Event Timeline
Log In to Comment