Components that render with change in Reactjs


Components re-renders when the parent render. Sometimes we may not need all the components get re rendered every time. As the program expanding these render can make some performance degrade.

PureComponent is a class component features. Functional component miss this feature.

So think about component that aware of the content, of course React has such One. A component extended from class PureComponent is called pure component.

class PureComp extends PureComponent {
   render() {
       console.log('*********Pure render*********');
       return (
           <div>
              Pure Component {this.props.name}
           </div>
      )
  }
}
export default PureComp

The class also implement shouldComponentUpdate lifecycle by perform shallow comparison on props and state.

The pure component only render when props name has changed. This is like someone keep tracking the changes for you.

I am really excited about this React feature

Published by

Manoj

A developer,teacher and a blogger obsessed with Python,Dart and open source world from India

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.