How can I render a child component or parallel component when a state is set in ReactJS?ReactJS - Does render get called any time “setState” is called?After updating props, this.props is always === nextProps / prevPropsWhat is the difference between state and props in React?When should ReactJS components make AJAX calls to update state from props?Invariant Violation: Objects are not valid as a React childWhy do we need middleware for async flow in Redux?ReactJs - Redux State is not updating in a dropdown in the child componentHow to re-render child component?My react component isn't rendering my state when i receive a response from socket.ioIn reactjs how to update component state when mapStateToProps returns the new prop

Is there some sort of French saying for "a person's signature move"?

How can I hint that my character isn't real?

What is the purpose of the rotating plate in front of the lock?

If every star in the universe except the Sun were destroyed, would we die?

Is it right to use the ideas of non-winning designers in a design contest?

How to apply a register to a command

Sinning and G-d's will, what's wrong with this logic?

Putting future professor position on CV

Project Euler Problem 45

How to interpret or parse this confusing 'NOT' and 'AND' legal clause

Examples where "thin + thin = nice and thick"

How strong is aircraft-grade spruce?

Is mountain bike good for long distances?

Why can't some airports handle heavy aircraft while others do it easily (same runway length)?

"syntax error near unexpected token" after editing .bashrc

Should I tip on the Amtrak train?

Can taking my 1-week-old on a 6-7 hours journey in the car lead to medical complications?

First Number to Contain Each Letter

Contractor cut joist hangers to make them fit

Do 643,000 Americans go bankrupt every year due to medical bills?

What is the "Brake to Exit" feature on the Boeing 777X?

Fantasy Military Arms and Armor: the Dwarven Grand Armory

Project Euler problem #112

What makes an ending "happy"?



How can I render a child component or parallel component when a state is set in ReactJS?


ReactJS - Does render get called any time “setState” is called?After updating props, this.props is always === nextProps / prevPropsWhat is the difference between state and props in React?When should ReactJS components make AJAX calls to update state from props?Invariant Violation: Objects are not valid as a React childWhy do we need middleware for async flow in Redux?ReactJs - Redux State is not updating in a dropdown in the child componentHow to re-render child component?My react component isn't rendering my state when i receive a response from socket.ioIn reactjs how to update component state when mapStateToProps returns the new prop






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















How can I render a child component or parallel component when a state is set?



Main component contains the following code



editValue(data) 
console.log("edited")
this.setState( edits:data , function()
console.log("edited value...")
)

render()
return(
<div>
<TextComponent edit=this.editValue.bind(this)/>
<AreaComponent editedValue = this.state.edits/>
</div>
)



TextComponent:



trigger = (data) => 
this.props.edit(data)


render()
return (
<div>
<p onClick=this.trigger.bind(this,'clicked')>Click</p>
</div>
)



AreaComponent:



componentDidUpdate() 
console.log("update - component")


componentWillReceiveProps(nextProps)
console.log('receive - component');



Here when I click the <p> I got my console as following



edited
receive - component
update - component
edited value...


What my issue is the edited value that I set in state is not reflecting in my AreaComponent. All the componentDidUpdate() and componentWillReceiveProps() are triggered before setting the state. I want to get the state value inside my next component. What changes should I do in this code?










share|improve this question
























  • The child liofecycle method are not triggered before state is set, instead the callback to setState is triggered after the child lifecycle method are called. Also how are you checking that the state has not updated and and how are you passing data to the editValue componet

    – Shubham Khatri
    Mar 28 at 6:10











  • The state is updated but only after the re-rendering of the components. I got this by checking the console values

    – Hareesh
    Mar 28 at 6:20

















0















How can I render a child component or parallel component when a state is set?



Main component contains the following code



editValue(data) 
console.log("edited")
this.setState( edits:data , function()
console.log("edited value...")
)

render()
return(
<div>
<TextComponent edit=this.editValue.bind(this)/>
<AreaComponent editedValue = this.state.edits/>
</div>
)



TextComponent:



trigger = (data) => 
this.props.edit(data)


render()
return (
<div>
<p onClick=this.trigger.bind(this,'clicked')>Click</p>
</div>
)



AreaComponent:



componentDidUpdate() 
console.log("update - component")


componentWillReceiveProps(nextProps)
console.log('receive - component');



Here when I click the <p> I got my console as following



edited
receive - component
update - component
edited value...


What my issue is the edited value that I set in state is not reflecting in my AreaComponent. All the componentDidUpdate() and componentWillReceiveProps() are triggered before setting the state. I want to get the state value inside my next component. What changes should I do in this code?










share|improve this question
























  • The child liofecycle method are not triggered before state is set, instead the callback to setState is triggered after the child lifecycle method are called. Also how are you checking that the state has not updated and and how are you passing data to the editValue componet

    – Shubham Khatri
    Mar 28 at 6:10











  • The state is updated but only after the re-rendering of the components. I got this by checking the console values

    – Hareesh
    Mar 28 at 6:20













0












0








0


1






How can I render a child component or parallel component when a state is set?



Main component contains the following code



editValue(data) 
console.log("edited")
this.setState( edits:data , function()
console.log("edited value...")
)

render()
return(
<div>
<TextComponent edit=this.editValue.bind(this)/>
<AreaComponent editedValue = this.state.edits/>
</div>
)



TextComponent:



trigger = (data) => 
this.props.edit(data)


render()
return (
<div>
<p onClick=this.trigger.bind(this,'clicked')>Click</p>
</div>
)



AreaComponent:



componentDidUpdate() 
console.log("update - component")


componentWillReceiveProps(nextProps)
console.log('receive - component');



Here when I click the <p> I got my console as following



edited
receive - component
update - component
edited value...


What my issue is the edited value that I set in state is not reflecting in my AreaComponent. All the componentDidUpdate() and componentWillReceiveProps() are triggered before setting the state. I want to get the state value inside my next component. What changes should I do in this code?










share|improve this question














How can I render a child component or parallel component when a state is set?



Main component contains the following code



editValue(data) 
console.log("edited")
this.setState( edits:data , function()
console.log("edited value...")
)

render()
return(
<div>
<TextComponent edit=this.editValue.bind(this)/>
<AreaComponent editedValue = this.state.edits/>
</div>
)



TextComponent:



trigger = (data) => 
this.props.edit(data)


render()
return (
<div>
<p onClick=this.trigger.bind(this,'clicked')>Click</p>
</div>
)



AreaComponent:



componentDidUpdate() 
console.log("update - component")


componentWillReceiveProps(nextProps)
console.log('receive - component');



Here when I click the <p> I got my console as following



edited
receive - component
update - component
edited value...


What my issue is the edited value that I set in state is not reflecting in my AreaComponent. All the componentDidUpdate() and componentWillReceiveProps() are triggered before setting the state. I want to get the state value inside my next component. What changes should I do in this code?







reactjs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 5:59









HareeshHareesh

6957 silver badges23 bronze badges




6957 silver badges23 bronze badges















  • The child liofecycle method are not triggered before state is set, instead the callback to setState is triggered after the child lifecycle method are called. Also how are you checking that the state has not updated and and how are you passing data to the editValue componet

    – Shubham Khatri
    Mar 28 at 6:10











  • The state is updated but only after the re-rendering of the components. I got this by checking the console values

    – Hareesh
    Mar 28 at 6:20

















  • The child liofecycle method are not triggered before state is set, instead the callback to setState is triggered after the child lifecycle method are called. Also how are you checking that the state has not updated and and how are you passing data to the editValue componet

    – Shubham Khatri
    Mar 28 at 6:10











  • The state is updated but only after the re-rendering of the components. I got this by checking the console values

    – Hareesh
    Mar 28 at 6:20
















The child liofecycle method are not triggered before state is set, instead the callback to setState is triggered after the child lifecycle method are called. Also how are you checking that the state has not updated and and how are you passing data to the editValue componet

– Shubham Khatri
Mar 28 at 6:10





The child liofecycle method are not triggered before state is set, instead the callback to setState is triggered after the child lifecycle method are called. Also how are you checking that the state has not updated and and how are you passing data to the editValue componet

– Shubham Khatri
Mar 28 at 6:10













The state is updated but only after the re-rendering of the components. I got this by checking the console values

– Hareesh
Mar 28 at 6:20





The state is updated but only after the re-rendering of the components. I got this by checking the console values

– Hareesh
Mar 28 at 6:20












2 Answers
2






active

oldest

votes


















1
















You seem to be misInterpreting the console results, you have looged edited value.. in the setState callback which is triggered after the component has updated due to a state change.



If you actually look into the componentWillReceiveProps and componentDidUpdate of childComponent and log the props in these lifecycle or as a matter of fact in render method you could actually see the updated value that you set in state.



You should think of setState callback as a lifecycle which is triggered after component updates similar to componentDidUpdate and componentDidUpdate of parent is triggered after componentDidUpdate of child components most often






share|improve this answer
































    1
















    Hey I tested out your code and it functions as you expected.



    Here's a sandbox for you: https://codesandbox.io/s/7yry1onrq6



    In order for you to see the changes after you click TextComponent just use the editedValue prop in the AreaComponent.



    This is an example mirroring your code:



    class AreaComponent extends React.Component 
    componentDidUpdate()
    console.log("update - component");


    componentWillReceiveProps(nextProps)
    console.log("receive - component");

    render()
    return <p>this.props.editedValue</p>;




    In the above example the editedValue is correctly changing after clicking.






    share|improve this answer

























    • Yes this works. Thanks for your suggestions

      – Hareesh
      Mar 28 at 6:53













    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/4.0/"u003ecc by-sa 4.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%2f55391028%2fhow-can-i-render-a-child-component-or-parallel-component-when-a-state-is-set-in%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









    1
















    You seem to be misInterpreting the console results, you have looged edited value.. in the setState callback which is triggered after the component has updated due to a state change.



    If you actually look into the componentWillReceiveProps and componentDidUpdate of childComponent and log the props in these lifecycle or as a matter of fact in render method you could actually see the updated value that you set in state.



    You should think of setState callback as a lifecycle which is triggered after component updates similar to componentDidUpdate and componentDidUpdate of parent is triggered after componentDidUpdate of child components most often






    share|improve this answer





























      1
















      You seem to be misInterpreting the console results, you have looged edited value.. in the setState callback which is triggered after the component has updated due to a state change.



      If you actually look into the componentWillReceiveProps and componentDidUpdate of childComponent and log the props in these lifecycle or as a matter of fact in render method you could actually see the updated value that you set in state.



      You should think of setState callback as a lifecycle which is triggered after component updates similar to componentDidUpdate and componentDidUpdate of parent is triggered after componentDidUpdate of child components most often






      share|improve this answer



























        1














        1










        1









        You seem to be misInterpreting the console results, you have looged edited value.. in the setState callback which is triggered after the component has updated due to a state change.



        If you actually look into the componentWillReceiveProps and componentDidUpdate of childComponent and log the props in these lifecycle or as a matter of fact in render method you could actually see the updated value that you set in state.



        You should think of setState callback as a lifecycle which is triggered after component updates similar to componentDidUpdate and componentDidUpdate of parent is triggered after componentDidUpdate of child components most often






        share|improve this answer













        You seem to be misInterpreting the console results, you have looged edited value.. in the setState callback which is triggered after the component has updated due to a state change.



        If you actually look into the componentWillReceiveProps and componentDidUpdate of childComponent and log the props in these lifecycle or as a matter of fact in render method you could actually see the updated value that you set in state.



        You should think of setState callback as a lifecycle which is triggered after component updates similar to componentDidUpdate and componentDidUpdate of parent is triggered after componentDidUpdate of child components most often







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 7:01









        Shubham KhatriShubham Khatri

        117k23 gold badges165 silver badges202 bronze badges




        117k23 gold badges165 silver badges202 bronze badges


























            1
















            Hey I tested out your code and it functions as you expected.



            Here's a sandbox for you: https://codesandbox.io/s/7yry1onrq6



            In order for you to see the changes after you click TextComponent just use the editedValue prop in the AreaComponent.



            This is an example mirroring your code:



            class AreaComponent extends React.Component 
            componentDidUpdate()
            console.log("update - component");


            componentWillReceiveProps(nextProps)
            console.log("receive - component");

            render()
            return <p>this.props.editedValue</p>;




            In the above example the editedValue is correctly changing after clicking.






            share|improve this answer

























            • Yes this works. Thanks for your suggestions

              – Hareesh
              Mar 28 at 6:53















            1
















            Hey I tested out your code and it functions as you expected.



            Here's a sandbox for you: https://codesandbox.io/s/7yry1onrq6



            In order for you to see the changes after you click TextComponent just use the editedValue prop in the AreaComponent.



            This is an example mirroring your code:



            class AreaComponent extends React.Component 
            componentDidUpdate()
            console.log("update - component");


            componentWillReceiveProps(nextProps)
            console.log("receive - component");

            render()
            return <p>this.props.editedValue</p>;




            In the above example the editedValue is correctly changing after clicking.






            share|improve this answer

























            • Yes this works. Thanks for your suggestions

              – Hareesh
              Mar 28 at 6:53













            1














            1










            1









            Hey I tested out your code and it functions as you expected.



            Here's a sandbox for you: https://codesandbox.io/s/7yry1onrq6



            In order for you to see the changes after you click TextComponent just use the editedValue prop in the AreaComponent.



            This is an example mirroring your code:



            class AreaComponent extends React.Component 
            componentDidUpdate()
            console.log("update - component");


            componentWillReceiveProps(nextProps)
            console.log("receive - component");

            render()
            return <p>this.props.editedValue</p>;




            In the above example the editedValue is correctly changing after clicking.






            share|improve this answer













            Hey I tested out your code and it functions as you expected.



            Here's a sandbox for you: https://codesandbox.io/s/7yry1onrq6



            In order for you to see the changes after you click TextComponent just use the editedValue prop in the AreaComponent.



            This is an example mirroring your code:



            class AreaComponent extends React.Component 
            componentDidUpdate()
            console.log("update - component");


            componentWillReceiveProps(nextProps)
            console.log("receive - component");

            render()
            return <p>this.props.editedValue</p>;




            In the above example the editedValue is correctly changing after clicking.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 28 at 6:20









            JaaqoJaaqo

            565 bronze badges




            565 bronze badges















            • Yes this works. Thanks for your suggestions

              – Hareesh
              Mar 28 at 6:53

















            • Yes this works. Thanks for your suggestions

              – Hareesh
              Mar 28 at 6:53
















            Yes this works. Thanks for your suggestions

            – Hareesh
            Mar 28 at 6:53





            Yes this works. Thanks for your suggestions

            – Hareesh
            Mar 28 at 6:53


















            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%2f55391028%2fhow-can-i-render-a-child-component-or-parallel-component-when-a-state-is-set-in%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

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해