Skip to main content
useDebugValue is a React Hook that lets you add a label to a custom Hook in React DevTools.
useDebugValue only runs in development mode and has no effect in production.

Parameters

T
required
The value you want to display in React DevTools. It can be of any type.
(value: T) => mixed
Optional formatting function. When the Hook is inspected, React DevTools will call the formatting function with the value as the argument, and then display the returned formatted value.This is useful if formatting is expensive - it will only be called when the Hook is actually inspected in DevTools.

Returns

useDebugValue returns undefined.

Usage

Adding a label to a custom Hook

Call useDebugValue at the top level of your custom Hook to display a readable debug value:

Deferring formatting of a debug value

If formatting the value is expensive, pass a formatting function as the second argument:
Without a format function, React would call date.toLocaleString() on every render. With a format function, it only calls it when you inspect the Hook in DevTools.

Common Use Cases

State management hooks

Network status hooks

Complex state hooks

Media query hooks

Timer hooks

TypeScript

Generic custom hook

Best Practices

Keep it simple

Use formatting for expensive operations

Only use in custom hooks

Provide meaningful labels

Troubleshooting

I don’t see the debug value in DevTools

Make sure:
  1. You’re in development mode (doesn’t work in production)
  2. You’re using React DevTools browser extension
  3. You called useDebugValue inside a custom Hook (not a component)
  4. The component using your Hook is selected in DevTools

The formatting function runs on every render

Make sure you’re passing the formatter as a second argument:

Should I add useDebugValue to all my hooks?

No! Only add it when:
  • The Hook is part of a shared library
  • The Hook’s state is complex or not obvious
  • You’re debugging and need visibility
Don’t add it to:
  • Simple hooks that just wrap useState
  • Hooks that are only used once
  • Hooks where the value is obvious

Examples

Authentication hook

API hook

Animation hook