Creating a Meteor package that exposes a React class

I’m looking for a good example of how to create Meteor package that exposes a React class for Meteor 1.3. Right now, I’m using NPM installed React, React DOM, Material-UI etc.

Specific questions:

  1. How to handle the dependencies: Will putting putting those dependencies (React, React DOM, etc.) in the Npm.depends(…) function in package.js work, or is this a separate set of logic that’s not smart enough to know whether I’ve got NPM packages installed globally?

  2. What’s the syntax for exposing the React class?

  3. What’s the syntax for consuming the React class in my client code?

I’ve looked at markoshust:material-ui, but I’m not sure it’s the most up-to-date pattern, and I wasn’t able to get it to work in any case.


I would say take a look through this as it contains breaking changes to api from 1.2 to 1.3.

Beware that this is a work in progress and is probably not 100% complete yet but it will still be a good place to start for you

1 Like

Take my advice with a grain of salt, as this is just my own experience and should probably be confirmed, but I don’t recommend using Npm.depends, at is can easily lead to conflicts with peer dependencies and the “multiple versions of React” error. Instead, users should separately install the packages your package depends on via NPM.

Also, as far as I can tell you can’t yet publish to Atmosphere a package that uses api.mainModule.

1 Like