Comma Agents
@comma-agents/tuiHooks

useDebugRender

Flash a component's background on render — visually identify re-render causes during development.

useDebugRender wraps a component with a colored flash on every render, making it easy to identify excessive re-renders during development. Each render reason (mount, props change, state change, etc.) can have its own color.

Only active when the DEBUG_RENDER flag is set -- in production builds, the hook is a no-op.

import { useDebugRender } from "@comma-agents/tui";

function MyComponent() {
  const debug = useDebugRender("MyComponent", {
    props: { value: 42 },
  });

  return <Box ref={debug.ref}>{/* content */}</Box>;
}

DebugRenderOptions

OptionTypeDefaultDescription
propsRecord<string, unknown>--Current props values to compare across renders
colorsDebugRenderColors--Custom per-reason background colors
flashMsnumber200Flash duration in milliseconds
enabledPartial<Record<RenderReason, boolean>>--Disable specific render reasons
showBackgroundbooleantrueWhether to apply background flash colors

RenderReason

ReasonDescription
mountFirst render of this component
unmountComponent is being removed
propsProps changed between renders
stateInternal state changed
contextContext value changed
rerenderUnknown cause (fallback)

DebugRenderRef

FieldTypeDescription
refReact.RefCallback<DOMElement>Attach to the root Box of your component

The hook renders a "label bar" below the component showing the component name, render count, reason, and relevant prop changes. The component's background flashes in the color assigned to the render reason for flashMs milliseconds.

On this page