How to pass data from one component to Navigator and from Navigator to componentReact native + redux populate store with data before any Component renderReact-native nested navigators within ReduxReact Native / React Navigation Performance: Best practice for storing/passing data for list views?Show splash screen before show main screen in react native without using 3rd party libraryHow to redirect to login screen in react navigation tab navigator with reduxNavigate in React-Native + Redux using React-Navigation between Nested NavigatorsReact-Navigation: Navigate screen when DeclaredHow to push a new scene using react-navigation?How to make a Login screen that switches with a Home Screen even when App is closedNot getting params in header

Why was the small council so happy for Tyrion to become the Master of Coin?

What do the dots in this tr command do: tr .............A-Z A-ZA-Z <<< "JVPQBOV" (with 13 dots)

LaTeX closing $ signs makes cursor jump

What is the word for reserving something for yourself before others do?

Writing rule stating superpower from different root cause is bad writing

Test if tikzmark exists on same page

Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?

How is it possible to have an ability score that is less than 3?

How much RAM could one put in a typical 80386 setup?

What's the output of a record cartridge playing an out-of-speed record

Why, historically, did Gödel think CH was false?

How to write a macro that is braces sensitive?

What is the offset in a seaplane's hull?

Mage Armor with Defense fighting style (for Adventurers League bladeslinger)

Schoenfled Residua test shows proportionality hazard assumptions holds but Kaplan-Meier plots intersect

US citizen flying to France today and my passport expires in less than 2 months

Mathematical cryptic clues

How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine

Pattern match does not work in bash script

How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?

Adding span tags within wp_list_pages list items

Characters won't fit in table

Can I ask the recruiters in my resume to put the reason why I am rejected?



How to pass data from one component to Navigator and from Navigator to component


React native + redux populate store with data before any Component renderReact-native nested navigators within ReduxReact Native / React Navigation Performance: Best practice for storing/passing data for list views?Show splash screen before show main screen in react native without using 3rd party libraryHow to redirect to login screen in react navigation tab navigator with reduxNavigate in React-Native + Redux using React-Navigation between Nested NavigatorsReact-Navigation: Navigate screen when DeclaredHow to push a new scene using react-navigation?How to make a Login screen that switches with a Home Screen even when App is closedNot getting params in header






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








3















I'm actually doing a login system and when my user is logged, the login component has to send data to my main screen but I don't really understand how to do it.



Actually I've this when user is logged :



User.username = data.username;
User.id = responseJson.id;
User.token = responseJson.token;
this.props.navigation.navigate('Main', User: User );


User is where everything is saved and it works.



Data is sended to Main a Switch Navigates inside an AppContainer :



export default createAppContainer(createSwitchNavigator(

Auth: screen: AuthStack, navigationOptions: tabBarVisible: false ,
Main: screen: MainStack ,
,

initialRouteName: "Auth"
),
);


so it goes on Mainstack who's a bottomTabNavigator and works like that :



const MainStack = createBottomTabNavigator(
{
Services:
screen: Home,
navigationOptions:
tabBarLabel:"Services",
tabBarIcon: ( tintColor ) => (
<Icon name="home" size=30 color="#0033CC" />
)
,
,


I know it's not complete I've other screens not only Services, just wanted to avoid too long function on paste.



So is that possible to send this data "User" to my Home screen ?
I'm open to any suggestion or answer, that's my first react Native project so there is maybe some mistakes :)










share|improve this question




























    3















    I'm actually doing a login system and when my user is logged, the login component has to send data to my main screen but I don't really understand how to do it.



    Actually I've this when user is logged :



    User.username = data.username;
    User.id = responseJson.id;
    User.token = responseJson.token;
    this.props.navigation.navigate('Main', User: User );


    User is where everything is saved and it works.



    Data is sended to Main a Switch Navigates inside an AppContainer :



    export default createAppContainer(createSwitchNavigator(

    Auth: screen: AuthStack, navigationOptions: tabBarVisible: false ,
    Main: screen: MainStack ,
    ,

    initialRouteName: "Auth"
    ),
    );


    so it goes on Mainstack who's a bottomTabNavigator and works like that :



    const MainStack = createBottomTabNavigator(
    {
    Services:
    screen: Home,
    navigationOptions:
    tabBarLabel:"Services",
    tabBarIcon: ( tintColor ) => (
    <Icon name="home" size=30 color="#0033CC" />
    )
    ,
    ,


    I know it's not complete I've other screens not only Services, just wanted to avoid too long function on paste.



    So is that possible to send this data "User" to my Home screen ?
    I'm open to any suggestion or answer, that's my first react Native project so there is maybe some mistakes :)










    share|improve this question
























      3












      3








      3








      I'm actually doing a login system and when my user is logged, the login component has to send data to my main screen but I don't really understand how to do it.



      Actually I've this when user is logged :



      User.username = data.username;
      User.id = responseJson.id;
      User.token = responseJson.token;
      this.props.navigation.navigate('Main', User: User );


      User is where everything is saved and it works.



      Data is sended to Main a Switch Navigates inside an AppContainer :



      export default createAppContainer(createSwitchNavigator(

      Auth: screen: AuthStack, navigationOptions: tabBarVisible: false ,
      Main: screen: MainStack ,
      ,

      initialRouteName: "Auth"
      ),
      );


      so it goes on Mainstack who's a bottomTabNavigator and works like that :



      const MainStack = createBottomTabNavigator(
      {
      Services:
      screen: Home,
      navigationOptions:
      tabBarLabel:"Services",
      tabBarIcon: ( tintColor ) => (
      <Icon name="home" size=30 color="#0033CC" />
      )
      ,
      ,


      I know it's not complete I've other screens not only Services, just wanted to avoid too long function on paste.



      So is that possible to send this data "User" to my Home screen ?
      I'm open to any suggestion or answer, that's my first react Native project so there is maybe some mistakes :)










      share|improve this question














      I'm actually doing a login system and when my user is logged, the login component has to send data to my main screen but I don't really understand how to do it.



      Actually I've this when user is logged :



      User.username = data.username;
      User.id = responseJson.id;
      User.token = responseJson.token;
      this.props.navigation.navigate('Main', User: User );


      User is where everything is saved and it works.



      Data is sended to Main a Switch Navigates inside an AppContainer :



      export default createAppContainer(createSwitchNavigator(

      Auth: screen: AuthStack, navigationOptions: tabBarVisible: false ,
      Main: screen: MainStack ,
      ,

      initialRouteName: "Auth"
      ),
      );


      so it goes on Mainstack who's a bottomTabNavigator and works like that :



      const MainStack = createBottomTabNavigator(
      {
      Services:
      screen: Home,
      navigationOptions:
      tabBarLabel:"Services",
      tabBarIcon: ( tintColor ) => (
      <Icon name="home" size=30 color="#0033CC" />
      )
      ,
      ,


      I know it's not complete I've other screens not only Services, just wanted to avoid too long function on paste.



      So is that possible to send this data "User" to my Home screen ?
      I'm open to any suggestion or answer, that's my first react Native project so there is maybe some mistakes :)







      react-native react-navigation






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 21 at 23:43









      EstroEstro

      161




      161






















          2 Answers
          2






          active

          oldest

          votes


















          0














          You'll probably want to persist the user data in the app (save it in the storage for when the user leaves the app then enters he stays logged in). That's why react-navigation has the switchNavigator (the one you are using). In order to persist data, you can use the AsyncStorage to save the user data and in the switch navigator constructor check whether the user data is already available in the storage or not then decide whether to navigate to the app or the authentication page. In fact React Navigation provides an example on this: https://reactnavigation.org/docs/en/auth-flow.html . Since you're new to RN, here's an extra tip on managing data: you can use a State in every component that is only for that specific component (which is also reactive), you can use global data (store) shared between all the components in the app (check react redux/flux/mobx), you can share data from parent components to children components by passing data/functions in the props (aka attributes), and you can use the new React context api to use a provider (also like a store shared between parent and children components)






          share|improve this answer























          • Thank your for you answer, that's not really what I want. I dont want to persist the user data but transfer it from my login component to my home component. While home is on Mainstack a BottomTabNavigator and login is on AuthStack a StackNavigator. And they're linked by the app container. I can make a little schema if you don't really understand,

            – Estro
            Mar 22 at 17:46












          • Don't you mean you wanna send the user data from one component to another? if yes, check the tip on managing data; I mentioned passing these data in the props, for me I am using mobx to create a store where i can import it and use the data in any component.

            – MaStErNeWbIe
            Mar 22 at 18:36











          • does it will works even if one of the component is in a stackNavigator and an other one in a bottomTabNavigator ? The only thing that they share is an AppContainer from their parents

            – Estro
            Mar 22 at 21:48


















          0














          I've made something maybe a bit more understandable :



          Diagram tree



          I get my user data in component login from an external api and it works well. To go from login to home I'm using this :



          this.props.navigation.navigate('Main', User: User)


          So it goes on Main who opens Mainstack Screen who's a bottomTabNavigator and if I don't do any mistakes my User data that I've sent is on this Mainstack but I don't know how to get it and how to share it to the other components.
          Every component got his own js file, there is only the App container and Authstack/Mainstack that are on the same file.



          Hope you understood it !






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55290833%2fhow-to-pass-data-from-one-component-to-navigator-and-from-navigator-to-component%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You'll probably want to persist the user data in the app (save it in the storage for when the user leaves the app then enters he stays logged in). That's why react-navigation has the switchNavigator (the one you are using). In order to persist data, you can use the AsyncStorage to save the user data and in the switch navigator constructor check whether the user data is already available in the storage or not then decide whether to navigate to the app or the authentication page. In fact React Navigation provides an example on this: https://reactnavigation.org/docs/en/auth-flow.html . Since you're new to RN, here's an extra tip on managing data: you can use a State in every component that is only for that specific component (which is also reactive), you can use global data (store) shared between all the components in the app (check react redux/flux/mobx), you can share data from parent components to children components by passing data/functions in the props (aka attributes), and you can use the new React context api to use a provider (also like a store shared between parent and children components)






            share|improve this answer























            • Thank your for you answer, that's not really what I want. I dont want to persist the user data but transfer it from my login component to my home component. While home is on Mainstack a BottomTabNavigator and login is on AuthStack a StackNavigator. And they're linked by the app container. I can make a little schema if you don't really understand,

              – Estro
              Mar 22 at 17:46












            • Don't you mean you wanna send the user data from one component to another? if yes, check the tip on managing data; I mentioned passing these data in the props, for me I am using mobx to create a store where i can import it and use the data in any component.

              – MaStErNeWbIe
              Mar 22 at 18:36











            • does it will works even if one of the component is in a stackNavigator and an other one in a bottomTabNavigator ? The only thing that they share is an AppContainer from their parents

              – Estro
              Mar 22 at 21:48















            0














            You'll probably want to persist the user data in the app (save it in the storage for when the user leaves the app then enters he stays logged in). That's why react-navigation has the switchNavigator (the one you are using). In order to persist data, you can use the AsyncStorage to save the user data and in the switch navigator constructor check whether the user data is already available in the storage or not then decide whether to navigate to the app or the authentication page. In fact React Navigation provides an example on this: https://reactnavigation.org/docs/en/auth-flow.html . Since you're new to RN, here's an extra tip on managing data: you can use a State in every component that is only for that specific component (which is also reactive), you can use global data (store) shared between all the components in the app (check react redux/flux/mobx), you can share data from parent components to children components by passing data/functions in the props (aka attributes), and you can use the new React context api to use a provider (also like a store shared between parent and children components)






            share|improve this answer























            • Thank your for you answer, that's not really what I want. I dont want to persist the user data but transfer it from my login component to my home component. While home is on Mainstack a BottomTabNavigator and login is on AuthStack a StackNavigator. And they're linked by the app container. I can make a little schema if you don't really understand,

              – Estro
              Mar 22 at 17:46












            • Don't you mean you wanna send the user data from one component to another? if yes, check the tip on managing data; I mentioned passing these data in the props, for me I am using mobx to create a store where i can import it and use the data in any component.

              – MaStErNeWbIe
              Mar 22 at 18:36











            • does it will works even if one of the component is in a stackNavigator and an other one in a bottomTabNavigator ? The only thing that they share is an AppContainer from their parents

              – Estro
              Mar 22 at 21:48













            0












            0








            0







            You'll probably want to persist the user data in the app (save it in the storage for when the user leaves the app then enters he stays logged in). That's why react-navigation has the switchNavigator (the one you are using). In order to persist data, you can use the AsyncStorage to save the user data and in the switch navigator constructor check whether the user data is already available in the storage or not then decide whether to navigate to the app or the authentication page. In fact React Navigation provides an example on this: https://reactnavigation.org/docs/en/auth-flow.html . Since you're new to RN, here's an extra tip on managing data: you can use a State in every component that is only for that specific component (which is also reactive), you can use global data (store) shared between all the components in the app (check react redux/flux/mobx), you can share data from parent components to children components by passing data/functions in the props (aka attributes), and you can use the new React context api to use a provider (also like a store shared between parent and children components)






            share|improve this answer













            You'll probably want to persist the user data in the app (save it in the storage for when the user leaves the app then enters he stays logged in). That's why react-navigation has the switchNavigator (the one you are using). In order to persist data, you can use the AsyncStorage to save the user data and in the switch navigator constructor check whether the user data is already available in the storage or not then decide whether to navigate to the app or the authentication page. In fact React Navigation provides an example on this: https://reactnavigation.org/docs/en/auth-flow.html . Since you're new to RN, here's an extra tip on managing data: you can use a State in every component that is only for that specific component (which is also reactive), you can use global data (store) shared between all the components in the app (check react redux/flux/mobx), you can share data from parent components to children components by passing data/functions in the props (aka attributes), and you can use the new React context api to use a provider (also like a store shared between parent and children components)







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 22 at 0:14









            MaStErNeWbIeMaStErNeWbIe

            15012




            15012












            • Thank your for you answer, that's not really what I want. I dont want to persist the user data but transfer it from my login component to my home component. While home is on Mainstack a BottomTabNavigator and login is on AuthStack a StackNavigator. And they're linked by the app container. I can make a little schema if you don't really understand,

              – Estro
              Mar 22 at 17:46












            • Don't you mean you wanna send the user data from one component to another? if yes, check the tip on managing data; I mentioned passing these data in the props, for me I am using mobx to create a store where i can import it and use the data in any component.

              – MaStErNeWbIe
              Mar 22 at 18:36











            • does it will works even if one of the component is in a stackNavigator and an other one in a bottomTabNavigator ? The only thing that they share is an AppContainer from their parents

              – Estro
              Mar 22 at 21:48

















            • Thank your for you answer, that's not really what I want. I dont want to persist the user data but transfer it from my login component to my home component. While home is on Mainstack a BottomTabNavigator and login is on AuthStack a StackNavigator. And they're linked by the app container. I can make a little schema if you don't really understand,

              – Estro
              Mar 22 at 17:46












            • Don't you mean you wanna send the user data from one component to another? if yes, check the tip on managing data; I mentioned passing these data in the props, for me I am using mobx to create a store where i can import it and use the data in any component.

              – MaStErNeWbIe
              Mar 22 at 18:36











            • does it will works even if one of the component is in a stackNavigator and an other one in a bottomTabNavigator ? The only thing that they share is an AppContainer from their parents

              – Estro
              Mar 22 at 21:48
















            Thank your for you answer, that's not really what I want. I dont want to persist the user data but transfer it from my login component to my home component. While home is on Mainstack a BottomTabNavigator and login is on AuthStack a StackNavigator. And they're linked by the app container. I can make a little schema if you don't really understand,

            – Estro
            Mar 22 at 17:46






            Thank your for you answer, that's not really what I want. I dont want to persist the user data but transfer it from my login component to my home component. While home is on Mainstack a BottomTabNavigator and login is on AuthStack a StackNavigator. And they're linked by the app container. I can make a little schema if you don't really understand,

            – Estro
            Mar 22 at 17:46














            Don't you mean you wanna send the user data from one component to another? if yes, check the tip on managing data; I mentioned passing these data in the props, for me I am using mobx to create a store where i can import it and use the data in any component.

            – MaStErNeWbIe
            Mar 22 at 18:36





            Don't you mean you wanna send the user data from one component to another? if yes, check the tip on managing data; I mentioned passing these data in the props, for me I am using mobx to create a store where i can import it and use the data in any component.

            – MaStErNeWbIe
            Mar 22 at 18:36













            does it will works even if one of the component is in a stackNavigator and an other one in a bottomTabNavigator ? The only thing that they share is an AppContainer from their parents

            – Estro
            Mar 22 at 21:48





            does it will works even if one of the component is in a stackNavigator and an other one in a bottomTabNavigator ? The only thing that they share is an AppContainer from their parents

            – Estro
            Mar 22 at 21:48













            0














            I've made something maybe a bit more understandable :



            Diagram tree



            I get my user data in component login from an external api and it works well. To go from login to home I'm using this :



            this.props.navigation.navigate('Main', User: User)


            So it goes on Main who opens Mainstack Screen who's a bottomTabNavigator and if I don't do any mistakes my User data that I've sent is on this Mainstack but I don't know how to get it and how to share it to the other components.
            Every component got his own js file, there is only the App container and Authstack/Mainstack that are on the same file.



            Hope you understood it !






            share|improve this answer



























              0














              I've made something maybe a bit more understandable :



              Diagram tree



              I get my user data in component login from an external api and it works well. To go from login to home I'm using this :



              this.props.navigation.navigate('Main', User: User)


              So it goes on Main who opens Mainstack Screen who's a bottomTabNavigator and if I don't do any mistakes my User data that I've sent is on this Mainstack but I don't know how to get it and how to share it to the other components.
              Every component got his own js file, there is only the App container and Authstack/Mainstack that are on the same file.



              Hope you understood it !






              share|improve this answer

























                0












                0








                0







                I've made something maybe a bit more understandable :



                Diagram tree



                I get my user data in component login from an external api and it works well. To go from login to home I'm using this :



                this.props.navigation.navigate('Main', User: User)


                So it goes on Main who opens Mainstack Screen who's a bottomTabNavigator and if I don't do any mistakes my User data that I've sent is on this Mainstack but I don't know how to get it and how to share it to the other components.
                Every component got his own js file, there is only the App container and Authstack/Mainstack that are on the same file.



                Hope you understood it !






                share|improve this answer













                I've made something maybe a bit more understandable :



                Diagram tree



                I get my user data in component login from an external api and it works well. To go from login to home I'm using this :



                this.props.navigation.navigate('Main', User: User)


                So it goes on Main who opens Mainstack Screen who's a bottomTabNavigator and if I don't do any mistakes my User data that I've sent is on this Mainstack but I don't know how to get it and how to share it to the other components.
                Every component got his own js file, there is only the App container and Authstack/Mainstack that are on the same file.



                Hope you understood it !







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 22 at 18:04









                EstroEstro

                161




                161



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55290833%2fhow-to-pass-data-from-one-component-to-navigator-and-from-navigator-to-component%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript