Run render and reconciler on children only





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







0















I want to skip rendering of container, but run rendering and reconciliation for the childeren passed via props. In the next example you can click it and see



render
render2
render value 2001
render value 3001


but I want it to be



render
render value 1001
render2
render value 2001
render value 3001


So I want Value 1001 to render, but without rendering Wrapper1.



How can I do that?






class Value extends React.Component {
render() {
console.log("render value " + this.props.value);
return this.props.value;
}
}

class Wrapper1 extends React.Component {
shouldComponentUpdate() {
return false;
}

render() {
console.log("render1");
return this.props.children;
}
}

class Wrapper2 extends React.PureComponent {
render() {
console.log("render2");
return this.props.children;
}
}

class App extends React.Component {
state = { count: 0 };

render() {
console.log("render");
return (
<div onClick={() => this.setState(({ count }) => ({ count: count + 1 }))}>
<Wrapper1><Value value={1000 + this.state.count} /></Wrapper1>
{" "}
<Wrapper2><Value value={2000 + this.state.count} /></Wrapper2>
{" "}
<Value value={3000 + this.state.count} />
</div>
);
}
}

ReactDOM.render(<App />, document.querySelector("main"));

<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>

<main></main>












share|improve this question























  • Why do you need Wrapper1? And why do you want to skip rendering it? Check stackoverflow.com/questions/30626030/…

    – UjinT34
    Nov 26 '18 at 14:20


















0















I want to skip rendering of container, but run rendering and reconciliation for the childeren passed via props. In the next example you can click it and see



render
render2
render value 2001
render value 3001


but I want it to be



render
render value 1001
render2
render value 2001
render value 3001


So I want Value 1001 to render, but without rendering Wrapper1.



How can I do that?






class Value extends React.Component {
render() {
console.log("render value " + this.props.value);
return this.props.value;
}
}

class Wrapper1 extends React.Component {
shouldComponentUpdate() {
return false;
}

render() {
console.log("render1");
return this.props.children;
}
}

class Wrapper2 extends React.PureComponent {
render() {
console.log("render2");
return this.props.children;
}
}

class App extends React.Component {
state = { count: 0 };

render() {
console.log("render");
return (
<div onClick={() => this.setState(({ count }) => ({ count: count + 1 }))}>
<Wrapper1><Value value={1000 + this.state.count} /></Wrapper1>
{" "}
<Wrapper2><Value value={2000 + this.state.count} /></Wrapper2>
{" "}
<Value value={3000 + this.state.count} />
</div>
);
}
}

ReactDOM.render(<App />, document.querySelector("main"));

<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>

<main></main>












share|improve this question























  • Why do you need Wrapper1? And why do you want to skip rendering it? Check stackoverflow.com/questions/30626030/…

    – UjinT34
    Nov 26 '18 at 14:20














0












0








0








I want to skip rendering of container, but run rendering and reconciliation for the childeren passed via props. In the next example you can click it and see



render
render2
render value 2001
render value 3001


but I want it to be



render
render value 1001
render2
render value 2001
render value 3001


So I want Value 1001 to render, but without rendering Wrapper1.



How can I do that?






class Value extends React.Component {
render() {
console.log("render value " + this.props.value);
return this.props.value;
}
}

class Wrapper1 extends React.Component {
shouldComponentUpdate() {
return false;
}

render() {
console.log("render1");
return this.props.children;
}
}

class Wrapper2 extends React.PureComponent {
render() {
console.log("render2");
return this.props.children;
}
}

class App extends React.Component {
state = { count: 0 };

render() {
console.log("render");
return (
<div onClick={() => this.setState(({ count }) => ({ count: count + 1 }))}>
<Wrapper1><Value value={1000 + this.state.count} /></Wrapper1>
{" "}
<Wrapper2><Value value={2000 + this.state.count} /></Wrapper2>
{" "}
<Value value={3000 + this.state.count} />
</div>
);
}
}

ReactDOM.render(<App />, document.querySelector("main"));

<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>

<main></main>












share|improve this question














I want to skip rendering of container, but run rendering and reconciliation for the childeren passed via props. In the next example you can click it and see



render
render2
render value 2001
render value 3001


but I want it to be



render
render value 1001
render2
render value 2001
render value 3001


So I want Value 1001 to render, but without rendering Wrapper1.



How can I do that?






class Value extends React.Component {
render() {
console.log("render value " + this.props.value);
return this.props.value;
}
}

class Wrapper1 extends React.Component {
shouldComponentUpdate() {
return false;
}

render() {
console.log("render1");
return this.props.children;
}
}

class Wrapper2 extends React.PureComponent {
render() {
console.log("render2");
return this.props.children;
}
}

class App extends React.Component {
state = { count: 0 };

render() {
console.log("render");
return (
<div onClick={() => this.setState(({ count }) => ({ count: count + 1 }))}>
<Wrapper1><Value value={1000 + this.state.count} /></Wrapper1>
{" "}
<Wrapper2><Value value={2000 + this.state.count} /></Wrapper2>
{" "}
<Value value={3000 + this.state.count} />
</div>
);
}
}

ReactDOM.render(<App />, document.querySelector("main"));

<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>

<main></main>








class Value extends React.Component {
render() {
console.log("render value " + this.props.value);
return this.props.value;
}
}

class Wrapper1 extends React.Component {
shouldComponentUpdate() {
return false;
}

render() {
console.log("render1");
return this.props.children;
}
}

class Wrapper2 extends React.PureComponent {
render() {
console.log("render2");
return this.props.children;
}
}

class App extends React.Component {
state = { count: 0 };

render() {
console.log("render");
return (
<div onClick={() => this.setState(({ count }) => ({ count: count + 1 }))}>
<Wrapper1><Value value={1000 + this.state.count} /></Wrapper1>
{" "}
<Wrapper2><Value value={2000 + this.state.count} /></Wrapper2>
{" "}
<Value value={3000 + this.state.count} />
</div>
);
}
}

ReactDOM.render(<App />, document.querySelector("main"));

<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>

<main></main>





class Value extends React.Component {
render() {
console.log("render value " + this.props.value);
return this.props.value;
}
}

class Wrapper1 extends React.Component {
shouldComponentUpdate() {
return false;
}

render() {
console.log("render1");
return this.props.children;
}
}

class Wrapper2 extends React.PureComponent {
render() {
console.log("render2");
return this.props.children;
}
}

class App extends React.Component {
state = { count: 0 };

render() {
console.log("render");
return (
<div onClick={() => this.setState(({ count }) => ({ count: count + 1 }))}>
<Wrapper1><Value value={1000 + this.state.count} /></Wrapper1>
{" "}
<Wrapper2><Value value={2000 + this.state.count} /></Wrapper2>
{" "}
<Value value={3000 + this.state.count} />
</div>
);
}
}

ReactDOM.render(<App />, document.querySelector("main"));

<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>

<main></main>






reactjs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 26 '18 at 13:58









QwertiyQwertiy

7,47052365




7,47052365













  • Why do you need Wrapper1? And why do you want to skip rendering it? Check stackoverflow.com/questions/30626030/…

    – UjinT34
    Nov 26 '18 at 14:20



















  • Why do you need Wrapper1? And why do you want to skip rendering it? Check stackoverflow.com/questions/30626030/…

    – UjinT34
    Nov 26 '18 at 14:20

















Why do you need Wrapper1? And why do you want to skip rendering it? Check stackoverflow.com/questions/30626030/…

– UjinT34
Nov 26 '18 at 14:20





Why do you need Wrapper1? And why do you want to skip rendering it? Check stackoverflow.com/questions/30626030/…

– UjinT34
Nov 26 '18 at 14:20












2 Answers
2






active

oldest

votes


















1














To rerender children without rerendering Wrapper1 you need to change their state somehow. Note that props of Value inside Wrapper1 never change. So forced renders will output the same value unless you pass it some other way. There is some bad code for example:






class Value extends React.Component {
state = {value: null};

componentDidMount() {
if (typeof(this.props.setUpdater) === 'function') this.props.setUpdater(
value => this.setState({value})
);
}

render() {
console.log("render value ", this.state.value, this.props.value);
return this.state.value || this.props.value;
}
}

class Wrapper1 extends React.Component {
shouldComponentUpdate() {
return false;
}

render() {
console.log("render1");
return this.props.children;
}
}

class Wrapper2 extends React.PureComponent {
render() {
console.log("render2");
return this.props.children;
}
}

class App extends React.Component {
state = { count: 0 };

render() {
console.log("render");
if (typeof(this.state.updater) === 'function') this.state.updater(1000 + this.state.count);
return (
<div onClick={() => this.setState(({ count }) => ({ count: count + 1 }))}>
<Wrapper1><Value value={1000 + this.state.count} setUpdater={updater => this.setState({updater})}/></Wrapper1>
{" "}
<Wrapper2><Value value={2000 + this.state.count} /></Wrapper2>
{" "}
<Value value={3000 + this.state.count} />
</div>
);
}
}

ReactDOM.render(<App />, document.querySelector("main"));

<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>

<main></main>








