meteor-mysql icon indicating copy to clipboard operation
meteor-mysql copied to clipboard

Use with React

Open tvogels opened this issue 9 years ago • 5 comments

Can meteor-mysql be used with React rendering in Meteor? I have a problem with a subscription that requires a parameter. I tried the following:

  ...
  mixins: [ReactMeteorData],

  getMeteorData() {
    let rooms = new MysqlSubscription('myPub','parameter (changing)');
    return {
      rooms: rooms.reactive(),
      ready: rooms.ready()
    };
  },
  ...

but it throws Error: Subscription failed!. Another thing I tried is having one global subscription and updating it with .change():

  ...
  componentWillUpdate() {
    console.log('component will update');
    eventsOnDate.change(this.getParams().date);
  },
  ...

but this results in rooms.ready() staying false forever.

tvogels avatar Sep 04 '15 13:09 tvogels

If you want me to take a look, give a link to a repository with the minimal code to reproduce the issue that I can clone.

numtel avatar Sep 15 '15 19:09 numtel

I'm also wondering about this. You call depend() and reactive() inside of template helper functions as per documentation which works great with the default templating, but what would it look like inside of a react component?

areim3r avatar Dec 16 '15 22:12 areim3r

ah nvm after a bit more research I've added react-template-helper to our project and it complements this very well. thanks!

areim3r avatar Dec 17 '15 18:12 areim3r

I have run into this issue as well. To test it, I've created a Meteor-React-Mysql version of the Tasks app from the tutorial using mysql and put it into a repository, meteor-react-mysql-tasks.

I can publish/subscribe and select all rows from a table, update and delete. However, whenever I try to use a parameterized subscription to select, e.g. filter tasks by owner or completed, I run into issues.

Part of this might be my misunderstanding of where in React subscription calls with parameters should go, e.g.:

foo = new MysqlSubscription('bar', some_id, user, some_state) 

When using Mongo, I can set subscription parameters in getMeteorData(), but with mysql it throws the same "Error: Subscription failed" found by the OP. Where can the call live such that the parameters it needs to get passed are scoped, whether they be state values, the Meteor.user(), or a parameter from the url? I'm working around it by placing change() calls in a couple of places in the lifecycle, but I need some clarification as to whether that is the appropriate technique. Any hints?

Here's the full exception:

Exception from Tracker recompute function:
debug.js:41 Error: Subscription failed!
at Array.MysqlSubscription (MysqlSubscription.js:40)
at React.createClass.getMeteorData (app.jsx:19)
at meteor-data-mixin.jsx:89
at Tracker.Computation._compute (tracker.js:323)
at new Tracker.Computation (tracker.js:211)
at Object.Tracker.autorun (tracker.js:562)
at meteor-data-mixin.jsx:76
at Object.Tracker.nonreactive (tracker.js:589)
at MeteorDataManager.calculateData (meteor-data-mixin.jsx:75)
at ReactMeteorData.componentWillUpdate (meteor-data-mixin.jsx:22)

hectoroso avatar Mar 18 '16 23:03 hectoroso

I know it's too late :) but am having same issue any one fixed that @hectoroso @numtel @areim3r @tvogels any help will be greatly appreciated

raza2022 avatar Sep 29 '18 07:09 raza2022