简体   繁体   中英

When react renders a component does it always render on the non-virtual DOM?

Let's say I have a console.log in a render method of a component:

class MyComp extends React{
    render(){
      console.log('rendering')
      return <div>Hello</div>
    }
}

Whenever this component renders I'll see it in the console. Does that always mean that the Virtual Dom is re-rendering?

Put another way, is logging the render method a good way to know if the non-virtual DOM is re-rendering?

Whenever this component renders I'll see it in the console. Does that always mean that the Virtual Dom is re-rendering?

Yes, you are right, Virtual Dom is re-rendering.

Put another way, is logging the render method a good way to know if the non-virtual DOM is re-rendering?

Putting console to render method is good and simple way to know when your component is updating.


There are 3 cases (as i know) when react component is re-rendering

  1. New props
  2. New state
  3. component.forceUpdate() method (never used it)

You can read more here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM