【发布时间】:2017-11-28 08:55:08
【问题描述】:
我正在构建一个应用程序,它会不断地监听位置变化并更新商店。我想知道将我的侦听器放在我的动作创建器中而不是组件本身是否是个好主意。
例如,
componentWillMount() {
this.props.watchLocation();
}
// inside action creator
export function watchLocation() {
LocationManager.on("location", location => {
dispatchLocationlocation);
});
}
或者,在我的 react-native 组件中,
componentWillMount() {
LocationManager.on("location", location => {
// call action to dispatch location updates
});
}
如果我将侦听器放在我的动作创建器中,在性能方面有什么不同?
【问题讨论】:
标签: javascript reactjs react-native redux redux-thunk