Skip to content

Instantly share code, notes, and snippets.

@chochinlu
Last active August 29, 2015 14:05
Show Gist options
  • Save chochinlu/0a9419dfe927adb43e42 to your computer and use it in GitHub Desktop.
Save chochinlu/0a9419dfe927adb43e42 to your computer and use it in GitHub Desktop.
TodoList react component to demo react component lifecycle
/** @jsx React.DOM */
var React = require('react');
var TodoList = React.createClass({
getInitialState: function(){
console.log('getInitialState');
return null;
},
componentWillMount: function(){
console.log('componentWillMount');
},
componentDidMount: function(){
console.log('componentDidMount');
},
componentWillReceiveProps: function(){
console.log('componentWillReceiveProps');
},
shouldComponentUpdate: function(){
console.log('shouldComponentUpdate');
return true;
},
componentWillUpdate: function(){
console.log('componentWillUpdate');
},
render: function(){
console.log('render');
var createItem = function(itemText){
return <li key={itemText}>{itemText}</li>;
};
return <ul>{this.props.items.map(createItem)}</ul>;
},
componentDidUpdate: function(){
console.log('componentDidUpdate');
},
componentWillUnmount: function(){
console.log('componentWillUnmount');
}
});
module.exports = TodoList;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment