Created
November 11, 2016 16:17
-
-
Save jdsharp/bc2a136cc6274af4702aade113812d3e to your computer and use it in GitHub Desktop.
React Unmanaged DOM Node Wrapping
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
const UnmanagedDOMContainer = React.createClass({ | |
getDefaultProps() { | |
return { | |
nodes : null | |
}; | |
}, | |
componentWillReceiveProps(newProps) { | |
if ( !this.props.nodes && newProps.nodes ) { | |
this.appendNodes(newProps.nodes); | |
} | |
}, | |
shouldComponentUpdate() { | |
return false; | |
}, | |
componentDidMount() { | |
this.appendNodes(this.props.nodes); | |
}, | |
appendNodes(nodes) { | |
if ( nodes ) { | |
let self = ReactDOM.findDOMNode(this); | |
self.appendChild(nodes); | |
} | |
}, | |
render() { | |
return (<div></div>); | |
} | |
}); | |
const MyWrapperComponent = React.createClass({ | |
componentWillMount() { | |
// Kidnap the childnodes... | |
theChildNodes = ... | |
this.setState({ | |
childNodes : theChildNodes | |
}); | |
}, | |
render() { | |
return ( | |
<UnmanagedDOMContainer nodes={this.state.childNodes} /> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment