New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@welldone-software/why-did-you-render

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@welldone-software/why-did-you-render

Monkey patches React to notify you about avoidable re-renders.


Version published
Maintainers
2
Created

What is @welldone-software/why-did-you-render?

@welldone-software/why-did-you-render is a tool for debugging unnecessary re-renders in React applications. It helps developers identify and fix performance issues by logging information about why a component re-rendered.

What are @welldone-software/why-did-you-render's main functionalities?

Basic Setup

This code sets up the @welldone-software/why-did-you-render package to track all pure components in a React application. It helps in identifying unnecessary re-renders by logging detailed information.

const React = require('react');
const whyDidYouRender = require('@welldone-software/why-did-you-render');

whyDidYouRender(React, {
  trackAllPureComponents: true,
});

Tracking Specific Components

This code demonstrates how to track a specific component for unnecessary re-renders. By setting the static property `whyDidYouRender` to true, the package will log information whenever `MyComponent` re-renders.

import React from 'react';
import whyDidYouRender from '@welldone-software/why-did-you-render';

whyDidYouRender(React);

class MyComponent extends React.Component {
  static whyDidYouRender = true;
  render() {
    return <div>{this.props.text}</div>;
  }
}

Customizing Log Output

This code customizes the log output by including and excluding specific components. It also enables logging when prop values change. This helps in fine-tuning the debugging process to focus on specific parts of the application.

import React from 'react';
import whyDidYouRender from '@welldone-software/why-did-you-render';

whyDidYouRender(React, {
  logOnDifferentValues: true,
  include: [/^MyComponent$/],
  exclude: [/^SomeOtherComponent$/],
});

Other packages similar to @welldone-software/why-did-you-render

FAQs

Package last updated on 13 Aug 2019

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