facebookarchive / react-meteor

React rendering for Meteor apps
948 stars 113 forks source link

Use components defined in packages #79

Closed merunga closed 9 years ago

merunga commented 9 years ago

In the example if I move the leaderboard.jsx file into a package, the template Leaderboard is not found: Uncaught Error: No such template: Leaderboard in blaze/lookup.js

Here's a reproduction repo, deployed here.

froatsnook commented 9 years ago

Don't forget to export the variable in package.js:

api.export("Leaderboard", ["client", "server"]);

As a rule, variables for packages:

merunga commented 9 years ago

Templates are always exported, aren't they? And the react mixin creates a real spacebar template, doesn't it? Or maybe i don't completely get how it works...

Either way, I tried what you said, didn't work either.

@froatsnook are you using react components inside your packages already?

froatsnook commented 9 years ago

@merunga No, I'm not using react components inside packages. At first glance it looked like a generic package export problem.

I'll take a look :)

froatsnook commented 9 years ago

OK at least the Leaderboard variable is now exported by the package. So you could do:

Template.yourTemplate.onRendered(function() {
    var container = this.find("#container");
    React.render(React.createElement(Leaderboard, { }), container);
});

This is definitely a react-meteor bug. It needs api.use("templating") in package.js. I submitted a pull request, but not sure when it will be merged in. I guess you could clone react-meteor and cherry-pick this commit? Also make sure to check out #77. I'm currently working from a local copy!

merunga commented 9 years ago

I cloned locally the package and added templating to the dependencies... that did the trick. Thanks @froatsnook !