Understand the Component and PureComponent in React-Native

Component :
The component is a very basic element of any react-native application. As we know a large application is divided into small segments and in react we know it as a component. This helps to make development fast and maintain the code very easily. The main advantage of the component is reusability which saved a lot of development time.

There are lots of default components provided by the react it-self. You can also create your own component and use it.

PureComponents :
The pure component is also one time of component but it has some benefits over a component. The major difference between both is pure component does a shallow comparison on state change. Like when we change any value of any state present in the pure component then It first compares their values, but when comparing objects it compares only references. The re-render of the pure component will only call if the value of the state is changed and used in the pure component.

Difference : 
  • Component re-renders every time its parent rerenders, regardless of whether the component's props and state have changed that's why we knew the component as a dump component.
  • A pure component, on the other hand, will not rerender if its parent rerenders unless the pure component's props (or state) have changed that's why we knew the pure component as a smart component.

Comments