New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot read property undefined of undefined #1919
Comments
I don't understand how is In the meantime, do have a look at my reply here. I believe you are facing something similar to this. |
I am having the same issue |
I also have the same issue. EDIT: |
I also have the same issue. |
Hi, I am having the same issue and I believe the problem is in the way we initialize the navigation state in redux. The docs say to do something like this to set the initial navigation state:
If AppNavigator is a StackNavigator and "Main" route is a DrawerNavigator (or TabNavigator), it will crash, because the StackRouter associated with the StackNavigator doesn't initialize the child router when it receives an action of navigate and its inner state isn't initialized. So I ended up doing something like this:
With this approach, it worked correctly. |
@boliveira thanks a LOT for that. However, I've noticed that you just need to do: let initialNavState = AppNavigator.router.getStateForAction(
NavigationActions.init()
); No need for that: const firstAction = AppNavigator.router.getActionForPathAndParams("Main");
//Then calculate the state with a navigate action to the first route, sending the previous initialized state as argument
initialNavState = AppNavigator.router.getStateForAction(
firstAction,
initialNavState
); At least in my case =^) |
@almirfilho, I thought that so but there a was a particular case in my app that wasn't working with just the Init. I had to explicitly call getStateForAction for the first screen in the app to make it work. So I advise you to do the same to avoid problems in the future. |
@almirfilho , you were right, if I only do the init thing, it works as well. The problem I was having was not related to navigation. And this approach has a distinct advantage because if you do only the init, and have StackNavigators inside one of the routes of the DrawerNavigator, these routes would NOT be duplicated or triplicated like they were if you initialized the state using the recommended approach in the docs... There is really some kind of bug in the way the StackNavigator inside a DrawerNavigator is handled right now. EDIT: Corrected "these routes would be duplicated" to "these routes would NOT be duplicated" |
@almirfilho it probably works with just the |
Closing since the question seems to be answered. 👍 |
@boliveira I tried using |
for more information see this: react-navigation/react-navigation#1919 (comment)
for more information see this: react-navigation/react-navigation#1919 (comment)
Current Behavior
I am very new to react and pretty much all this stack. What I am trying to accomplish is to implement a tab navigator inside a stack navigator. I've done this without redux using this library but I can not do it when I move my stack navigator to redux. I've even tried a different navigation library and I keep ending up with that error in the title which is driving me crazy because it does not tell much (or I just do not get it).
I've used the exact redux example available in the examples repo. everything works until I change my home screen (the one after login) to a tab navigator I've created.
My HomeRoutes.js file
Just text screen file
Expected Behavior
Your Environment
I've literally spent about 7 hours on my saturday to figure this out. Please please help. I have no idea what I am doing wrong or if this is a bug (I bet that it is me though) and I can use some light into this depressed dark state that is my soul.
The text was updated successfully, but these errors were encountered: