You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

use-why-did-you-render

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-why-did-you-render

This react hook helps to find which prop change is causing re-renders in a React component

1.0.3
latest
Source
npmnpm
Version published
Weekly downloads
238
39.18%
Maintainers
1
Weekly downloads
 
Created
Source

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:

  • First, install.
  npm install use-why-did-you-render
            OR
  yarn add use-why-did-you-render
  • Then,add the below code to your component.
useWhyDidYouRender(props, { name : "COMPONENT_NAME", printLog: true });
            OR
const { changedProps } = useWhyDidYouRender(props);
console.log(changedProps);
  • 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

PropertyDescriptionTypeDefault
nameLike Component namestringuseWhyDidYouRender
printLogIf true prints prop changesbooleanfalse

License

MIT © pulkitchdha

Keywords

react

FAQs

Package last updated on 16 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts