fn
usePerformanceObserver
v0.0.15testeddemoObserve 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
| Parameter | Type | Description |
|---|---|---|
callback | PerformanceObserverCallback | Invoked with the observed entries and observer |
options? | UsePerformanceObserverOptions | Observer init (`entryTypes`/`type`/`buffered`) plus `immediate` |
Returns
UsePerformanceObserverReturn`isSupported`, `isActive`, `pause`, `resume`, `stop`, and `takeRecords`