所以,我有两家商店。第一个 pageStore 服务特定页面的业务逻辑,第二个 globalStore 服务 Android/iOS 全局事件逻辑。 当用户进入特定页面时 React.componentDidMount 调用
pageEntered: function () {
this.listenTo(globalStore, this.locationUpdated);
},
从此我的 pageStore 开始监听全局存储以获取 GPS 更新。但是有什么方法可以在 React.componentWillUnmount 上断开 ListenTo 的连接吗?
最佳答案
这里有一个如何取消订阅商店监听的示例(取自官方示例):
var Status = React.createClass({
getInitialState: function() { },
onStatusChange: function(status) {
this.setState({
currentStatus: status
});
},
componentDidMount: function() {
this.unsubscribe = statusStore.listen(this.onStatusChange);
},
componentWillUnmount: function() {
this.unsubscribe();
},
render: function() {
// render specifics
}
});
关于reactjs - 断开回流listenTo方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31346493/