How can I access a portion of the state in a reducer











up vote
1
down vote

favorite












In my case I have a reducer that is a filter configuration and instead of initializing it with an object



initial_state = {ditance: 2, showMan: false ...} 


I want those values to take them from the store because the user has logged in and those values are already in the bbdd of firebase firestore,



I am using the library react-redux-firestore and that information is already in another reducer. The problem is that if I use the static initial_state when I kill the application it is no longer synchronized with what is in the database.



So what I ask is that if there is any way to be able to take in a reduce the portion of a state that there is in another reduce to generate the new state. I've seen that you can send an action or something like that but I'm looking for another way to do it, if possible .










share|improve this question




























    up vote
    1
    down vote

    favorite












    In my case I have a reducer that is a filter configuration and instead of initializing it with an object



    initial_state = {ditance: 2, showMan: false ...} 


    I want those values to take them from the store because the user has logged in and those values are already in the bbdd of firebase firestore,



    I am using the library react-redux-firestore and that information is already in another reducer. The problem is that if I use the static initial_state when I kill the application it is no longer synchronized with what is in the database.



    So what I ask is that if there is any way to be able to take in a reduce the portion of a state that there is in another reduce to generate the new state. I've seen that you can send an action or something like that but I'm looking for another way to do it, if possible .










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      In my case I have a reducer that is a filter configuration and instead of initializing it with an object



      initial_state = {ditance: 2, showMan: false ...} 


      I want those values to take them from the store because the user has logged in and those values are already in the bbdd of firebase firestore,



      I am using the library react-redux-firestore and that information is already in another reducer. The problem is that if I use the static initial_state when I kill the application it is no longer synchronized with what is in the database.



      So what I ask is that if there is any way to be able to take in a reduce the portion of a state that there is in another reduce to generate the new state. I've seen that you can send an action or something like that but I'm looking for another way to do it, if possible .










      share|improve this question















      In my case I have a reducer that is a filter configuration and instead of initializing it with an object



      initial_state = {ditance: 2, showMan: false ...} 


      I want those values to take them from the store because the user has logged in and those values are already in the bbdd of firebase firestore,



      I am using the library react-redux-firestore and that information is already in another reducer. The problem is that if I use the static initial_state when I kill the application it is no longer synchronized with what is in the database.



      So what I ask is that if there is any way to be able to take in a reduce the portion of a state that there is in another reduce to generate the new state. I've seen that you can send an action or something like that but I'm looking for another way to do it, if possible .







      reactjs redux state reducers






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 8 at 21:34









      Rajab Shakirov

      1,13241735




      1,13241735










      asked Nov 8 at 11:09









      jorge morales lopez

      62




      62
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          if data is in another reducer, you can get the value and pass it with action when you call it.



          but if it's in the same reducer, you pass two parameters essentially



          const reducer = (state = initial_state, action) = > {
          switch (action.type){
          case actionType.TOGGLE_SHOWMAN:
          return { ...state, showMan: ! state.showMan };
          default:
          return state;
          }
          }


          so you can access previous state by calling state inside the reducer






          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',
            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%2f53206542%2fhow-can-i-access-a-portion-of-the-state-in-a-reducer%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            if data is in another reducer, you can get the value and pass it with action when you call it.



            but if it's in the same reducer, you pass two parameters essentially



            const reducer = (state = initial_state, action) = > {
            switch (action.type){
            case actionType.TOGGLE_SHOWMAN:
            return { ...state, showMan: ! state.showMan };
            default:
            return state;
            }
            }


            so you can access previous state by calling state inside the reducer






            share|improve this answer

























              up vote
              0
              down vote













              if data is in another reducer, you can get the value and pass it with action when you call it.



              but if it's in the same reducer, you pass two parameters essentially



              const reducer = (state = initial_state, action) = > {
              switch (action.type){
              case actionType.TOGGLE_SHOWMAN:
              return { ...state, showMan: ! state.showMan };
              default:
              return state;
              }
              }


              so you can access previous state by calling state inside the reducer






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                if data is in another reducer, you can get the value and pass it with action when you call it.



                but if it's in the same reducer, you pass two parameters essentially



                const reducer = (state = initial_state, action) = > {
                switch (action.type){
                case actionType.TOGGLE_SHOWMAN:
                return { ...state, showMan: ! state.showMan };
                default:
                return state;
                }
                }


                so you can access previous state by calling state inside the reducer






                share|improve this answer












                if data is in another reducer, you can get the value and pass it with action when you call it.



                but if it's in the same reducer, you pass two parameters essentially



                const reducer = (state = initial_state, action) = > {
                switch (action.type){
                case actionType.TOGGLE_SHOWMAN:
                return { ...state, showMan: ! state.showMan };
                default:
                return state;
                }
                }


                so you can access previous state by calling state inside the reducer







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 9 at 9:39









                Biskrem Muhammad

                51811015




                51811015






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206542%2fhow-can-i-access-a-portion-of-the-state-in-a-reducer%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

                    Landwehr

                    Reims

                    Schenkenzell