Adding an Api Call in a focus callBack in the screen you're returning to solves the issue.
componentDidMount() {
this.props.fetchData();
this.willFocusSubscription = this.props.navigation.addListener(
'willFocus',
() => {
this.props.fetchData();
}
);
}
componentWillUnmount() {
this.willFocusSubscription.remove();
}
UPDATE 2021:
componentDidMount() {
this.props.fetchData();
this.willFocusSubscription = this.props.navigation.addListener(
'willFocus',
() => {
this.props.fetchData();
}
);
}
componentWillUnmount() {
this.willFocusSubscription();
}
If you use React Hook:
React.useEffect(() => {
fetchData();
const willFocusSubscription = props.navigation.addListener('focus', () => {
fetchData();
});
return willFocusSubscription;
}, []);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…