im having a hard time with this error because everything used to work perfectly now its says that its deprecated. Can someone help me with error cause nothing its working, I have tried the new code in the App State documentation but still the same error TypeError: undefined is not an object (evaluating 'appState.remove')
This is my code:
constructor(props) {
super(props);
this.state = {
region: null,
status: undefined,
appState: AppState?.currentState,
modalVisible: true,
isLoading: true,
};
this._getLocationAsync();
}
componentDidMount() {
AppState.removeEventListener("change", this.handleAppStateChange);
}
handleAppStateChange = (nextAppState) => {
if (
this.state.appState.match(/inactive|background/) &&
nextAppState === "active"
) {
this._getLocationAsync();
}
this.setState({ appState: nextAppState });
};
componentWillUnmount() {
AppState.addEventListener("change", this.handleAppStateChange);
this._getLocationAsync();
}
_getLocationAsync = async () => {
let { status } = await Location.requestPermissionsAsync();
let location = await Location.getCurrentPositionAsync({
enableHighAccuracy: false,
timeout: 10000,
maximumAge: 0,
});
let region = {
latitude: location.coords.latitude,
longitude: location.coords.longitude,
latitudeDelta: 0.0045,
longitudeDelta: 0.0045,
};
this.props.callback({
latitude: region.latitude,
longitude: region.longitude,
});
this.setState({ region: region, status: status });
};
appState
is null (that what create the error) – Tubercle