Skip to content

Waiting for the user to finish writing #615

Answered by francoischalifour
Drigtime asked this question in Q&A
Discussion options

You must be logged in to vote

Hey! You can debounce the promise in getSources, like we're doing in this example:

function debouncePromise<TParams extends unknown[], TResponse>(
fn: (...params: TParams) => Promise<TResponse>,
time: number
) {
let timerId: ReturnType<typeof setTimeout> | undefined = undefined;
return function (...args: TParams) {
if (timerId) {
clearTimeout(timerId);
}
return new Promise<TResponse>((resolve) => {
timerId = setTimeout(() => resolve(fn(...args)), time);
});
};
}
const debouncedFetch = d…

Replies: 1 comment 1 reply

Comment options

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

Answer selected by Drigtime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants