Created
April 20, 2018 14:16
-
-
Save panchaow/3552a3f93710deb21622dbafb245607d to your computer and use it in GitHub Desktop.
new Refs API in React
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
class MyComponent extends React.Component { | |
constructor(props) { | |
super(props); | |
// Refs are created using React.createRef(). | |
// Refs are commonly assigned to an instance property when a component is constructed so they can be referened throughout the component. | |
this.myRef = React.createRef(); | |
} | |
render() { | |
// Refs are attached to React elements via the ref attribute | |
return <div ref={this.myRef} />; | |
} | |
} | |
// assessing refs: const node = this.myRef.current; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment