【问题标题】:meteor and reactJS - how to make child components reactive?流星和reactJS - 如何使子组件反应?
【发布时间】:2015-12-19 21:06:03
【问题描述】:

我有一个子组件,它依赖于另一个小部件来设置它应该订阅的数据。如此有效的动态订阅。

getMeteorData() { var topicName = this.context.topicName; var handle = Meteor.subscribe('RebotTopicDetail', {name: topicName}); ...

如果 topicName 发生变化,我想重新订阅新数据。

最好的方法是什么?

topicName 正在由另一个组件设置,我正在使用上下文在对象之间传递它。 https://facebook.github.io/react/docs/context.html 我可以看到context.topicName 在我显示它时正在发生变化。 但它不会触发流星数据中的反应计算重新运行。

有没有办法在 getMeteorData 中的变量上声明 Deps? 我的理解是这是一个反应性块,因此更改会导致 getMeteorData 块重新运行。

https://react-in-meteor.readthedocs.org/en/latest/meteor-data/

我也尝试通过props 传递topicName,但这也不会触发响应式更新。

对于其他来这里的人,相关主题

【问题讨论】:

    标签: meteor reactjs reactive-programming


    【解决方案1】:

    编辑:道具似乎是被动的

    ```

      getMeteorData() {
        var topicName = this.props.topicName;
        var handle = Meteor.subscribe('RebotTopicDetail', {name: topicName});
    
    
    /// and in the container passing in a prop
    <TriggerList topicName={this.state.topicName} />
    

    ```

    有效。不确定容器项的使用状态是否与它有关。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-21
      • 1970-01-01
      • 1970-01-01
      • 2014-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多