This meteorjs package allows you to use Blaze templates as and inside React components.
### Installation
You can add this package to your meteor app like any other package from atmosphere
$ meteor add 4commerce:blaze-as-react
This package registers the function Template.AsReactComponent()
and the property React.BlazeView
.
##### Sample template
foo.html:
<template name="foo">
<div>
<p>Hello world!: {{bar}}
</div>
</template>
##### use React.BlazeView
about.jsx:
var pageAbout = React.createClass({
render() {
return (
<div>
<React.BlazeView template="foo" bar="Send from React ..." />
</div>
);
}
});
##### use Template.AsReactComponent()
about.jsx:
var Foo = Template.AsReactComponent('foo');
var pageAbout = React.createClass({
render() {
return (
<div>
<Foo bar="Send from React ..." />
</div>
);
}
});
You may decide which method fits your needs best.
> Attention: If you use `Template.AsReactComponent` don't name your var starting with lowercase character like `foo` or `myFoo` etc. In that case React will not use that variable as a component. > > var foo = Template.AsReactComponent('foo'); > ... > <foo bar="Send from React ..." /> > > does not work!
When you add this package, follwing dependencies will load:
- underscore
- templating
- react-runtime
- Meteor Forum: Smoothly feature up your Blaze Apps with React Components
- Read the docs: React in Meteor
- Meteor on github: React packages
In case of support or error please report your issue request. The issue tracker is available at: https://github.com/4commerce-technologies-AG/meteor-package-blaze-as-react/issues
Author: Tom Freudenberg, 4commerce technologies AG
Copyright (c) 2015 Tom Freudenberg, 4commerce technologies AG, released under the MIT license
I found a number of ressources on the internet doing something similar but not completely. So I took all here together in this new package. Thanks to all unlisted authors for their inspiration.