Skip to content

Instantly share code, notes, and snippets.

@milankinen
Created December 9, 2015 08:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save milankinen/8b47f2ab1890085814c8 to your computer and use it in GitHub Desktop.
React "ServerOnly" component
import React from "react"
import {findDOMNode} from "react-dom"
export default React.createClass({
componentWillMount() {
if (process.browser) {
this.setState({html: findDOMNode(this).innerHTML})
}
},
render() {
if (process.browser) {
return <div dangerouslySetInnerHTML={{__html: this.state.html}} />
} else {
return <div>{this.props.children}</div>
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment