【发布时间】:2019-06-18 23:39:28
【问题描述】:
我将 React 与带有多个 reducer 的 Redux 一起使用。
我有一个组件,我想从多个 reducer 中获取数据,但每次我发出号召性用语时,它都会重新呈现组件(显然......)
async componentDidMount() {
await this.props.getBooksNamesAsync();
await this.props.getAuthorsNamesAsync();
await this.props.getSubscribersAsync();
this.props.setFilter(
this.props.book.bookNames,
this.props.author.authorNames,
this.props.subscriber.subscriberNames
);
}
- this.props.getBooksNamesAsync() 是对图书的操作。
- this.props.getAuthorsNamesAsync() 是对作者的操作。
- this.props.getSubscribersAsync() 是对订阅者的操作。
我的问题是此类问题的最佳做法是什么?
- 每次操作都重新渲染组件是否合法?
- 我是否应该在一个地方编写另一个包含所有这些操作的操作? 这是安静的代码重复,我更愿意避免它......
或任何其他选项...
【问题讨论】: