You decide you want to show a component on click, so you do this.
function Bar() {
return <div>This is BAR</div>
}
function Foo() {
import { FetchBaseQueryError } from '@rtk-incubator/rtk-query/dist'; | |
/** | |
* Default tags used by the cacher helpers | |
*/ | |
const defaultTags = ["UNAUTHORIZED", "UNKNOWN_ERROR"] as const; | |
type DefaultTags = typeof defaultTags[number]; | |
function concatErrorCache<T, ID>( | |
existingCache: CacheList<T, ID>, |
/** | |
* Get a union type derived from values of a const asserted array. | |
* @example | |
* const values = ['foo', 'bar'] as const; | |
* type Val = ArrayValues<typeof values>; | |
* // => 'foo' | 'bar' | |
* | |
* See https://github.com/microsoft/TypeScript/issues/28046#issuecomment-607145719 | |
*/ | |
export type ArrayValues<T extends ReadonlyArray<unknown>> = T[number]; |
type ComparisonFn = (left: number, right: number) => boolean; | |
// `buildComparison` is a 'Type Narrowing Identity Function' | |
// It returns the value given to it, but also narrows the types. | |
// In this case it allows typescript to retain the literal types of the keys | |
// rather than widening them to 'string' | |
const buildComparisons = <Comparison extends Record<string, ComparisonFn>>(comparison: Comparison) => comparison; | |
// Using the Type Narrowing Identity Function: | |
const comparisons = buildComparisons({ |
import { useRef, useCallback} from 'react'; | |
/** | |
* Accepts a given callback, and provides a new callback with a stable reference, | |
* which will itself always call the latest version of the provided callback. | |
* Useful for dealing with third party components that use stale closures. | |
* @param callback - the original callback desired to be called | |
* @returns A new callback with a stable reference, which when called, | |
* calls the latest provided callback | |
* @deprecated - This implementation may have future issues in concurrent mode, as it mutates |
export type Entries<T> = { | |
[K in keyof T]: [K, T[K]]; | |
}[keyof T][]; | |
/** | |
* Helper to use `Object.entries` while retaining key type information. | |
* Input object should be cast `as const` for maximum effectiveness. | |
*/ | |
export function objEntries<T extends Record<string, unknown>>(obj: T): Entries<T> { | |
return Object.entries(obj) as Entries<T>; |