babel-plugin-react-hooks-debug-value

1.0.1 • Public • Published

babel-plugin-react-hooks-debug-value

Babel plugin to give React Hooks a label in DevTools.

With this plugin, it's clear in React DevTools which hook values correspond to which variables.

This is intended for development only.

Suppose you have this code:

const MyComp = () => {
  const [myState, setMyState] = useState(1);
  const [otherState, setOtherState] = React.useState(2);

  return <Ok />
}

You'll now see this:

after

Instead of this:

before `

since the code is transformed into this:

const useDebugValue2 = (...args) => {
  React.useDebugValue("otherState");
  return React.useState(...args);
};

const useDebugValue1 = (...args) => {
  React.useDebugValue("myState");
  return useState(...args);
};

const MyComp = () => {
  const [myState, setMyState] = useDebugValue1(1);
  const [otherState, setOtherState] = useDebugValue2(2);

  return React.createElement(Ok, null);
};

Install

npm add -D babel-plugin-react-hooks-debug-value

In your Babel config (scoping to your dev build somehow):

module.exports = {
  plugins: ['babel-plugin-react-hooks-debug-value']
}

Package Sidebar

Install

npm i babel-plugin-react-hooks-debug-value

Weekly Downloads

4

Version

1.0.1

License

none

Unpacked Size

50 kB

Total Files

5

Last publish

Collaborators

  • andersdjohnson