Show a concise status label
A custom Hook exposes a boolean or enum state
React 19+ · Hook
useDebugValue lets a custom Hook expose a readable label or value in React DevTools. An optional formatter controls how the value appears when the component is inspected.
Call useDebugValue inside a custom Hook to expose a value or readable label in React DevTools. React displays the value directly unless you provide a formatter; with one, DevTools invokes it when the component is inspected and displays its result.
useDebugValue(value, format?)| Name | Type | Description |
|---|---|---|
value | any | The value to display in React DevTools; it can have any type. |
format | (value: any) => any | Optional function that receives value and returns the formatted value displayed by React DevTools when the component is inspected. |
Nothing; useDebugValue does not return a value.
import { useDebugValue, useState } from 'react';
function useOnlineStatus() {
const [isOnline] = useState(true);
useDebugValue(isOnline ? 'Online' : 'Offline');
return isOnline;
}
export default function App() {
useOnlineStatus();
return <p>Inspect this component with React DevTools.</p>;
}The custom Hook exposes a readable online-status label in React DevTools while returning the underlying status to its caller.
A custom Hook exposes a boolean or enum state
A custom Hook stores complex data
Formatting is expensive or unnecessary during normal rendering
useDebugValue adds a custom Hook label or value to React DevTools. It returns nothing and is intended for making custom Hook state easier to inspect.
Follow-up: How can expensive formatting be deferred? Pass a formatter as the second argument; DevTools calls it when the component is inspected rather than requiring the formatted value on every Hook call.
The first argument is the value shown in DevTools and may have any type. If no formatter is supplied, React DevTools displays that original value.
Follow-up: What happens if the formatter returns a non-string? The returned value is still used as the formatted display value, because the documentation allows it to have any type.
Place useDebugValue at the top level of the custom Hook. A common pattern is to convert internal state into a concise status such as Online or Offline for inspection.
Follow-up: Should every custom Hook use it? No; use it when a meaningful developer-facing label improves inspection, rather than adding noise to simple Hooks.
React DevToolsCustom HooksRules of HooksuseState