React “lifting state up” philosophie : How to avoid ending up with one big parent component containing all the code?










0















This is not a very precise question. I think I understand the "react lifting state up" paradigm. As far as I know, this is the only clean way for two sibling components to have access to their respective properties.



But doing so, I end up with one tremendous class containing everything : the data information for the properties of all of its child components, and all the functions in charge of updating this information (in charge of calling setState). I'm unhappy with the fact that I'm not able anymore to dispatch into sub-components, the work that has to do with them.



My question is : how to avoid the concentration of all the code in parent components, using react, while keeping the nice clean state/prop mechanism ? Or am I wrong to complain maybe ?










share|improve this question






















  • Think of it as Lifting state 'enough'. Only raise state to the point at which necessary sharing of state can happen. That will sometimes be the top of the app, but not always.

    – D Lowther
    Nov 15 '18 at 16:27











  • Lifting up state to the root component is not a good idea. Lift up state when it is necessary. I think with redux library managing state is easier because component can connect to redux store to get data. You can also update store by dispatch an action.

    – miuosh
    Nov 15 '18 at 16:34












  • "We recommend lifting the shared state up to their closest common ancestor". The "closest common ancestor" part is important, as lifting the state up higher than that would be very cumbersome, like you said.

    – Tholle
    Nov 15 '18 at 16:39















0















This is not a very precise question. I think I understand the "react lifting state up" paradigm. As far as I know, this is the only clean way for two sibling components to have access to their respective properties.



But doing so, I end up with one tremendous class containing everything : the data information for the properties of all of its child components, and all the functions in charge of updating this information (in charge of calling setState). I'm unhappy with the fact that I'm not able anymore to dispatch into sub-components, the work that has to do with them.



My question is : how to avoid the concentration of all the code in parent components, using react, while keeping the nice clean state/prop mechanism ? Or am I wrong to complain maybe ?










share|improve this question






















  • Think of it as Lifting state 'enough'. Only raise state to the point at which necessary sharing of state can happen. That will sometimes be the top of the app, but not always.

    – D Lowther
    Nov 15 '18 at 16:27











  • Lifting up state to the root component is not a good idea. Lift up state when it is necessary. I think with redux library managing state is easier because component can connect to redux store to get data. You can also update store by dispatch an action.

    – miuosh
    Nov 15 '18 at 16:34












  • "We recommend lifting the shared state up to their closest common ancestor". The "closest common ancestor" part is important, as lifting the state up higher than that would be very cumbersome, like you said.

    – Tholle
    Nov 15 '18 at 16:39













0












0








0


1






This is not a very precise question. I think I understand the "react lifting state up" paradigm. As far as I know, this is the only clean way for two sibling components to have access to their respective properties.



But doing so, I end up with one tremendous class containing everything : the data information for the properties of all of its child components, and all the functions in charge of updating this information (in charge of calling setState). I'm unhappy with the fact that I'm not able anymore to dispatch into sub-components, the work that has to do with them.



My question is : how to avoid the concentration of all the code in parent components, using react, while keeping the nice clean state/prop mechanism ? Or am I wrong to complain maybe ?










share|improve this question














This is not a very precise question. I think I understand the "react lifting state up" paradigm. As far as I know, this is the only clean way for two sibling components to have access to their respective properties.



But doing so, I end up with one tremendous class containing everything : the data information for the properties of all of its child components, and all the functions in charge of updating this information (in charge of calling setState). I'm unhappy with the fact that I'm not able anymore to dispatch into sub-components, the work that has to do with them.



My question is : how to avoid the concentration of all the code in parent components, using react, while keeping the nice clean state/prop mechanism ? Or am I wrong to complain maybe ?







javascript reactjs design-patterns






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 16:21









ArchimondainArchimondain

1577




