Convert to withTracker


#1

I have this code copied from orionsoft:react-meteor-data and used it in my app.

import { createContainer } from "meteor/react-meteor-data";

export default function(getMeteorData, opts) {
  return function(ComposedComponent) {
    return createContainer(
      Object.assign({ getMeteorData }, opts),
      ComposedComponent
    );
  };
}

How can I convert this to using withTracker?


#2

Convert this part

import { createContainer } from "meteor/react-meteor-data";

...

createContainer(
  Object.assign({ getMeteorData }, opts),
  ComposedComponent
);

to

import { withTracker } from "meteor/react-meteor-data";

...

withTracker(Object.assign({ getMeteorData }, opts))(ComposedComponent);

As you see, the signature has just slightly changed.


#3

I am sure I did what you answered but been having some error when I ran it… But now that I cut and paste your solution the error I encountered was gone… Anyhow, thank you very much =)…

I am now totally a believer of the power of the Copy&Paste :smile:


#4

Yow! I remember what I did now…

export default function(getMeteorData, opts) {
  return function(ComposedComponent) {
   return withTracker(
       Object.assign({ getMeteorData }, opts)(ComposedComponent)
    );
 };
}

#5

I was just about to point out the nesting and amount of parens involved you have going on in there :wink:

Good thing I’m copy&paste-friendly :wink: Not cut&paste though, that would be unfair and technically harder :smiley:


#6

now I edited my reply hahahahha lol