This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// #region Necessary types | |
type NonEmptyArray<T> = [head: T, ...T[]]; | |
type Tuple<T> = [T, T]; | |
declare function head<T>(collection: [T, ...T[]]): T; | |
// #endregion | |
const cloudflareDNS: NonEmptyArray<string> = ["1.1.1.1"]; | |
const googleDNS: Tuple<string> = ["8.8.8.8", "8.8.4.4"] | |
// ✅ These Just Work™️ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type PromisifyMethods<T> = { | |
[K in keyof T]: T[K] extends AnyFunction ? (...parameters: Parameters<T[K]>) => Promise<ReturnType<T[K]>> : T[K]; | |
}; | |
type AsynchronousStorage = PromisifyMethods<Storage>; | |
export function promisify(storage: Storage): AsynchronousStorage { | |
return new Proxy(storage, { | |
get(target, name: string) { | |
if (typeof target[name] === 'function') { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FlattenSimpleInterpolation } from 'styled-components'; | |
import { pick } from './objects'; | |
type Stylesheet<K extends string> = Record<K, FlattenSimpleInterpolation>; | |
/** | |
* CSS-in-JS equivalent for `classNames`. | |
* | |
* @example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Response<T> { | |
status: 'success' | 'pending' | 'error'; | |
data: T | null; | |
} | |
/** | |
* A promise tracker that will be updated | |
* when promise resolves or rejects | |
*/ | |
const response: Response<unknown> = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
const NON_BREAKING_SPACE_CHARACTER = '\u00A0'; | |
interface Props { | |
children: string; | |
/** | |
* If the text is shorter than this, it will not be processed. | |
*/ | |
requiredLength?: number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import createPersistedState from 'use-persisted-state'; | |
import { storage } from '../utilities/storage'; | |
import { hasElements, head, isDefined } from '@rhim/utils'; | |
const usePersistedEntityId = createPersistedState('some-entity-key', storage); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bound<This extends object, Args extends any[], Return>( | |
target: (this: This, ...args: Args) => Return, | |
context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return> | |
) { | |
const methodName = String(context.name); | |
if (context.private) { | |
throw new Error(`${bound.name} cannot decorate private properties like ${methodName}.`); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { Form } from 'antd'; | |
import { ValidationState } from '@react-types/shared'; | |
type PropsAreEqual<P> = (prevProps: Readonly<P>, nextProps: Readonly<P>) => boolean; | |
/** | |
* When the wrapped component is placed inside an Ant Design form, this higher-order component | |
* will grab the validation status from the nearest form field and translate it to `ValidationState`. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
enum Tao { Yin, Yang } | |
interface Props<T> { | |
value: T; | |
onClick(value: T): void; | |
} | |
class GenericClassComponent<T> extends React.Component<Props<T>> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FetchQueryOptions, PayloadType, PrefetchableHook, useQueryClient } from 'react-query'; | |
import { useDeepCompareEffect } from 'react-use'; | |
/** | |
* Prefetches a query. Cancels any outgoing queries on unmount. | |
* | |
* @param hook Hook that returns a `UseQueryResult`. | |
* @param dependencies List of parameters required to build the key for the hook. | |
* @param options | |
* |
NewerOlder