是否包装了所有消费者性能差的组件?

时间:2019-03-04 10:48:38

标签: reactjs

我正在使用以下模式。

function map_number_context_to_props ({ actions, state }:Number_context) {
    return {
        number: state.number
    };
}

function map_string_context_to_props ({ actions, state }:String_context) {
    return {
        number: state.string
    };
}

export default (
    with_number_consumer<Props, Injected_props>(map_number_context_to_props)(
        with_string_consumer<Props, Injected_props>(map_string_context_to_props)(Component)
    )
);

但是如您所见,这很不方便。因此,我正在考虑是否包装与所有消费者连接在一起的组件,如下所示。有点像<Number_consumer><String_consumer><Component2/></Conponent></String_consumer></Number_consumer>

function map_context_to_props (context:Context) {
    return {
        number: context.number.state.number
    };
}

export default with_consumer<Props, Injected_props>(Component2);

我想了解优点和缺点,尤其是在性能方面。如果还有其他更好的方法,请告诉我。谢谢:D

0 个答案:

没有答案