useReportingObserver

A React Hook that helps to use ReportingObserver API to report errors and warnings with ease.

Demo

SourceSee log in console for reports

Usage

See API for more details.

Source

Click links below to view source on GitHub.

API

const { observerRef, isSupported, ...controls } = useReportingObserver(callback, options)

Callback

ReportingObserverCallback function that will be called when the observer is triggered.

Options

export type UseWebObserverOptions = { /** * Start the observer immediate after calling this function * * @defaultValue true */ immediate?: boolean } interface ReportingObserverOptions { buffered?: boolean types?: string[] } export interface UseReportingObserverOptions extends UseWebObserverOptions, ReportingObserverOptions {}

Returns

Retuerns contain Pausable instance that can be paused, resumed.

See Pausable for more details.

export type UseWebObserverReturns<Observer> = Pausable & { /** * ref that holds the observer instance */ observerRef: React.MutableRefObject<Observer | null> /** * Check if the observer is supported in the current environment */ isSupported: boolean } export interface UseReportingObserverReturns extends UseWebObserverReturns<ReportingObserver> {}