UNPKG

@zendesk/react-measure-timing-hooks

Version:

react hooks for measuring time to interactive and time to render of components

23 lines (22 loc) 1.39 kB
/** * Copyright Zendesk, Inc. * * Use of this source code is governed under the Apache License, Version 2.0 * found at http://www.apache.org/licenses/LICENSE-2.0. */ import type { DependencyList } from 'react'; import type { UseTimingMeasurementHookConfiguration } from './types'; /** * @description Internal hook that handles measuring React's lifecycle. * * What happens inside of the hook can seem a bit odd and non-standard React coding. * This is explained by what we're trying to do - measure the timing of a React lifecycle. * For instance, the state is kept in refs, which normally would not be a thing you want to do. * However in this case, we want to preserve a single instance of state in the component that renders this hook, * and refs are a great way to do this. * This is designed so that this hook itself doesn't change any of it's state, * and should never itself cause any additional re-renders. * We also do not want to persist certain state across renders. * ActionLog handles the long-lifecycle of the timed interaction. */ export declare const useTimingMeasurement: <CustomMetadata extends Record<string, unknown>>({ id, reportFn, isActive, shouldResetOnDependencyChangeFn, stage, actionLog, placement, onInternalError, error, onActionAddedCallback, }: UseTimingMeasurementHookConfiguration<CustomMetadata>, restartWhenChanged: DependencyList) => void;