Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access original props inside CreateContainer?

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?

like image 308
Oner Ksor Avatar asked Aug 12 '16 04:08

Oner Ksor


People also ask

What is props original react?

Props are an ordinary object of React that follow the immutable properties. This simply means that you cannot change their value throughout the component.

What is inside a props in react?

In ReactJS, the props are a type of object where the value of attributes of a tag is stored. The word “props” implies “properties”, and its working functionality is quite similar to HTML attributes. Basically, these props components are read-only components.


1 Answers

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);
like image 77
Waiski Avatar answered Sep 23 '22 07:09

Waiski