【发布时间】:2020-09-18 16:32:47
【问题描述】:
警告:无法对未安装的组件执行 React 状态更新。这是一个空操作,但它表明您的应用程序中存在内存泄漏。要修复,请在 componentWillUnmount 方法中取消所有订阅和异步任务。
componentDidMount() {
this.RetrieveSellerNo();
this.requestLocationPermission();
this.requestData();
this.Watch();
this._interval = setInterval(() => {
if (this.state.SellerNo !== null) {
this.uploadPosition();
}
this.requestData();
}, 60000);
setTimeout(() => {
this.requestData();
this.StoreiposLat();
this.StoreiposLong();
}, 5000);
}
componentWillUnmount = () => {
Geolocation.clearWatch(this.watchId);
}
Watch = () => {
this.watchId = Geolocation.watchPosition(
(position) => {
this.setState({
watch: {
lat: position.coords.latitude,
long: position.coords.longitude
}
});
},
(error) => {
// console.log(error.message)
},
{ enableHighAccuracy: false, timeout: 20000, maximumAge: 1000, } //distanceFilter:1
);
}
【问题讨论】:
标签: javascript react-native memory-leaks geolocation