Integrating React with Meteor's reactive data system
In the preceding example, the data passed to the child component via props was generated in the parent component itself in the setInterval function. In order to render React components on Meteor's data change, we need to create a component container.
The steps are as follows:
Add react-meteor-data and react-addons-pure-render-mixin npm packages using the following command:
The first parameter is a callback function that returns the result as an object named time, and the second parameter is the Timer component. The way it works is that on any changes in the browser database Minimongo, the data will be fetched and passed to the component as props (time in our case).
To break this down, refer to this:
We defined Time as a MongoDB collection.
find() is a MongoDB method to query records (records are called documents in MongoDB) from the collection. If there is no query specified, will return cursor for the first 20 records by default.
Adding the fetch() method will return the documents as an array.
Meteor allows us to create a collection directly in the code: