Forked from ryanflorence/gist:058845a355369ed0830f
Last active
August 29, 2015 14:20
-
-
Save eiriklv/8a9f14995e48bcad067b 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
| var React = require('react'); | |
| var Ridiculous = React.createClass({ | |
| getInitialState () { | |
| console.log(this.props.name, 'getInitialState'); | |
| return { foo: true }; | |
| }, | |
| render () { | |
| console.log(this.props.name, 'render'); | |
| return <div>{this.props.name}: {this.props.now}</div>; | |
| }, | |
| getDefaultProps () { | |
| console.log('getDefaultProps'); | |
| return { | |
| bar: false | |
| }; | |
| }, | |
| componentWillMount () { | |
| console.log(this.props.name, 'componentWillMount'); | |
| }, | |
| componentDidMount () { | |
| console.log(this.props.name, 'componentDidMount'); | |
| }, | |
| componentWillReceiveProps () { | |
| console.log(this.props.name, 'componentWillReceiveProps'); | |
| }, | |
| shouldComponentUpdate () { | |
| console.log(this.props.name, 'shouldComponentUpdate'); | |
| return true; | |
| }, | |
| componentWillUpdate () { | |
| console.log(this.props.name, 'componentWillUpdate'); | |
| }, | |
| componentDidUpdate () { | |
| console.log(this.props.name, 'componentDidUpdate'); | |
| }, | |
| componentWillUnmount () { | |
| console.log(this.props.name, 'componentWillUnmount'); | |
| } | |
| }); | |
| var App = React.createClass({ | |
| getInitialState () { | |
| return { | |
| now: Date.now(), | |
| killStuff: false | |
| }; | |
| }, | |
| setStateWithConsoleGroup (state) { | |
| console.group(); | |
| this.setState(state, () => { | |
| console.groupEnd(); | |
| }); | |
| }, | |
| changeStuff () { | |
| this.setStateWithConsoleGroup({ | |
| now: Date.now() | |
| }); | |
| }, | |
| killStuff () { | |
| this.setStateWithConsoleGroup({ killStuff: true }); | |
| }, | |
| unKillStuff () { | |
| this.setStateWithConsoleGroup({ killStuff: false }); | |
| }, | |
| render () { | |
| return ( | |
| <div> | |
| <button onClick={this.changeStuff}>change now</button> | |
| <button onClick={this.killStuff}>kill stuff</button> | |
| <button onClick={this.unKillStuff}>unkill stuff</button> | |
| {!this.state.killStuff && ( | |
| <div> | |
| <Ridiculous now={this.state.now} name="one"/> | |
| </div> | |
| )} | |
| </div> | |
| ); | |
| } | |
| }); | |
| React.render(<App/>, document.getElementById('app')); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment