[v2] 'Component id already exists' when using setStackRoot
Issue Description
I'm trying to replace a screen in the stack. So I figured that setStackRoot is maybe the way to do it because there is no replace API and setStackRoot supports multiple children. So if I rebuild the stack it should be the same as replacing a part of it.
Code Snippets
Navigation.setStackRoot('CustomComponentId', [
{
component: {
id: 'CustomId',
name: 'CustomName'
}
},
{
component: {
id: 'CustomId2',
name: 'CustomName2'
}
},
]);
Screenshot
The code above results in that error:

Environment
- React Native Navigation version: 2.5.2
- React Native version: 0.57.1
- Platform(s) (iOS, Android, or both?): iOS
- Device info (Simulator/Device? OS version? Debug/Release?): Simulator / Debug
So I can't use that API if a component is already in the stack. I think that this is directly related to this issue #4333. Is there any workaround for replacing a component in the stack?
Hello, I encounter the issue myself, so if anyone has an idea to share, I'd greatly appreciate it !
Hi @thinklinux, I made library for redux integration for RNN : https://www.npmjs.com/package/react-native-navigation-redux-integration. So if you integrate it with your project you can omit custom IDs and use selectors for getting component ids ( RNN will always create unique id for every component you use). In your example you can either use getActiveScreenId selector or even better, dispatch action and let middleware handle setting stack root with this action creator setStackRoot ( If you are currently on active stack ). Just dispatch actions like this
dispatch(setStackRoot([
{
component: {
//note - no id
name: 'CustomName'
}
},
{
component: {
name: 'CustomName2'
}
},
]))
Also library provides more selectors and middleware actions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.
The issue has been closed for inactivity.