Capítulo 51 de 116
useDebugValue(value, format?) labels a custom Hook's internal state with a readable value shown next to it in React DevTools — a debugging aid with no effect on runtime behavior, useful only inside custom Hooks used by a library or shared across a team.
useDebugValue(value, format?) — called inside a custom Hook, not a regular component. value is whatever DevTools should display; the optional format function lazily formats it, only actually invoked when DevTools is open and the Hook is inspected (avoiding cost on every render in normal operation).useDebugValue gives it a meaningful label (e.g. showing "Online" / "Offline" next to a useOnlineStatus() custom Hook instead of just its raw boolean).format function means expensive formatting logic doesn't run unless DevTools is actually inspecting that Hook.function useOnlineStatus() {
const [isOnline, setIsOnline] = useState(true);
useDebugValue(isOnline, status => status ? 'Online' : 'Offline');
// ...
return isOnline;
}
format function.(value, format) two-argument form when formatting is nontrivial, to avoid paying that cost on every render.