Last active
August 8, 2016 12:57
-
-
Save deepak/e9f1e079d4e0a004e61292d15461e39e to your computer and use it in GitHub Desktop.
when you do not need a router
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
when you do not need a router | |
then we can escape by mounting and unmounting components manually | |
also can we hook `history.js` into mount and unmount to get a stupid router ? |
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 HelloWorld = React.createClass({ | |
componentWillMount: function() { | |
console.log("mounting HelloWorld"); | |
}, | |
render: function() { | |
console.log("rendering HelloWorld"); | |
return ( | |
<p>hello world</p> | |
); | |
}, | |
componentDidMount: function() { | |
console.log("mounted HelloWorld"); | |
}, | |
componentWillUnmount: function() { | |
console.log("unmounting HelloWorld"); | |
} | |
}); | |
var YoWorld = React.createClass({ | |
componentWillMount: function() { | |
console.log("mounting YoWorld"); | |
}, | |
render: function() { | |
console.log("rendering YoWorld"); | |
return ( | |
<p>Yo! World</p> | |
); | |
}, | |
componentDidMount: function() { | |
console.log("mounted YoWorld"); | |
}, | |
componentWillUnmount: function() { | |
console.log("unmounting YoWorld"); | |
} | |
}); | |
var Wrapper = React.createClass({ | |
unMountApp: function() { | |
ReactDOM.unmountComponentAtNode(document.getElementById('app2')); | |
}, | |
mountHello: function() { | |
ReactDOM.render( | |
<HelloWorld />, | |
document.getElementById('app2') | |
); | |
}, | |
mountYo: function() { | |
ReactDOM.render( | |
<YoWorld />, | |
document.getElementById('app2') | |
); | |
}, | |
render: function() { | |
return ( | |
<div> | |
<button onClick={this.mountHello}>hello</button> | |
<button onClick={this.mountYo}>yo</button> | |
<div id="app2"> | |
{this.props.children} | |
</div> | |
</div> | |
); | |
} | |
}); | |
ReactDOM.render( | |
<Wrapper><HelloWorld/></Wrapper>, | |
document.getElementById('app') | |
); |
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
<div id="app"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment