score:4

Accepted answer

by default react re-render all components and sub components every time setstate is called.

there is a method boolean shouldcomponentupdate(object nextprops, object nextstate), each component has this method and its responsible to determine "should component update (run render function)?" every time you change state or pass new props from parent component.

you can write your own implementation of shouldcomponentupdate method for your component, but default implementation always returns true - meaning always re-run render function.

by default, shouldcomponentupdate always returns true to prevent subtle bugs when state is mutated in place, but if you are careful to always treat state as immutable and to read only from props and state in render() then you can override shouldcomponentupdate with an implementation that compares the old props and state to their replacements. http://facebook.github.io/react/docs/component-specs.html#updating-shouldcomponentupdate

score:1

you might want to move the code out of the render() method and put it into one of the lifecycle methods in this case it would be

componentwillmount and componentwillreceiveprops. you can construct your children array there and simply disply it in the render() e.g.

render(){
  return (
      <div>{children} {this.state.something_else}</div>
  );
}

Related Query

More Query from same tag