从母组件传递道具或在助焊剂存储中听取状态变化是否更高效?

时间:2015-10-30 21:09:39

标签: reactjs flux reactjs-flux

我们说我有以下父母 - >反应组件内的子关系:

<parentComponent>
    <childComponent>
        <grandChildComponent>
            <greatGrandChildComponent></greatGrandChildComponent>
                ...
                  ...
                     ... // And so on
        </grandChildComponent>
</parentComponent>

假设我从Flux商店获取数据,让<parentComponent>获取其状态/监听Flux商店中的更改,然后将相关数据传递给其子项更为高效props或者让每个<..child>组件直接监听商店对其状态的任何更新是否更高效?

1 个答案:

答案 0 :(得分:1)

Performance would likely depend on your specific program. Is there a reason youre concerned with performance between these two practices? I must imagine its an extremely minimal difference.

that being said, idiomatic react greatly favors stateful components housing stateless components. unless theres a good reason for a child component to manage itself (that is manage its own state and not let its parent manage it), you should be composing your site with as few stateful components as possible that contain many stateless children.

tl;dr pass in props from your parent