R
fn

usePerformanceObserver

v0.0.15testeddemo

Observe performance metrics via `PerformanceObserver`. The observer is (re)created only when activation changes, and can be paused, resumed, or permanently stopped. SSR-safe: nothing runs until mounted in a supporting environment.

Examples

ts
usePerformanceObserver((list) => {
  console.log(list.getEntries());
}, { entryTypes: ['paint', 'measure'] });
ts
const { pause, resume } = usePerformanceObserver(onEntries, {
  entryTypes: ['longtask'],
  buffered: true,
});

Demo

Loading demo…

Signature

ts
export function usePerformanceObserver(
  callback: PerformanceObserverCallback,
  options: UsePerformanceObserverOptions ={ ... }

Parameters

ParameterTypeDescription
callbackPerformanceObserverCallbackInvoked with the observed entries and observer
options?UsePerformanceObserverOptionsObserver init (`entryTypes`/`type`/`buffered`) plus `immediate`

Returns

UsePerformanceObserverReturn`isSupported`, `isActive`, `pause`, `resume`, `stop`, and `takeRecords`