【问题标题】:May I use alt stores in multiple components in react?我可以在反应的多个组件中使用替代商店吗?
【发布时间】:2016-08-06 00:01:33
【问题描述】:

例如,在一页中,我想在许多组件中使用 UserStore。 可以这样用吗?

  1. 如果组件是 UserComponent 的子组件,我必须在每个子组件中声明 {...props} 吗?还是可以在许多子组件中使用重复的覆盖注入?

  2. 如果组件不在UserComponent中,是否可以在多个组件中声明UserStore重复?

什么是最佳实践?

<Component1>
  <UserComponent>    < --- UserStore : get states to props
    <Component1 />

    <Component2>
      <Component3>
        <Component4>
          <Component5 /> < --- UserStore : get states to props
        </Component4>
      </Component3>
  </UserComponent>
</Component1>

<Component6>
  <Component7></Component7> < --- UserStore : get states to props
</Component6>

【问题讨论】:

    标签: reactjs flux alt.js


    【解决方案1】:

    这里有很多思路。我承认我没有使用过 alt.js,所以可能有一些我没有解决的观点。

    那就是说;

    FB's Flux Documentation 建议了一个最佳实践。他们的架构建议是使用两类组件;容器和视图。

    容器与商店交互以收集数据,并且不接收任何道具。它们没有视图逻辑,它们将存储数据作为道具传递给子视图。

    视图将所有信息作为道具传递(没有商店通信)。

    所以是的,您可以将这些值作为道具从孩子传递到孩子。但是您可以拥有多个从商店中提取相同信息的容器。重要的是容器应该不知道自己的位置和位置,完全不知道自己的父母是谁。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-27
      • 2018-11-07
      • 2020-10-13
      • 2020-08-27
      • 1970-01-01
      • 1970-01-01
      • 2021-10-18
      相关资源
      最近更新 更多