Last active
May 23, 2018 10:42
-
-
Save trueadm/079048c1e002ea0e718fcf15294197db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const State = React.createState(); | |
function MyComponent(props) { | |
return ( | |
<State | |
initialState={() => ({ counter: 0, lastProps: props, divRef: React.createRef() }) } | |
deriveState={state => ({ lastProps: props }) } | |
shouldUpdate={(state, nextState) => ... } | |
didMount={(state, setState) => ... } | |
getSnapshotBeforeUpdate={state => ... } | |
didUpdate={(state, setState, prevState, snapshot) => ... } | |
willUnmount={state => ... } | |
> | |
{(state, setState) => ( | |
... | |
)} | |
</State> | |
); | |
} |
s/createRef/createState/
should initialState be initial? Should deriveState be derive? Does it matter?
Maybe initialValue
but I don't think initial
has enough meaning anything by itself. "Initial...what?".
I also think deriveState
and initialState
are fine as is.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Points:
React.createRef()
the best API for this? Is it confusing that<State>
has all the lifecycles?adopt
syntax, it makes render props like above far less painful to use.initialState
beinitial
? ShouldderiveState
bederive
? Does it matter?