What I'm trying to do is very common: I need to navigate between user profiles and being able to go back to each of them.
User1 -> User2 -> User3 And then User3 -> User2 -> User1
To do so, I'm using the navigation.push() method like this :
navigation.push('Profile', {userId: state.userId})
Each time, I call the Profile component, it fetches to relevant data using the userId passed in route.params.
The problem occurs when I want to navigate back. The previous Profile components only display the data of the last fetched user data...
Was my approach wrong ?
You need to keep some kind of global cache which every screen reads from. The data will be up to date if every screen reads from the same place.
The easiest way to do this would be to use react-query for data fetching: https://react-query.tanstack.com/
There are also other options like storing data in Redux after fetching etc.