We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When we make a debouced method with returned values, we're not allowed to get the values, which could be usefull in some cases
const deboucedFn = useDebounceFn(() => 'value', 100); console.log(deboucedFn()); // undefined
This will currently return undefined
We can make this method return a promise with the returned values
const deboucedFn = useDebounceFn(() => 'value', 100); console.log(deboucedFn()); // Promise<'value'>
This can return promise that will be resolve with 'value'
As example for this implementation, i've done in a project this method
function useDeboundeFnWithRet<Args extends unknown[], R>(fn: (...args: Args) => Promise<R>, time: number) { let timerId: NodeJS.Timeout; return function debounced(...args: Args) { if (timerId) { clearTimeout(timerId); } return new Promise<R>((resolve) => { timerId = setTimeout(() => resolve(fn(...args)), time); }); }; }
No response
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
Clear and concise description of the problem
When we make a debouced method with returned values, we're not allowed to get the values, which could be usefull in some cases
This will currently return undefined
Suggested solution
We can make this method return a promise with the returned values
This can return promise that will be resolve with 'value'
As example for this implementation, i've done in a project this method
Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: