Created
May 1, 2015 00:46
-
-
Save carlosdlf/815d4066a56f7dcc7de3 to your computer and use it in GitHub Desktop.
Mount and unmount - reactjs
This file contains 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
/** | |
* Created by clarico on 30/04/2015. | |
*/ | |
var Button = React.createClass({ | |
getInitialState: function () { | |
return {val : 0} | |
}, | |
update : function () { | |
this.setState({val: this.state.val +1}); | |
}, | |
componentWillMount: function () { | |
console.log('mounting') | |
}, | |
render:function(){ | |
console.log("rendering..."); | |
return <button onClick={this.update}>{this.state.val}</button> | |
}, | |
componentDidMount : function () { | |
console.log('mounted'); | |
}, | |
componentWillUnmount : function () { | |
console.log('bye!') | |
} | |
}); | |
var App = React.createClass({ | |
mount : function () { | |
React.render(<Button />, document.getElementById("app")); | |
}, | |
unmount : function () { | |
React.unmountComponentAtNode(document.getElementById("app")); | |
}, | |
render:function(){ | |
return ( | |
<div> | |
<button onClick={this.mount}>Mount</button> | |
<button onClick={this.unmount}>UnMount</button> | |
<div id="app"></div> | |
</div> | |
) | |
} | |
}); | |
React.render(<App/>,document.body ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment