Page does not update after deep link to same page is clicked

I am using React-navigation to handle deep link.

Let's say I am in BusinessProfile Page that is currently displaying detail for BUSINESS B1. I click on home button and minimize my app. When I click on a deep link, myapp://BusinessProfilePage/B2, It takes me to the BusinessProfile Page but still displays result for Business B1. The function to get business detail for B2 is not called.

How can I make the page refresh when a page opens from a deep link.

P.S. I cannot call the function in componentDidUpdate because when the function to get Business Detail is called, it updates the state which then evoke componentDidMount again.

1 answer

  • answered 2019-05-15 04:16 iuliu.net

    You should call your function in a listener for the change event of AppState:

    import { AppState } from 'react-native';
    
    componentDidMount() {
      AppState.addEventListener('change', this._handleAppStateChange);
    }
    
    _handleAppStateChange = (nextAppState) => {
      if (nextAppState === 'active') { // App has come to the foreground
        if(this.state.currentBusiness.ID != (ID received in deep link)) // Need to get data
             this.getBusiness(ID received in deep link);
      }
     };
    

    Taking my best guess here with regards to variable names as you didn't provide and code (you should always include code samples when describing your issue :) ), but you get the idea.