Abhishek
Abhishek

Reputation: 301

How to re-render or refresh previous screen when going back using react router flux

In my react native app I am using react native router flux, while going back to the previous screen I want the previous screen to re-render or refresh. I am using Action.pop() to go back to the previous. How I can refresh the previous screen?

Upvotes: 1

Views: 791

Answers (2)

Abhishek
Abhishek

Reputation: 301

I solved it using Action.reset('key of the screen') of react router flux

Upvotes: 0

neiker
neiker

Reputation: 8992

You need to listen "focus" event on navigation object on your screen and add the logic for fetching new data inside the event handler.

function YourScreenComponent({ navigation }) {
  React.useEffect(() => {
    const unsubscribe = navigation.addListener('focus', () => {
      // fetch new data here
    });

    return unsubscribe;
  }, [navigation]);

  return <SomeContent />;
}

Upvotes: 1

Related Questions