-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
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
Given function for useDebounce should expect arguments (as for the type signature) #618
Comments
I think args are not actually function args, they are deps, if deps changing so debounce function called. It's why you should directly use the screenSize variable inside the resize function. // ...
const resize = () => {
const { width = 0, height = 0 } = screenSize;
console.log(`screen: ${width}x${height}`);
};
// ... |
I completely understand. However, as the code within the function is defined, it seems to pass dependencies as function arguments. Line 5 in e6077c1
So, we have 2 choices to either:
If we were to strictly follow the Hooks rule, yes, @testarossaaaaa , I agree with you. It works just fine with plain Javascript, but not for TypeScript... which sometime annoys me, and makes me reconsider if it is worth to define types at all... |
@minagawah I think we should remove the dependency array from the function arguments as standard React hooks don't do this either. Currently the deps array is also not spread ( const resize = ([screen]): any => {
const { width = 0, height = 0 } = screen;
console.log(`screen: ${width}x${height}`);
}; I have opened a PR that implements these changes, let me know what you think. |
@wardoost PR looks good. And, yes. You are so right about the spreading as well. |
🎉 This issue has been resolved in version 12.2.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What is the current behavior?
Although the first argument of
useDebounce
(which is a function) expects arguments, the type signature for the function does not seem to accept arguments, and I get the following TypeScript error:While the actual implementation (within
useDebounce
) is no problem, I suggest to change the signature to take arguments:Steps to reproduce it and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than
react-use
. Paste the link to your JSFiddle or CodeSandbox example below:What is the expected behavior?
It should not raise a TypeScript error even if I specify arguments to the function.
A little about versions:
react-use
: 12.2.0The text was updated successfully, but these errors were encountered: