• Stars
    star
    126
  • Rank 284,543 (Top 6 %)
  • Language
    JavaScript
  • Created almost 9 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

No-Config reactive React Components with Meteor

image Current Version: 1.0.5

Meteor 1.3
meteor add ultimatejs:tracker-react
Meteor 1.2
meteor add ultimatejs:[email protected]

TrackerReact is an upgrade to what ReactMeteorData offers. Using TrackerReact instead you are no longer required to "freeze" all your reactivity in a single method. Any reactive data sources (e.g: collection.find() or Session.get('foo')) used in your render method or by methods called by your render method are automatically reactive! This replicates the standard helper experience from Meteor/Blaze. Enjoy!

GOTCHA: You must call .fetch() on your cursors to trigger reactivity!!

Usage

From Meteor v.1.3 and up, react components can be made reactive either by using TrackerReact in a Composition (inheritance), as Mixin or as Decorator.

Example-App

Clone & Read the Source: https://github.com/D1no/TrackerReact-Example

trackerreact-demo

Profiling

Currently only under the profiler Branch and will be added with the final release of Meteor 1.3 Use the profiler argument TrackerReact(React.Component, {profiler: true}) to see render times of a reactive components. Or set this._profMode = {profiler: true} within the constructor() function.

Implementation

Composition (wrapping a relevant React.Component in TrackerReact) is a clean, default alternative until Meteor supports decorators.

import React from 'react';
import ReactDOM from 'react-dom';

// TrackerReact is imported (default) with Meteor 1.3 new module system
import TrackerReact from 'meteor/ultimatejs:tracker-react';

// Get the Collection
Tasks = new Mongo.Collection("tasks");

// > React.Component is simply wrapped with TrackerReact
class App extends TrackerReact(React.Component) {

	// Note: In ES6, constructor() === componentWillMount() in React ES5
	constructor() {
		super();
		this.state = {
          subscription: {
            tasks: Meteor.subscribe('tasks')
          }
        }
	}
	
	componentWillUnmount() {
		this.state.subscription.tasks.stop();
	}
	
	//tracker-based reactivity in action, no need for `getMeteorData`!
	tasks() {
	    return Tasks.find({}).fetch(); //fetch must be called to trigger reactivity
	},
	

	render() {
		return (
			<div className="container">
				<h1>
					Todo List - {Session.get('title')}
				</h1>

				<ul>
				  	{this.tasks().map((task) => {
						  return <Task key={task._id} task={task} />;
					  })}
				</ul>
			</div>
		);
	}
});

Same is possible as Mixin (ES6 example)

import React from 'react';
import ReactDOM from 'react-dom';

// Use ReactMixin from npm
import ReactMixin from 'react-mixin';

// > Make sure to import the TrackerReactMixin export
import {TrackerReactMixin} from 'meteor/ultimatejs:tracker-react';

// Get the Collection
Tasks = new Mongo.Collection("tasks");

class App extends React.Component {

	// (...)

});
// > Using ReactMixin 
ReactMixin(App.prototype, TrackerReactMixin);

Same example as Decorator (ES6/ES7 Example). Cleanest solution: Requires support for decorators either setting babel to experimental or TypeScript with experimental ES7 features turned on.

import React from 'react';
import ReactDOM from 'react-dom';

// > Make sure to import the TrackerReactMixin export
import {TrackerReactMixin} from 'meteor/ultimatejs:tracker-react';

// Get the Collection
Tasks = new Mongo.Collection("tasks");

// > Assign as Decorator
@TrackerReactMixin
class App extends React.Component {

	// (...)

Old Example: Meteor 1.2

Package version: ultimatejs:[email protected]

App = React.createClass({
	mixins: [TrackerReact],

	//tracker-based reactivity in action, no need for `getMeteorData`!
	tasks() {
	    return Tasks.find({}).fetch(); //fetch must be called to trigger reactivity
	},
	

	render() {
		return (
			<div className="container">
				<h1>
					Todo List - {Session.get('title')}
				</h1>

				<ul>
				  	{this.tasks().map((task) => {
						  return <Task key={task._id} task={task} />;
					  })}
				</ul>
			</div>
		);
	}
});

More Repositories

1

react-universal-component

🚀 The final answer to a React Universal Component: simultaneous SSR + Code Splitting
JavaScript
1,696
star
2

redux-first-router

🎖 seamless redux-first routing -- just dispatch actions
JavaScript
1,568
star
3

extract-css-chunks-webpack-plugin

Extract CSS from chunks into multiple stylesheets + HMR
JavaScript
691
star
4

webpack-flush-chunks

💩 server-to-client chunk discovery + transportation for Universal Rendering
JavaScript
355
star
5

universal-demo

DEMO: Webpack Flush Chunks + React Universal Component 3.0 🚀
JavaScript
230
star
6

redux-first-router-demo

Kick-Ass Universal RFR Demo That Answers Your SSR + Splitting Questions
JavaScript
125
star
7

babel-plugin-universal-import

🍾 universal(props => import(`./${props.page}`)) + dual css/js imports
JavaScript
114
star
8

redux-first-router-link

<Link /> + <NavLink /> that mirror react-router's + a few additional props
JavaScript
55
star
9

jest-storybook-facade

JavaScript
53
star
10

babel-plugin-dual-import

NOTE: now use babel-plugin-universal-import if you're using React Universal Component
JavaScript
50
star
11

require-universal-module

Universal-Rendering Module Loading Primitives
JavaScript
28
star
12

transition-group

What React CSS Transition Group is s'posed to be
JavaScript
25
star
13

respond-framework-docs-old

25
star
14

redux-first-router-boilerplate

JavaScript
23
star
15

flush-chunks-boilerplate

💩 A boilerplate showing how to achieve Universal Code-Splitting and Universal HMR with react-loadable, webpack-flush-chunks and extract-css-chunks-webpack-plugin
JavaScript
18
star
16

redux-first-router-restore-scroll

JavaScript
13
star
17

remixx

JavaScript
12
star
18

flush-chunks-boilerplate-babel-chunknames

babel boilerplate for Webpack Flush Chunks + React Universal Component + webpack's "magic comment" feature
JavaScript
10
star
19

travis-github-status

Set statuses on github from travis for jest, flow, + eslint
JavaScript
8
star
20

extract-css-chunk

JavaScript
7
star
21

jest-redux-snap

📸 reactive test helpers for redux and jest. snap everything!!!
JavaScript
7
star
22

redux-first-router-codesandbox

HOW TO USE: https://medium.com/faceyspacey/redux-first-router-lookin-sexy-on-code-sandbox-d9d9bea15053
JavaScript
6
star
23

react-native-20-screcorder-demo

JavaScript
6
star
24

redux-first-router-navigation

JavaScript
5
star
25

flush-chunks-boilerplate-webpack

universal webpack boilerplate for Webpack Flush Chunks + React Universal Component
JavaScript
5
star
26

rudy

JavaScript
5
star
27

blog-demo

JavaScript
3
star
28

redux-first-router-demo-codesandbox

JavaScript
3
star
29

redux-first-router-scroll-container

JavaScript
3
star
30

redux-first-router-navigation-boilerplate

JavaScript
3
star
31

nucleus

JavaScript
2
star
32

universal-react-vue-loader-demo

JavaScript
2
star
33

animated-transition-group

like <ReactTransitionGroup /> + callbacks, extras and child-specific customization
JavaScript
2
star
34

universal-render

2
star
35

ck

JavaScript
1
star
36

pure-redux-router

👶 Seamless Redux-First Routing
JavaScript
1
star
37

webpack-server-middleware

Hot updates Webpack bundles on the server
JavaScript
1
star
38

rudy-match-path

JavaScript
1
star
39

flush-chunks-boilerplate-babel

babel boilerplate for Webpack Flush Chunks + React Universal Component
JavaScript
1
star
40

redux-first-router-scroll-container-native

scroll restoration for React Native using Redux First Router
JavaScript
1
star
41

coastbeachwear

Web Store for Coast Beachwear Inc.
JavaScript
1
star
42

rfr-demo-mike

Created with CodeSandbox
JavaScript
1
star