如何在CreateContainer中访问原始道具?

One*_*sor 5 meteor reactjs react-jsx meteor-react

我有一个非常简单和可怕的问题.

让我们说,我有一个React组件(称为List)包裹createContainer:

class List extends Component {
  render() {
    return (
      ...
    );
  }
}
export default createContainer({
  ...
}, List);
Run Code Online (Sandbox Code Playgroud)

List父母有一个道具:activeListId.

createContainer用来订阅订阅,但我需要在该订阅中传递一个参数.参数是activeListId值.

export default createContainer({
  Meteor.subscribe('ListItems', this.props.activeListId);
  return {
    ...
  }
}, List);
Run Code Online (Sandbox Code Playgroud)

所以我需要访问createContainer代码中原始组件的props .这太奇怪了,但我不能这样做!this上下文中createContainer是从不同的this内部List.

谁知道如何实现这一目标?

Wai*_*ski 8

作为它的第一个参数,createContainer应该接收一个props作为参数的函数.所以你需要这样做:

export default createContainer(props => {
  Meteor.subscribe('ListItems', props.activeListId);
  return {
    ...
  }
}, List);
Run Code Online (Sandbox Code Playgroud)