Skip to content

Instantly share code, notes, and snippets.

@deepak
Last active August 8, 2016 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepak/e9f1e079d4e0a004e61292d15461e39e to your computer and use it in GitHub Desktop.
Save deepak/e9f1e079d4e0a004e61292d15461e39e to your computer and use it in GitHub Desktop.
when you do not need a router
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 ?
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')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment