Skip to main content
useDebugValue displays a custom label for custom hooks in the Preact DevTools panel. This helps with debugging by providing meaningful information about custom hook state.

Signature

Parameters

T
required
The value to display in the devtools. This can be any type: string, number, object, etc.
(value: T) => any
An optional function to format the value before displaying it in devtools. This is useful for expensive formatting operations that should only run when the devtools are open and inspecting the component.

Returns

void

Basic Usage

With Formatter

Custom Hook Debugging

Async State Debugging

Complex State Debugging

Timer Debugging

API State Machine

Without Formatter

useDebugValue only affects the display in Preact DevTools. It has no effect on production code behavior and minimal performance impact when devtools are closed.
Use the optional formatter parameter for expensive formatting operations. The formatter function will only be called when devtools are open and inspecting the component, avoiding unnecessary computation.
useDebugValue is most useful in custom hooks that are used in multiple places. For component-local state, the regular devtools inspection is usually sufficient.