-
Notifications
You must be signed in to change notification settings - Fork 347
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
Props don't get updated for custom event handelrs #102
Comments
My way of looking at things is that RR does not have props. It has state. And willReceiveProps really means will receive state. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Given this (heavily reduced) component:
onChange
will never be called with anything other than1
, regardless of what thecount
prop is changed to. The reason is of course thatmake
will be called again on props change, which will define a newhandleClick
function that closes over the new prop value, but will not (and obviously should not) calldidMount
again to attach the updated event handler. So the old event handler with the old prop value will be called in perpetuity.This isn't all that surprising if you understand how RR actually works, but it is if you expect it to work like reactjs'
this.props
(which of course I did, even though I should know better). RR creates the illusion, and thereby expectation, that it does work likethis.props
, until of course it doesn't. I suggest that this is made clear in the documentation somewhere, even if just as a FAQ.There are two workarounds, neither of which are very nice:
didUpdate
. This would also involve maintaining state to keep a reference of the currently attached event handler for removal, but is a more contained solution and good practice regardless of needing updated props, in case the element is re-inserted.This seems like a fundamental restriction with the API as it currently is, but I wanted to bring it up so perhaps it can be addressed in some future iteration at least.
Full example here: https://github.com/glennsl/rr-stale-props-issue/blob/abb81215857d4240b5bfd748dbb28e4d98590d33/src/index.re
The text was updated successfully, but these errors were encountered: