-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add React lifecycles getDerivedStateFromProps, getSnapshotBeforeUpdate #6511
Conversation
This will have merge conflicts with #6510 which I'd be happy to resolve once either PR is merged. |
Can you link to documentation or code backing this change, to ensure this is the correct definition? |
|
|
|
I can get |
@motiz88 I think |
= objects with the shape of Your comment would have been correct if I was referring to |
A couple of remaining issues due to facebook#6606: - gDSFP's return type is correct, but in need of a cleanup once $NonMaybeType<$Shape<State>> works. - gSBU's return type still allows undefined, which should be rejected. I have made these explicit in the code by using $FIXME-prefixed aliases.
Back working on this after a busy few weeks (also helped by the fact that CI builds are working again). 8a7bb7d brings us to what I think is the best of all possible worlds right now:
|
We are not updating class component typing at this point. |
Closes #6101, closes #6104.
Broadly speaking, there are three possible approaches for handling
getSnapshotBeforeUpdate
andcomponentDidUpdate
:any
and assume the user knows what they're doing (this is what I did here).mixed
and force the user to cast / "promise" they know what they're doing.Snapshot
toReact.Component
, see if Flow can infer it from usage, etc.I thought (3) was overkill for a rarely-used React feature and (2) would mostly add unhelpful noise, hence I stuck with (1). Happy to take guidance from a reviewer if you think another option is preferable though.