Reputation: 113
Lets say the app has two tabs, the first one has 10 buttons, each button commands the second tab to show a different screen. And I want the new screen to replace the old one when the button is pressed; I don't want the new screen to stack on top of the old one. So far I've achieved this by rendering all ten screens with a boolean state for each that determines whether it returns anything or not, but rendering them all at the same time has slowed the app down.
Upvotes: 0
Views: 861
Reputation: 526
To replace a route in the navigation state you can use :
import { StackActions } from '@react-navigation/native';
navigation.dispatch(
StackActions.replace('Profile', {
user: 'jane',
})
);
source : https://reactnavigation.org/docs/stack-actions/#replace
Upvotes: 1