How to pass Mobx store to BottomTabs from another screen using React-Native-Navigation V2?











up vote
0
down vote

favorite












I'm relatively new to React Native and I'm a little confused about combining MobX with React Native Navigation (by Wix) and passing the stores.



One concrete example:



I have a single Login component as root which has a store injected by using Provider in it's wrapper and inject in the component, the store is updated for example with the user name, and finally a method is invoked called goToMain, which sets up a bottom tab layout.



export const goToMain = () => Navigation.setRoot({
root: {
bottomTabs: {
children: [{
stack: {
children: [{
component: {
name: "Tab1",
passProps: {
text: 'This is tab 1'
}
}
}],
options: {
bottomTab: {
text: "Tab1",
icon: require('../../assets/icons/test_tab_icon.png'),
testID: "TAB_"'
}
}
}
},
{
stack: {
children: [{
component: {
name: "Tab2",
passProps: {
text: "This is tab 2"
}
}
}],
options: {
bottomTab: {
text: "Tab2",
icon: require('../../assets/icons/test_tab_icon.png'),
testID: "TAB_2"
}
}
}
}]
}
}


So far so good but I would like to pass the store from the Login to the tabs so they have access to the user name or other attributes from the store but I have no idea how to do that.



Do I have to play around with the structure of the screens and root or maybe use Provider in some other way?



Would be great to hear an expert opinion on the topic. :)










share|improve this question


























    up vote
    0
    down vote

    favorite












    I'm relatively new to React Native and I'm a little confused about combining MobX with React Native Navigation (by Wix) and passing the stores.



    One concrete example:



    I have a single Login component as root which has a store injected by using Provider in it's wrapper and inject in the component, the store is updated for example with the user name, and finally a method is invoked called goToMain, which sets up a bottom tab layout.



    export const goToMain = () => Navigation.setRoot({
    root: {
    bottomTabs: {
    children: [{
    stack: {
    children: [{
    component: {
    name: "Tab1",
    passProps: {
    text: 'This is tab 1'
    }
    }
    }],
    options: {
    bottomTab: {
    text: "Tab1",
    icon: require('../../assets/icons/test_tab_icon.png'),
    testID: "TAB_"'
    }
    }
    }
    },
    {
    stack: {
    children: [{
    component: {
    name: "Tab2",
    passProps: {
    text: "This is tab 2"
    }
    }
    }],
    options: {
    bottomTab: {
    text: "Tab2",
    icon: require('../../assets/icons/test_tab_icon.png'),
    testID: "TAB_2"
    }
    }
    }
    }]
    }
    }


    So far so good but I would like to pass the store from the Login to the tabs so they have access to the user name or other attributes from the store but I have no idea how to do that.



    Do I have to play around with the structure of the screens and root or maybe use Provider in some other way?



    Would be great to hear an expert opinion on the topic. :)










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm relatively new to React Native and I'm a little confused about combining MobX with React Native Navigation (by Wix) and passing the stores.



      One concrete example:



      I have a single Login component as root which has a store injected by using Provider in it's wrapper and inject in the component, the store is updated for example with the user name, and finally a method is invoked called goToMain, which sets up a bottom tab layout.



      export const goToMain = () => Navigation.setRoot({
      root: {
      bottomTabs: {
      children: [{
      stack: {
      children: [{
      component: {
      name: "Tab1",
      passProps: {
      text: 'This is tab 1'
      }
      }
      }],
      options: {
      bottomTab: {
      text: "Tab1",
      icon: require('../../assets/icons/test_tab_icon.png'),
      testID: "TAB_"'
      }
      }
      }
      },
      {
      stack: {
      children: [{
      component: {
      name: "Tab2",
      passProps: {
      text: "This is tab 2"
      }
      }
      }],
      options: {
      bottomTab: {
      text: "Tab2",
      icon: require('../../assets/icons/test_tab_icon.png'),
      testID: "TAB_2"
      }
      }
      }
      }]
      }
      }


      So far so good but I would like to pass the store from the Login to the tabs so they have access to the user name or other attributes from the store but I have no idea how to do that.



      Do I have to play around with the structure of the screens and root or maybe use Provider in some other way?



      Would be great to hear an expert opinion on the topic. :)










      share|improve this question













      I'm relatively new to React Native and I'm a little confused about combining MobX with React Native Navigation (by Wix) and passing the stores.



      One concrete example:



      I have a single Login component as root which has a store injected by using Provider in it's wrapper and inject in the component, the store is updated for example with the user name, and finally a method is invoked called goToMain, which sets up a bottom tab layout.



      export const goToMain = () => Navigation.setRoot({
      root: {
      bottomTabs: {
      children: [{
      stack: {
      children: [{
      component: {
      name: "Tab1",
      passProps: {
      text: 'This is tab 1'
      }
      }
      }],
      options: {
      bottomTab: {
      text: "Tab1",
      icon: require('../../assets/icons/test_tab_icon.png'),
      testID: "TAB_"'
      }
      }
      }
      },
      {
      stack: {
      children: [{
      component: {
      name: "Tab2",
      passProps: {
      text: "This is tab 2"
      }
      }
      }],
      options: {
      bottomTab: {
      text: "Tab2",
      icon: require('../../assets/icons/test_tab_icon.png'),
      testID: "TAB_2"
      }
      }
      }
      }]
      }
      }


      So far so good but I would like to pass the store from the Login to the tabs so they have access to the user name or other attributes from the store but I have no idea how to do that.



      Do I have to play around with the structure of the screens and root or maybe use Provider in some other way?



      Would be great to hear an expert opinion on the topic. :)







      react-native mobx react-native-navigation mobx-react






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 at 11:50









      Balazs Holpar

      62210




      62210





























          active

          oldest

          votes











          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',
          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%2f53374057%2fhow-to-pass-mobx-store-to-bottomtabs-from-another-screen-using-react-native-navi%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374057%2fhow-to-pass-mobx-store-to-bottomtabs-from-another-screen-using-react-native-navi%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

          Wiesbaden

          Marschland

          Dieringhausen