Created
August 28, 2016 14:40
-
-
Save awatson1978/2f73120565f295647590d2836e56e4df to your computer and use it in GitHub Desktop.
Rendering Blaze into a React Template
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
http://stackoverflow.com/questions/36269581/meteor-rendering-a-blaze-template-within-a-react-template | |
To render blaze from react, you make a wrapper class: | |
``` | |
AccountsWrapper = React.createClass({ | |
componentDidMount() { | |
this.view = Blaze.render(Template.Accounts, | |
React.findDOMNode(this.refs.container)); | |
}, | |
componentWillUnmount() { | |
Blaze.remove(this.view); | |
}, | |
render() { | |
// Just render a placeholder container that will be filled in | |
return <span ref="container" />; | |
} | |
}); | |
``` | |
This references a blaze template defined in accounts.html: | |
``` | |
<template name="Accounts"> | |
{{> loginButtons }} | |
<div> | |
{{> React component=Test}} | |
</div> | |
</template> | |
``` | |
In my routes file, I render the wrapper template like so: | |
``` | |
FlowRouter.route("/", { | |
name: "root", | |
action: function(params, queryParams) { | |
ReactLayout.render(Root, | |
{content: <AccountsWrapper />}) | |
} | |
}) | |
``` | |
You can also see that in my blaze template I'm calling | |
``` | |
{{> React component=Test}} | |
``` | |
``` | |
Test = React.createClass({ | |
render() { | |
return <div> | |
WORKING | |
</div> | |
} | |
}) | |
if (Meteor.isClient) { | |
Template.Accounts.helpers({ | |
Test() { | |
return Test; | |
} | |
}) | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment