react-use-debug
TypeScript icon, indicating that this package has built-in type declarations

0.9.3 • Public • Published

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

Package Sidebar

Install

npm i react-use-debug

Weekly Downloads

4

Version

0.9.3

License

MIT

Unpacked Size

23.6 kB

Total Files

19

Last publish

Collaborators

  • kolengri