通过道具更新redux状态,我该如何避免呢?

时间:2017-08-07 12:34:38

标签: javascript reactjs redux react-redux

我正在为数据过滤构建react-redux库。它的基本工作方式是通过装饰您的过滤器组件,以便它可以访问要过滤的数据。装饰组件使用库的Filter组件。这大致是这样的:

const MyComponent = (props) => {
    <Filter
        prop="propA" // What prop to filter in the data
        operator="AND" // Use the AND operator between keywords
        component={FilterList} // The component used to render the filter. It sets the keywords to filter with a callback passed to it's props
    />
};

export default filterDecorator({name: 'myFilter', getData: (state) => state.data })(MyComponent);

我希望最终用户能够通过Filter的道具设置过滤选项。例如,在使用关键字进行过滤时,我希望能够通过道具AND设置逻辑运算符(ORoperator)。该库还导出一个函数来检索过滤后的数据。由于此函数需要了解过滤器的选项,但它无法访问props,因此我使用redux状态(Filter组件在更新operator道具时调度操作。)

我觉得这很尴尬。感觉不对,两个人在两个不同的地方都有信息:redux的状态和道具。

这种情况是否有任何已知的模式?

0 个答案:

没有答案
相关问题