Skip to main content

useRenderTracker

Description and use case

useRenderTracker helps identify components that render too often and why. Pass tracked props to log changed keys and optionally trigger warnings when a render threshold is reached.

API signature

function useRenderTracker(
props?: Record<string, unknown>,
options?: UseRenderTrackerOptions
): RenderInfo

Parameters

NameTypeRequiredDescription
propsRecord<string, unknown>NoObject to diff against previous render using Object.is per key.
options.namestringNoLabel in console output. Defaults to "Component".
options.enabledbooleanNoEnable/disable tracking (dev true, prod false by default).
options.warnAtnumberNoWarn once render count reaches threshold.

Return value

FieldTypeDescription
countnumberTotal render count while tracking is enabled.
lastRenderTimenumberperformance.now() timestamp of latest render.

Live interactive demo (StackBlitz)

This demo uses an embedded StackBlitz sandbox. Load it inline or open it in a new tab.

Open demo in StackBlitz

Code example

import {useRenderTracker} from 'react-perf-hooks';

type Props = {
userId: string;
filters: Record<string, string>;
};

export function UserTable({userId, filters}: Props) {
const {count} = useRenderTracker({userId, filters}, {name: 'UserTable', warnAt: 10});

return <p>Render count: {count}</p>;
}

Companion article