MatkoMilic
MatkoMilic

Reputation: 55

React Native on goBack from SPECIFIC screen call a function refresh

I found similar questions but none answered it the way I need.

I use react navigation. I have two screens, HomeScreen and PostScreen. When I create a post in PostScreen I use

this.props.navigation.goBack()

and successfully go back to home screen, however inside HomeScreen I have a certain function called refresh() and I would love for that function to be called upon using goBack from PostScreen. Solutions on similar questions show how to refresh screen ,from goBack but anytime coming from ANY screen by using stuff like onWillFocus() or some listeners, but I want this behaviour to only be for specific screen. I guess I need to pass some stuff don't I? I use class components btw.

SO BASICALLY I NEED: onWillFocus { this.refresh() IF I CAME FROM POSTSCREEN and not if I came from anywhere}

Upvotes: 0

Views: 1093

Answers (1)

dianaqqq
dianaqqq

Reputation: 668

I think you could navigate back sending one parameter to the Home screen in order to know when you should call the refresh() in onWillFocus(). Like this navigation.navigate('Home", {refresh: true})

Upvotes: 1

Related Questions