Created
October 4, 2015 23:13
-
-
Save ryan-williams/bed5aaeb3ead5f7ff3e4 to your computer and use it in GitHub Desktop.
React component for rendering Blaze templates inside other React components. Adapted from https://github.com/jedwards1211/meteor-webpack-react/blob/a4cf9be698a3ded97ffa4bb53b11ede0c39d364e/app/components/BlazeTemplate.js and https://forums.meteor.com/t/calling-meteor-template-from-react-components/8704
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
BlazeTemplate = React.createClass({ | |
propTypes: { | |
template: React.PropTypes.any.isRequired, | |
component: React.PropTypes.any, | |
}, | |
getDefaultProps() { | |
return { | |
component: 'div' | |
}; | |
}, | |
// we don't want to re-render this component if parent changes | |
shouldComponentUpdate() { | |
return false; | |
}, | |
componentDidMount() { | |
this.view = Blaze.render(this.props.template, React.findDOMNode(this.refs.root)); | |
}, | |
componentWillUnmount() { | |
Blaze.remove(this.view); | |
}, | |
render() { | |
let {component, ...props} = this.props; | |
props.ref = 'root'; | |
return React.createElement(component, props); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment