Last active
November 9, 2018 03:28
-
-
Save seanrankin/0c8f54a0ca4d5d9431d3cc9f59d7b3f3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// React Notes | |
/////////////////////////////////////////////////////////////////////////// | |
// Render Props | |
// The term “render prop” refers to a simple | |
// technique for sharing code between React components | |
// using a prop whose value is a function. | |
/////////////////////////////////////////////////////////////////////////// | |
<DataProvider render={data => ( <h1>Hello {data.target}</h1> )} /> | |
/////////////////////////////////////////////////////////////////////////// | |
// Refs API | |
/////////////////////////////////////////////////////////////////////////// | |
// Setting a ref that can be called with this.myNode: | |
<div ref={node => (this.myNode = node)} /> | |
// Sometimes you need to assign them wihin iterators: | |
<Component ref={node => { this[`node-${index}`] = node }} /> | |
// You can even use the callback to do fun things like get getBoundingClientRect(): | |
<div ref={this.refCallback} /> | |
/////////////////////////////////////////////////////////////////////////// | |
// State | |
/////////////////////////////////////////////////////////////////////////// | |
// Use the setState callback to access previous state (avoids batching issue) | |
this.setState(prevState => { | |
return { count: prevState.count++ }; | |
}); | |
/////////////////////////////////////////////////////////////////////////// | |
// New Context API | |
/////////////////////////////////////////////////////////////////////////// | |
/////////////////////////////////////////////////////////////////////////// | |
// Hooks | |
/////////////////////////////////////////////////////////////////////////// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment