Refresh previous screen on goBack()

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 2023: willFocus event was renamed to focus

  componentDidMount() {
    this.props.fetchData();
    this.focusSubscription = this.props.navigation.addListener(
      'focus',
      () => {
        this.props.fetchData();
      }
    );
  }

  componentWillUnmount() {
    this.focusSubscription();
  }

Leave a Comment