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?
Props are an ordinary object of React that follow the immutable properties. This simply means that you cannot change their value throughout the component.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With