1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| var HelloReact = React.createClass({ componentWillReceiveProps:function(newProps){ console.log('componnetWillReceiveProps',1) console.log(newProps) }, shouldComponentUpdate:function(newProps,newState){ console.log('shouldComponentUpdate',2) console.log(newProps,newState) return true; }, componentWillUpdate:function(){ console.log('componentWillUpdate',3) }, render:function(){ console.log('render',4) return <p>Hello {this.props.name?this.props.name:'React'}</p> }, componentDidUpdate:function(){ console.log('componentDidUpdate',5) }, componentWillUnmount:function(){ console.log('BOOOOOOOOOOOOOOOOOM') } }) var Demo = React.createClass({ getInitialState:function(){ return { name:'' } }, handleChange:function(e){ if(e.target.value == '1234'){ ReactDOM.unmountComponentAtNode(document.getElementById("app")) return ; } this.setState({ name:e.target.value }) }, render:function(){
return( <div> <HelloReact name={this.state.name}/> <input type="text" onChange={this.handleChange} /> </div> ) } }) ReactDOM.render(<Demo/>,document.getElementById("app"))
|