Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Last active August 29, 2015 14:06
Show Gist options
  • Save ryanflorence/b7ecaf9bbda3b8f1a156 to your computer and use it in GitHub Desktop.
Save ryanflorence/b7ecaf9bbda3b8f1a156 to your computer and use it in GitHub Desktop.
var Popover = React.createClass({
render: function() {
// break this rendering tree
return null;
},
componentDidMount: function() {
var node = this.node = document.createElement('div');
// append a node to render into later
document.body.appendChild(node);
this.renderContent();
},
componentWillReceiveProps: function(newProps) {
// need to get updates from the outside world
this.renderContent(newProps);
},
renderContent: function(props) {
props = props || this.props;
// reconnect the rendering tree with the children
React.renderComponent(<div>{props.children}</div>, this.node);
}
});
// Usage
var App = React.createClass({
render: function() {
return (
<div>
<Popover>
Hello and stuff, I am rendered in `document.body`
</Popover>
</div>
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment