reactjs - Re-rendering an app using ReactDOM.render() rather than within its container component -- anti-pattern? -


i have single object state-driven application state dispatch/subscribe logic kept separate react 'flow' (i.e. no helpers react-redux bindings).

when state changes, app re-renders.

is there difference between following 2 implementations, or anti-pattern concerns? (sorry upset i'm not using jsx)

var myelementclass = react.createclass(    render : function() {       //make use of this.props.state...    } );  var myappcontainercomponent = react.createelement(   myelementclass,   {state : datastore.getstate()} );  datastore.onchange(function(){   reactdom.render(myappcontainercomponent, somedomcontainer); }); 

vs...

var myelementclass = react.createclass(    componentdidmount : function() {       var self = this;       this.props.store.onchange(function(){          self.setstate(self.props.store.getstate());       });    },    render : function() {       //make use of this.state...    } );  var myappcontainercomponent = react.createelement(    myelementclass,    {store : datastore} );  reactdom.render(myappcontainercomponent, somedomcontainer); 

the first forces app-wide re-render 'outside', i.e. using reactdom. second same thing within container app.

i've done performance tests , don't see difference. run in issues down road? hitting reactdom.render() many times issue?

i know people comment both ways possibly expensive they're each re-rendering whole app (isn't react ;) ), that's out of scope of question.

there no big difference when have few components, when app grows large, re-rendering top going introduce slowdown. why recommend subscribing individual components store , using setstate() if the part of state care has changed. way components more performant app grows.

finally, don’t recommend use store.subscribe() directly. there whole library called react redux subscription you! when use connect() it, wraps components setstate() logic don’t have write it, , need specify parts of state components care about. also, react redux more efficient code write hand because contains many optimizations.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -