Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-use-debug

kolengri26MIT0.9.3TypeScript support: included

Debug hook for react

react, debug, hook, react-hook, console, rerender, rerender count

readme

react-use-debug

Debug hook for react

NPM JavaScript Style Guide Badges Badges Badges Badges Badges Badges

Install

npm install --save react-use-debug
yarn add react-use-debug

Usage

The aim of this package is to end up with annoying practice of component debugging. Hook shows component name with changed props and rerender count to console, and returns all needed info as a result

// SomeComponent.tsx
import * as React from 'react';
import { useDebug } from 'react-use-debug';

const SomeComponent: React.FC = () => {
  const [count, setCount] = React.useState(0);
  // Use info whatever you want
  const info = useDebug(SomeComponent.displayName || SomeComponent.name, {
    count,
  });

  return (
    <div>
      {count}
      <button onClick={() => setCount((s) => s + 1)}>Click!</button>
    </div>
  );
};

Browser Console

License

MIT © kolengri

Inspired by