Skip to content

Source code for useAsyncDebounce()? #4014

Answered by nrayburn-tech
memark asked this question in Q&A
Discussion options

You must be logged in to vote

Code here for v7. I don't know if it exists in v8.

table/src/publicUtils.js

Lines 163 to 197 in 46bcc7c

export function useAsyncDebounce(defaultFn, defaultWait = 0) {
const debounceRef = React.useRef({})
const getDefaultFn = useGetLatest(defaultFn)
const getDefaultWait = useGetLatest(defaultWait)
return React.useCallback(
async (...args) => {
if (!debounceRef.current.promise) {
debounceRef.current.promise = new Promise((resolve, reject) => {
debounceRef.current.resolve = resolve
debounceRef.current.reject = reject
})
}
if (debounceRef.current.timeout) {
clearTimeout(debounceRef.current.timeout)
}

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@KevinVandy
Comment options

Answer selected by memark
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants