-1

If we call the setState() function of a component in React, Browser re-render the whole DOM? or re-render only that component?

Updated

What I want to know is that whether Browser re-render(re-paint) the whole DOM(Page) when render() of only one component is called or Browser re-render only that Node.

Byeongin Yoon
  • 3,233
  • 6
  • 26
  • 44
  • 1
    Possible duplicate of [ReactJS - Does render get called any time "setState" is called?](https://stackoverflow.com/questions/24718709/reactjs-does-render-get-called-any-time-setstate-is-called) – LakshanSS Apr 28 '19 at 10:44

1 Answers1

2

That's not the case setState not only calls the render() function but after setState, the following lifecycle functions will run in order depending on what shouldComponentUpdate returns

if shouldComponentUpdate returns true(which is true by default).

  1. shouldComponentUpdate (returns Boolean true/false)
  2. componentWillUpdate (if true is returned)
  3. render() (if true is returned)
  4. componentDidUpdate (if true is returned)

It only triggers the re-render for the current component and all its children(considering no implementation of shouldComponentUpdate for any of its children), The process is called reconcilation.

Abhisar Tripathi
  • 1,569
  • 10
  • 21