Does React re-render all components and sub components every time setState is called?

Technology CommunityCategory: ReactDoes React re-render all components and sub components every time setState is called?
VietMX Staff asked 3 years ago

By default – yes.

There is a method boolean shouldComponentUpdate(object nextProps, object nextState), each component has this method and it’s 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.