WH

Why Did You Render

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

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

Forms
react
component
pure
performance
render
update
tool
@welldone-software/why-did-you-render
Forms
javascript
Stars
13k
Weekly
830k
Open issues
45
Bundle
~25 kB

Installation

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

Code example

import { useWhyDidYouRender } from "@welldone-software/why-did-you-render";

export function Example() {
  const form = useWhyDidYouRender({ defaultValues: { email: "" } });

  function onSubmit(event: React.FormEvent<HTMLFormElement>) {
    event.preventDefault();
    console.log(form);
  }

  return (
    <form onSubmit={onSubmit}>
      <input name="email" type="email" placeholder="you@example.com" />
      <button type="submit">Submit</button>
    </form>
  );
}

Pros & cons

Pros

  • Actively maintained by danikenan
  • 830k weekly downloads. Battle tested
  • First-class TypeScript definitions
  • MIT licensed

Considerations

  • Adds roughly ~25 kB to your bundle
  • Needs client-only rendering in SSR frameworks
  • Not supported in React Native
  • 45 open issues on GitHub

FAQs

Alternatives & similar libraries