Sunday, 6 October 2024

React Pure components

We use the shouldComponentUpdate() Lifecycle method to customize the default behavior and implement it when the React component should re-render or update itself.

import React from "react";

export default class Test extends React.PureComponent {

    render() {

        return <h1>Welcome to GeeksforGeeks</h1>;

    }

}

Pure components automatically implement the shouldComponentUpdate() method with a shallow prop and state comparison. This method returns false if the props and state haven’t changed.

No comments:

Post a Comment