Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Swap getDerived and shouldUpdate in lifecycle diagram (#255)
Browse files Browse the repository at this point in the history
Also add a note about their interaction to the API reference
  • Loading branch information
MagiMaster committed Feb 7, 2020
1 parent d9b7f96 commit a2f0047
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 96 deletions.
5 changes: 4 additions & 1 deletion docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -608,4 +608,7 @@ end
As with `setState`, you can set use the constant `Roact.None` to remove a field from the state.

!!! note
`getDerivedStateFromProps` is a *static* lifecycle method. It does not have access to `self`, and must be a pure function.
`getDerivedStateFromProps` is a *static* lifecycle method. It does not have access to `self`, and must be a pure function.

!!! caution
`getDerivedStateFromProps` runs before `shouldUpdate` and any non-nil return will cause the state table to no longer be shallow-equal. This means that a `PureComponent` will rerender even if nothing actually changed. Similarly, any component implementing both `getDerivedStateFromProps` and `shouldUpdate` needs to do so in a way that takes this in to account.
2 changes: 1 addition & 1 deletion docs/images/lifecycle.gv
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ digraph G {
<br /><br />
<font face="monospace">Roact.update</font>
>];
update -> shouldUpdate -> getDerivedStateFromProps -> willUpdate -> render -> updated -> didUpdate;
update -> getDerivedStateFromProps -> shouldUpdate -> willUpdate -> render -> updated -> didUpdate;

unmounted [style="rounded", color="#000000", label=<<i>Instances Destroyed</i>>];
unmount [style="rounded", color="#000000", label=<
Expand Down

0 comments on commit a2f0047

Please sign in to comment.