Skip to content

@technobuddha > react-hooks > React > Hooks

Function: useWhyDidIRender()

ts
function useWhyDidIRender(name: string, props: Record<string, unknown>): void;

Defined in: use-why-did-i-render.ts:21

Logs to the console whenever the given component re-renders and its props have changed. Useful for debugging unnecessary or unexpected re-renders during development.

Parameters

ParameterTypeDescription
namestringThe name of the component (for logging).
propsRecord<string, unknown>The current props object to track for changes.

Returns

void

Example

typescript
function MyComponent(props: { value: number }) {
  useWhyDidIRender('MyComponent', props);
  return <div>{props.value}</div>;
}