use-why-did-you-render
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

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.
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

Package Sidebar

Install

npm i use-why-did-you-render

Weekly Downloads

170

Version

1.0.3

License

Apache-2.0

Unpacked Size

18.3 kB

Total Files

8

Last publish

Collaborators

  • pulkitchadha