react-template-helper

v0.2.12Published 2 years ago

Lets you easily include React components in Meteor templates. Pass the component class through the component argument.

Examples:

1<template name="Dropdown">
2  <div>
3    {{> React component=dropdown options=options value=selected onChange=onChange}}
4  </div>
5</template>
1Template.Dropdown.onCreated(function () {
2  this.state = new ReactiveDict;
3  this.state.set("selected", null);
4});
5
6Template.Dropdown.helpers({
7  dropdown: function () {
8    // Assuming this is https://github.com/fraserxu/react-dropdown, loaded
9    // elsewhere in the project.
10    return Dropdown;
11  },
12  options: [
13    { value: 'one', label: 'One' },
14    { value: 'two', label: 'Two' },
15    {
16      type: 'group', name: 'group1', items: [
17        { value: 'three', label: 'Three' },
18        { value: 'four', label: 'Four' }
19      ]
20    }
21  ],
22  selected: function () {
23    return Template.instance().state.get("selected");
24  },
25  onChange: function () {
26    var tmpl = Template.instance();
27    return function (option) {
28      tmpl.state.set("selected", option);
29    }
30  }
31});

Check out the React article](http://guide.meteor.com/react.html) in the Meteor Guide to learn how to use Meteor and React together to build awesome apps.