Last active
October 6, 2017 14:25
-
-
Save mykeels/06d58ac363208ba58f7ff04d6973cf1a to your computer and use it in GitHub Desktop.
The ultimate explanation for React's component lifecycle event handlers from https://tylermcginnis.com/reactjs-tutorial-a-comprehensive-guide-to-building-apps-with-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
| var FriendsContainer = React.createClass({ | |
| getInitialState: function(){ | |
| alert('In getInitialState'); | |
| return { | |
| name: 'Tyler McGinnis' | |
| } | |
| }, | |
| // Invoked once before first render | |
| componentWillMount: function(){ | |
| // Calling setState here does not cause a re-render | |
| alert('In Component Will Mount'); | |
| }, | |
| // Invoked once after the first render | |
| componentDidMount: function(){ | |
| // You now have access to this.getDOMNode() | |
| alert('In Component Did Mount'); | |
| }, | |
| // Invoked whenever there is a prop change | |
| // Called BEFORE render | |
| componentWillReceiveProps: function(nextProps){ | |
| // Not called for the initial render | |
| // Previous props can be accessed by this.props | |
| // Calling setState here does not trigger an additional re-render | |
| alert('In Component Will Receive Props'); | |
| }, | |
| // Called IMMEDIATELY before a component is unmounted | |
| componentWillUnmount: function(){}, | |
| render: function(){ | |
| return ( | |
| <div> | |
| Hello, {this.state.name} | |
| </div> | |
| ) | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment