-
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
'Bind' will result in errors in onClick handler #6306
Comments
Would you like to investigate why this happens? |
Related to #5172 (comment)? |
This happens because the API is |
Ah, right. The problem is you bind only the first argument, the second one becomes the event from the event handler. As a result We can probably provide a better invariant message when we receive an event instead of the callback because |
I would like to reopen until we provide a better error message or decide it is not necessary. |
It appears that a better error message was added in #5193.
is not much better for this particular case, and we can explain the problem much more specifically. |
I think this is a good argument for having pages on our site for each invariant / warning where we can go much more in depth than we can in a string. We can show specific cases like this where we show common "bad" code that might be triggering it. Adding all the code to React that does all of the possible debugging gets tricky. Especially in a case like there where you could probably just do an |
Put up #6310 to address this. |
I will close this as we can continue the discussion in #6310. |
If you create any react component, and add this attribute to it:
onClick={this.setState.bind(this, {smKey:smValue} )}
then you click it, it will report an error:
but actually it's working, the state will be correctly updated, nothing wrong, just the annoying error.
I think this is a bug, but I can not image how could it be, when this can work:
onClick={()=>this.setState({smKey,smValue})}
to me they are exactly the same things.
The text was updated successfully, but these errors were encountered: