Right now I have the following:
componentWillUnmount() { console.log("Leaving"); this._isMounted = false; }
componentDidMount() { this._isMounted = true; }
I have a function like so:
this.saveSomething(this.state.data).then((response) => {
if(response !== null) {
console.log(this._isMounted);
if(this._isMounted) {
Alert.alert(
'Success!', 'It was saved',
[
{text: 'Go Home', style: 'cancel', onPress: () => {
//navigate the app home
this.props.navigation.navigate('Home');
}},
{text: 'Stay Here'},
{text: 'Do something else', onPress: () => {
//stuff that they need to be on the page to do
}}
]
);
}
}
})
If this functions runs and I click the back button with my react-navigation
, componentWillUnmount()
runs but once the saveSomething
finishes, my alert box still pops up if I am not on the page.
Does anyone know why this would happen?