useDebugValue

what is useDebugValue ?

  • Profile picture of Mcs
  • by Mcs July 3, 2025

useDebugValue() is a React Hook used to label custom hooks in React DevTools — making it easier to debug and understand the hook's state during development.

It's mostly used inside custom hooks to help developers see useful info in React DevTools.

Syntax

useDebugValue(value);

or with formatting:

useDebugValue(value, value => `Formatted: ${value}`);

Basic Example

import { useState, useDebugValue } from 'react';

function useOnlineStatus() {
 const [isOnline, setIsOnline] = useState(true);

 useDebugValue(isOnline); // Shows "true" or "false" in DevTools

 return isOnline;
}

Example with Custom Formatting

function useFriendStatus(friendID) {
 const [isOnline, setIsOnline] = useState(null);

 useDebugValue(isOnline, online => (online ? ' Online' : ' Offline'));

 return isOnline;
}

In React DevTools, this hook will now show a friendly label like:

useFriendStatus:  Online

Notes

  1. Used only for debugging, it has no effect on app behavior.
  2. Appears only in development mode, not in production.
  3. Great for custom reusable hooks (not necessary in regular components).

Summary

FeatureDescription
useDebugValue()Adds debug label for custom hooks in DevTools
Used insideCustom hooks only
Useful forShowing state clearly in debugging tools
Shown inReact Developer Tools (Components tab)

Comments

Add new comment

Restricted HTML

  • Allowed HTML tags: <br> <p> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <cite> <dl> <dt> <dd> <a hreflang href> <blockquote cite> <ul type> <ol type start> <strong> <em> <code> <li>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.