1577












  • Think of it as Lifting state 'enough'. Only raise state to the point at which necessary sharing of state can happen. That will sometimes be the top of the app, but not always.

    – D Lowther
    Nov 15 '18 at 16:27











  • Lifting up state to the root component is not a good idea. Lift up state when it is necessary. I think with redux library managing state is easier because component can connect to redux store to get data. You can also update store by dispatch an action.

    – miuosh
    Nov 15 '18 at 16:34












  • "We recommend lifting the shared state up to their closest common ancestor". The "closest common ancestor" part is important, as lifting the state up higher than that would be very cumbersome, like you said.

    – Tholle
    Nov 15 '18 at 16:39

















  • Think of it as Lifting state 'enough'. Only raise state to the point at which necessary sharing of state can happen. That will sometimes be the top of the app, but not always.

    – D Lowther
    Nov 15 '18 at 16:27











  • Lifting up state to the root component is not a good idea. Lift up state when it is necessary. I think with redux library managing state is easier because component can connect to redux store to get data. You can also update store by dispatch an action.

    – miuosh
    Nov 15 '18 at 16:34












  • "We recommend lifting the shared state up to their closest common ancestor". The "closest common ancestor" part is important, as lifting the state up higher than that would be very cumbersome, like you said.

    – Tholle
    Nov 15 '18 at 16:39
















Think of it as Lifting state 'enough'. Only raise state to the point at which necessary sharing of state can happen. That will sometimes be the top of the app, but not always.

– D Lowther
Nov 15 '18 at 16:27





Think of it as Lifting state 'enough'. Only raise state to the point at which necessary sharing of state can happen. That will sometimes be the top of the app, but not always.

– D Lowther
Nov 15 '18 at 16:27













Lifting up state to the root component is not a good idea. Lift up state when it is necessary. I think with redux library managing state is easier because component can connect to redux store to get data. You can also update store by dispatch an action.

– miuosh
Nov 15 '18 at 16:34






Lifting up state to the root component is not a good idea. Lift up state when it is necessary. I think with redux library managing state is easier because component can connect to redux store to get data. You can also update store by dispatch an action.

– miuosh
Nov 15 '18 at 16:34














"We recommend lifting the shared state up to their closest common ancestor". The "closest common ancestor" part is important, as lifting the state up higher than that would be very cumbersome, like you said.

– Tholle
Nov 15 '18 at 16:39





"We recommend lifting the shared state up to their closest common ancestor". The "closest common ancestor" part is important, as lifting the state up higher than that would be very cumbersome, like you said.

– Tholle
Nov 15 '18 at 16:39












1 Answer
1






active

oldest

votes


















1














Many people believe jumping directly into redux would be a good idea, but in fact, it comes with lots of computational overhead and boilerplate code.



As a rule of thumb, you would simply move logic up the tree which is relevant not only for child components but also for siblings.



You should also have a look at the concept of Presentational and Container Components.






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%2f53323736%2freact-lifting-state-up-philosophie-how-to-avoid-ending-up-with-one-big-paren%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









    1














    Many people believe jumping directly into redux would be a good idea, but in fact, it comes with lots of computational overhead and boilerplate code.



    As a rule of thumb, you would simply move logic up the tree which is relevant not only for child components but also for siblings.



    You should also have a look at the concept of Presentational and Container Components.






    share|improve this answer



























      1














      Many people believe jumping directly into redux would be a good idea, but in fact, it comes with lots of computational overhead and boilerplate code.



      As a rule of thumb, you would simply move logic up the tree which is relevant not only for child components but also for siblings.



      You should also have a look at the concept of Presentational and Container Components.






      share|improve this answer

























        1












        1








        1







        Many people believe jumping directly into redux would be a good idea, but in fact, it comes with lots of computational overhead and boilerplate code.



        As a rule of thumb, you would simply move logic up the tree which is relevant not only for child components but also for siblings.



        You should also have a look at the concept of Presentational and Container Components.






        share|improve this answer













        Many people believe jumping directly into redux would be a good idea, but in fact, it comes with lots of computational overhead and boilerplate code.



        As a rule of thumb, you would simply move logic up the tree which is relevant not only for child components but also for siblings.



        You should also have a look at the concept of Presentational and Container Components.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 16:43









        Fabian HinsenkampFabian Hinsenkamp

        1716




        1716





























            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%2f53323736%2freact-lifting-state-up-philosophie-how-to-avoid-ending-up-with-one-big-paren%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







            這個網誌中的熱門文章

            What does pagestruct do in Eviews?

            Dutch intervention in Lombok and Karangasem

            Channel Islands