What are Pure Components in React-JS ?

Forums ReactWhat are Pure Components in React-JS ?
Staff asked 2 years ago

Answers (2)

Add Answer
prinkesha lathidadiya Marked As Accepted
Staff answered 2 years ago

According to functional programming paradigms, a function is considered pure if it satisfies the following two requirements:

  • Only its input values define what it will return.
  • For the same input values, its return value is constant.

If a React component delivers the same output given the same state and props, it is said to be pure. React offers the PureComponent base class for this form of class component. Class elements that broaden React

Staff answered 2 years ago

Pure components were introduced in React 15.3 version. The React.Component and React.PureComponent differ in the shouldComponentUpdate() React lifecycle method. This method decides the re-rendering of the component by returning a boolean value (true or false). In React.Component, shouldComponentUpdate() method returns true by default. But in React.PureComponent, it compares the changes in state or props to re-render the component. The pure component enhances the simplicity of the code and the performance of the application.

Subscribe

Select Categories