5

I have amazingly simple and terrible problem.

Let's say, I have a React component (called List) wrapped by createContainer:

class List extends Component {
  render() {
    return (
      ...
    );
  }
}
export default createContainer({
  ...
}, List);

List has one prop from parent: activeListId.

I use createContainer to subscribe for subscription, but i need to pass a parameter inside that subscription. The parameter is activeListId value.

export default createContainer({
  Meteor.subscribe('ListItems', this.props.activeListId);
  return {
    ...
  }
}, List);

So I need to have an access to props of the original component inside the createContainer code. It is so strange but I can not do this! this context inside createContainer is different from this inside List.

Who knows how to achieve that?

Oner Ksor
  • 901
  • 6
  • 16

1 Answers1

8

As its first argument, createContainer should receive a function that takes props as an argument. So you need to do this:

export default createContainer(props => {
  Meteor.subscribe('ListItems', props.activeListId);
  return {
    ...
  }
}, List);
Waiski
  • 9,214
  • 3
  • 21
  • 30
  • If anybody looks for mor info then there is an article in the official guide: https://guide.meteor.com/react.html#using-createContainer – Oner Ksor Aug 16 '16 at 01:10