-
Notifications
You must be signed in to change notification settings - Fork 47.1k
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
enqueueCallback invariant should specify/identify actual object in failure message #5172
Comments
Well, the typecheck happens with that exact typecheck, just not directly in forceupdate. Here's forceUpdate: https://github.com/facebook/react/blob/master/src/renderers/shared/reconciler/ReactUpdateQueue.js#L109-L114 and where the invariant happens: https://github.com/facebook/react/blob/master/src/renderers/shared/reconciler/ReactUpdateQueue.js#L109-L114 FWIW, We need to do the typecheck so I guess we could discuss whether we keep it as an invariant or a warning. But it is a misuse of the API. |
To follow up on that, the more "equal" thing would be: window.addEventListener(
'resize',
(e) => this.forceUpdate(e)
); Which should throw the same error that you see with your first bind example. |
Correct. Yes, I understand all of that. It wasn't toooo hard for me to understand what is happening. And it is a misuse of the API. So I guess, I would consider adding the argument type to the invariant to help make it clearer? Something more like:
It's kind of moot. But It confused me for a second. Might confuse others also. |
Oddly enough, the two examples below are not equal as I thought they would be.
The error is as follows:
I'm assuming that is because the function as assuming an optional callback. But I would expect your code to do a typeof check, and not just a defined check. Can we change it to do a
typeof fn === 'function'
check? I can submit a PR.The text was updated successfully, but these errors were encountered: