Skip to content

This hook helps to identify the changes in react component that made it to re-render and returns an object with the changes.

License

Notifications You must be signed in to change notification settings

Pulkitchadha/use-why-did-you-render

Repository files navigation

useWhyDidYouRender

This react hook helps to find which prop change is causing re-renders in a React component, making it easier to fix rendering issues in the React component.

How to use it:

  1. First, install.
  npm install use-why-did-you-render
            OR
  yarn add use-why-did-you-render
  1. Then,add the below code to your component.
import { useWhyDidYouRender } from "use-why-did-you-render";

useWhyDidYouRender(props, { name : "COMPONENT_NAME", printLog: true });
            OR
const { changedProps } = useWhyDidYouRender(props);
console.log(changedProps);
  1. When component re-renders, it will print it on console.
COMPONENT_NAME => {
    PROP_NAME: {
        from: oldValue,
        to: newValue,
    },
    PROP_NAME_2: {
        from: oldValue,
        to: newValue,
    },
}

Options

Property Description Type Default
name Like Component name string useWhyDidYouRender
printLog If true prints prop changes boolean false

License

MIT © pulkitchdha

About

This hook helps to identify the changes in react component that made it to re-render and returns an object with the changes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published