Meteor 1.3 and React Composition with Reactive Data

3 min read

Note: This blog post is a republish from my original post over at the Spacedojo Medium publication.

Unless you’ve been living under a rock you know that mixins are dead when writing React components with ES2015 classes. The new way to handle data is to use composition/higher-order components. The problem is that Meteor’s official solution for reactive data is using a mixin. I recently attended Josh Owens’ live Mastering Meteor class and he went over Meteor 1.3 and loading data in React. Let’s check out the previous way of handling reactive data, and then compare two new ways, I learned about in class, of handling data with composition.

ReactMeteorData Mixin and getMeteorData()

Unfortunately, Meteor’s official solution for handling reactive data in a React component uses a mixin, called ReactMeteorData. While mixins can work in ES2015 classes by using an experimental ES7 feature called decorators or with a special packages like ReactMixin, it’s best to know that they will not stick around forever. By using the ReactMeteorData, you have access to a method called getMeteorData() that houses your reactive data. Data returned by getMeteorData is usable in the render() method by accessing Here’s a simple example:

3TodoList = React.createClass({
4 mixins: [ReactMeteorData],
5 getMeteorData() {
6 var handle = Meteor.subscribe('todoList',
8 return {
9 loading: !handle.ready(),
10 todoList: TodoLists.findOne(,
11 todoListTasks: Tasks.find({listId:}).fetch(),
12 }
13 },
14 render() {
15 const {loading, todoList, todoListTasks} =
16 if (loading) {
17 return <LoadingSpinner />
18 }
20 return (
21 <div>
22 <h1>{}</h1>
23 <ul>
24 {todoListTasks &&
25, index) => {
26 return <li key={index}>{task}</li>
27 })}
28 </ul>
29 </div>
30 )
31 },

Higher-Order Components, Composition, Containers, UI components

The answer to replacing mixins is by building two pieces of code: a container and a UI component (sometimes called a dumb component). The role of the container is to fetch data and pass that data down as props to the UI component. The role of the UI component is to display that data. Pretty simple, huh? Of course, there is always more to worry about like showing a loading indicator, showing an error if it occurs, and re-fetching and passing the new data to the UI component. This is where a few packages step in to save the day.

React Komposer: Composing React Components

React Komposer is an NPM package created by Kadira. It helps users create containers with less boilerplate by handling loading indicators and cleaning up resources. React-Komposer’s goal is to also works with a wide range of other technologies besides Meteor’s Tracker like Promises, Rx.JS, and Observables. Below is the same example we saw previously, but instituted with composition using React Komposer.

3import { composeWithTracker } from 'react-composer';
4import TodoList from '../components/TodoList.jsx';
6function composer(props, onData) {
7 const subscription = Meteor.subscribe('todoList',;
8 if (subscription.ready()) {
9 const todoList = TodoLists.findOne({ });
10 const todoListTasks = Tasks.find({ listId: }).fetch();
12 onData(null, { todoList, todoListTasks });
13 };
16default composeWithTracker(composer)(TodoList);

Above is a container called TodoListContainer.js which subscribes to a publication, and when is ready calls other queries. You take the data you query and pass it to the onData method which will pass it off as props to the component below.

3const TodoList = ({todoList, todoListTasks}) => (
4 <div>
5 <h1>{}</h1>
6 <ul>
7 {, index) => {
8 return <li key={index}>{task}</li>
9 })}
10 </ul>
11 </div>

Pretty easy. Even better than that, React Komposer handles displaying the loading indicator until onData method is called and it will display any errors we pass it automatically for us! If you want to change the loading indicator or error display, it’s effortless.

Now on to TrackerReact, a more straightforward approach. Unfortunately, TrackerReact does not help with some of the repetitive aspects of using containers, like stopping subscriptions, displaying loading indicators, or handling passed errors.

TrackerReact: No-Config Reactive React Components With Meteor

TrackerReact has been out a while, but has seen a major overhaul recently for Meteor 1.3. The documentation states that it is well suited for small to mid-sized applications that have simple features. TrackerReact is Meteor focused and allows a React component to become reactive by wrapping the component with Tracker. The benefit of wrapping the component with Tracker is developers can use any of Meteor’s reactive data sources like collections, methods, and sessions from anywhere in the component. TrackerReact feels more like a natural ‘Meteor way’ to handle things inside of React. TrackerReact can be used in composition, as a mixin, or as a decorator.

Below is our same example, using TrackerReact:

3import TrackerReact from 'meteor/ultimatejs:tracker-react';
5class App extends TrackerReact(React.Component) {
6 constructor() {
7 super();
8 this.state = {
9 subscription: {
10 todoList: Meteor.subscribe('todoList',
11 }
12 }
13 }
14 componentWillUnmount() {
15 this.state.subscription.todoList.stop();
16 }
17 todoList() {
18 return TodoLists.findOne(;
19 },
20 todoListTasks() {
21 return Tasks.find({ listId: }).fetch();
22 },
23 render() {
24 return (
25 <TodoList
26 todoList={ this.todoList }
27 todoListTasks={ this.todoListTasks }
28 />
29 );
30 }
3const TodoList = ({todoList, todoListTasks}) => (
4 <div>
5 <h1>{}</h1>
6 <ul>
7 {, index) => {
8 return <li key={index}>{task}</li>
9 })}
10 </ul>
11 </div>

For more information on how to use TrackerReact as a mixin or decorator, check out the GitHub README.

Decorators are experimental and mixins are meeting their end, so we have to change how we write React components. Understanding containers and how they interact with components is not complicated, but we have several tools to make building them easier.

If you want a more opinionated solution, stick with React Komposer. But if you are just beginning to shift away from mixins, I would take a good look TrackerReact. Both offer pros and cons, such as Komposer’s automatic loading indicator or TrackerReact’s ability to use any of Meteor’s reactive sources.

Now get back to work, and start composing!