UNPKG

@zendesk/react-measure-timing-hooks

Version:

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

40 lines (39 loc) 969 B
/** * 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. */ /** * Helper to replace your nested 'ifs' with a single, readable expression. * Note that both the return and case are eagerly evaluated. If you wish to avoid that, use getters (2nd example). * @example * switchFn( * {case: A === B, return: 'equal'}, * {case: B > C, return: 'different'}, * {return: 'default_value'} * ); * @example * switchFn( * { * get case() { * return deepEqual(A, B); * }, * get return() { * return computationallyExpensive(A, B); * }, * }, * // ... * {return: 'default_value'} * ); * @param caseDefinitions */ export declare function switchFn<ResultT>(...caseDefinitions: [ ...cases: { case: boolean; return: ResultT; }[], defaultCase: { return: ResultT; } ]): ResultT;