share|improve this answer































    0














    Try using shouldComponentUpdate






    share|improve this answer
























    • It's already in the example. How do you propose to use it?

      – Qwertiy
      Nov 26 '18 at 16:14












    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%2f53482717%2frun-render-and-reconciler-on-children-only%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














    To rerender children without rerendering Wrapper1 you need to change their state somehow. Note that props of Value inside Wrapper1 never change. So forced renders will output the same value unless you pass it some other way. There is some bad code for example:






    class Value extends React.Component {
    state = {value: null};

    componentDidMount() {
    if (typeof(this.props.setUpdater) === 'function') this.props.setUpdater(
    value => this.setState({value})
    );
    }

    render() {
    console.log("render value ", this.state.value, this.props.value);
    return this.state.value || this.props.value;
    }
    }

    class Wrapper1 extends React.Component {
    shouldComponentUpdate() {
    return false;
    }

    render() {
    console.log("render1");
    return this.props.children;
    }
    }

    class Wrapper2 extends React.PureComponent {
    render() {
    console.log("render2");
    return this.props.children;
    }
    }

    class App extends React.Component {
    state = { count: 0 };

    render() {
    console.log("render");
    if (typeof(this.state.updater) === 'function') this.state.updater(1000 + this.state.count);
    return (
    <div onClick={() => this.setState(({ count }) => ({ count: count + 1 }))}>
    <Wrapper1><Value value={1000 + this.state.count} setUpdater={updater => this.setState({updater})}/></Wrapper1>
    {" "}
    <Wrapper2><Value value={2000 + this.state.count} /></Wrapper2>
    {" "}
    <Value value={3000 + this.state.count} />
    </div>
    );
    }
    }

    ReactDOM.render(<App />, document.querySelector("main"));

    <script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
    <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>

    <main></main>








    share|improve this answer




























      1














      To rerender children without rerendering Wrapper1 you need to change their state somehow. Note that props of Value inside Wrapper1 never change. So forced renders will output the same value unless you pass it some other way. There is some bad code for example:






      class Value extends React.Component {
      state = {value: null};

      componentDidMount() {
      if (typeof(this.props.setUpdater) === 'function') this.props.setUpdater(
      value => this.setState({value})
      );
      }

      render() {
      console.log("render value ", this.state.value, this.props.value);
      return this.state.value || this.props.value;
      }
      }

      class Wrapper1 extends React.Component {
      shouldComponentUpdate() {
      return false;
      }

      render() {
      console.log("render1");
      return this.props.children;
      }
      }

      class Wrapper2 extends React.PureComponent {
      render() {
      console.log("render2");
      return this.props.children;
      }
      }

      class App extends React.Component {
      state = { count: 0 };

      render() {
      console.log("render");
      if (typeof(this.state.updater) === 'function') this.state.updater(1000 + this.state.count);
      return (
      <div onClick={() => this.setState(({ count }) => ({ count: count + 1 }))}>
      <Wrapper1><Value value={1000 + this.state.count} setUpdater={updater => this.setState({updater})}/></Wrapper1>
      {" "}
      <Wrapper2><Value value={2000 + this.state.count} /></Wrapper2>
      {" "}
      <Value value={3000 + this.state.count} />
      </div>
      );
      }
      }

      ReactDOM.render(<App />, document.querySelector("main"));

      <script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
      <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>

      <main></main>








      share|improve this answer


























        1












        1








        1







        To rerender children without rerendering Wrapper1 you need to change their state somehow. Note that props of Value inside Wrapper1 never change. So forced renders will output the same value unless you pass it some other way. There is some bad code for example:






        class Value extends React.Component {
        state = {value: null};

        componentDidMount() {
        if (typeof(this.props.setUpdater) === 'function') this.props.setUpdater(
        value => this.setState({value})
        );
        }

        render() {
        console.log("render value ", this.state.value, this.props.value);
        return this.state.value || this.props.value;
        }
        }

        class Wrapper1 extends React.Component {
        shouldComponentUpdate() {
        return false;
        }

        render() {
        console.log("render1");
        return this.props.children;
        }
        }

        class Wrapper2 extends React.PureComponent {
        render() {
        console.log("render2");
        return this.props.children;
        }
        }

        class App extends React.Component {
        state = { count: 0 };

        render() {
        console.log("render");
        if (typeof(this.state.updater) === 'function') this.state.updater(1000 + this.state.count);
        return (
        <div onClick={() => this.setState(({ count }) => ({ count: count + 1 }))}>
        <Wrapper1><Value value={1000 + this.state.count} setUpdater={updater => this.setState({updater})}/></Wrapper1>
        {" "}
        <Wrapper2><Value value={2000 + this.state.count} /></Wrapper2>
        {" "}
        <Value value={3000 + this.state.count} />
        </div>
        );
        }
        }

        ReactDOM.render(<App />, document.querySelector("main"));

        <script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
        <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>

        <main></main>








        share|improve this answer













        To rerender children without rerendering Wrapper1 you need to change their state somehow. Note that props of Value inside Wrapper1 never change. So forced renders will output the same value unless you pass it some other way. There is some bad code for example:






        class Value extends React.Component {
        state = {value: null};

        componentDidMount() {
        if (typeof(this.props.setUpdater) === 'function') this.props.setUpdater(
        value => this.setState({value})
        );
        }

        render() {
        console.log("render value ", this.state.value, this.props.value);
        return this.state.value || this.props.value;
        }
        }

        class Wrapper1 extends React.Component {
        shouldComponentUpdate() {
        return false;
        }

        render() {
        console.log("render1");
        return this.props.children;
        }
        }

        class Wrapper2 extends React.PureComponent {
        render() {
        console.log("render2");
        return this.props.children;
        }
        }

        class App extends React.Component {
        state = { count: 0 };

        render() {
        console.log("render");
        if (typeof(this.state.updater) === 'function') this.state.updater(1000 + this.state.count);
        return (
        <div onClick={() => this.setState(({ count }) => ({ count: count + 1 }))}>
        <Wrapper1><Value value={1000 + this.state.count} setUpdater={updater => this.setState({updater})}/></Wrapper1>
        {" "}
        <Wrapper2><Value value={2000 + this.state.count} /></Wrapper2>
        {" "}
        <Value value={3000 + this.state.count} />
        </div>
        );
        }
        }

        ReactDOM.render(<App />, document.querySelector("main"));

        <script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
        <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>

        <main></main>








        class Value extends React.Component {
        state = {value: null};

        componentDidMount() {
        if (typeof(this.props.setUpdater) === 'function') this.props.setUpdater(
        value => this.setState({value})
        );
        }

        render() {
        console.log("render value ", this.state.value, this.props.value);
        return this.state.value || this.props.value;
        }
        }

        class Wrapper1 extends React.Component {
        shouldComponentUpdate() {
        return false;
        }

        render() {
        console.log("render1");
        return this.props.children;
        }
        }

        class Wrapper2 extends React.PureComponent {
        render() {
        console.log("render2");
        return this.props.children;
        }
        }

        class App extends React.Component {
        state = { count: 0 };

        render() {
        console.log("render");
        if (typeof(this.state.updater) === 'function') this.state.updater(1000 + this.state.count);
        return (
        <div onClick={() => this.setState(({ count }) => ({ count: count + 1 }))}>
        <Wrapper1><Value value={1000 + this.state.count} setUpdater={updater => this.setState({updater})}/></Wrapper1>
        {" "}
        <Wrapper2><Value value={2000 + this.state.count} /></Wrapper2>
        {" "}
        <Value value={3000 + this.state.count} />
        </div>
        );
        }
        }

        ReactDOM.render(<App />, document.querySelector("main"));

        <script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
        <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>

        <main></main>





        class Value extends React.Component {
        state = {value: null};

        componentDidMount() {
        if (typeof(this.props.setUpdater) === 'function') this.props.setUpdater(
        value => this.setState({value})
        );
        }

        render() {
        console.log("render value ", this.state.value, this.props.value);
        return this.state.value || this.props.value;
        }
        }

        class Wrapper1 extends React.Component {
        shouldComponentUpdate() {
        return false;
        }

        render() {
        console.log("render1");
        return this.props.children;
        }
        }

        class Wrapper2 extends React.PureComponent {
        render() {
        console.log("render2");
        return this.props.children;
        }
        }

        class App extends React.Component {
        state = { count: 0 };

        render() {
        console.log("render");
        if (typeof(this.state.updater) === 'function') this.state.updater(1000 + this.state.count);
        return (
        <div onClick={() => this.setState(({ count }) => ({ count: count + 1 }))}>
        <Wrapper1><Value value={1000 + this.state.count} setUpdater={updater => this.setState({updater})}/></Wrapper1>
        {" "}
        <Wrapper2><Value value={2000 + this.state.count} /></Wrapper2>
        {" "}
        <Value value={3000 + this.state.count} />
        </div>
        );
        }
        }

        ReactDOM.render(<App />, document.querySelector("main"));

        <script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
        <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>

        <main></main>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 26 '18 at 14:56









        UjinT34UjinT34

        2,0641213




        2,0641213

























            0














            Try using shouldComponentUpdate






            share|improve this answer
























            • It's already in the example. How do you propose to use it?

              – Qwertiy
              Nov 26 '18 at 16:14
















            0














            Try using shouldComponentUpdate






            share|improve this answer
























            • It's already in the example. How do you propose to use it?

              – Qwertiy
              Nov 26 '18 at 16:14














            0












            0








            0







            Try using shouldComponentUpdate






            share|improve this answer













            Try using shouldComponentUpdate







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 26 '18 at 14:19









            FawziFawzi

            267110




            267110













            • It's already in the example. How do you propose to use it?

              – Qwertiy
              Nov 26 '18 at 16:14



















            • It's already in the example. How do you propose to use it?

              – Qwertiy
              Nov 26 '18 at 16:14

















            It's already in the example. How do you propose to use it?

            – Qwertiy
            Nov 26 '18 at 16:14





            It's already in the example. How do you propose to use it?

            – Qwertiy
            Nov 26 '18 at 16:14


















            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%2f53482717%2frun-render-and-reconciler-on-children-only%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