理想情况下,我们应该在哪里放置一个在 React 中发生事件时进行的 api 调用
在eventHandler
orcomponentDidUpdate
里面
例子:
handleItemClick = (item) => (event) => {
this.setState({selectedItem: item});
this.props.requestDataActionDispatch(item);
}
或者
componentDidUpdate(prevProps, prevState, snapshot) {
if(prevState.item !== this.state.item) {
this.props.requestDataActionDispatch(item);
}
}