This file contains hidden or 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
| export function useArrayHash<T>(array: T[], key: keyof T): string { | |
| return array.map((x) => x[key]).join(""); | |
| } |
This file contains hidden or 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 type { Dispatch } from "react"; | |
| import { useState } from "react"; | |
| export function useAutoResetState<S>( | |
| initialState: S | (() => S), | |
| ): [S, Dispatch<S>] { | |
| const [state, setState] = useState(initialState); | |
| return [ | |
| state, | |
| (temporaryState: S) => { |
This file contains hidden or 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
| export function el<K extends keyof HTMLElementTagNameMap>( | |
| nodeName: K, | |
| props?: Record<string, unknown>, | |
| children?: (string | number | boolean | Node)[], | |
| ): HTMLElementTagNameMap[K]; | |
| export function el<T extends HTMLElement>( | |
| nodeName: string, | |
| props?: Record<string, unknown>, | |
| children?: (string | number | boolean | Node)[], |
This file contains hidden or 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
| const triggerDownload = (blob: Blob, filename: string) => { | |
| const url = window.URL.createObjectURL(blob); | |
| const link = document.createElement('a'); | |
| link.download = filename; | |
| link.href = url; | |
| document.body.appendChild(link); | |
| link.dispatchEvent(new MouseEvent('click', { | |
| bubbles: true, |
This file contains hidden or 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 { createRef, ForwardedRef, forwardRef, useImperativeHandle, useRef } from 'react'; | |
| interface ForwardedHandlers<T> { | |
| getValue(): T; | |
| } | |
| interface ForwardedProps<T> { | |
| value: T; | |
| children?: never; | |
| } |
This file contains hidden or 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
| const setText = (input: HTMLInputElement, value: string): void => { | |
| const prototype = Object.getPrototypeOf(input); | |
| const valueSetter = Object.getOwnPropertyDescriptor(prototype, 'value').set; | |
| valueSetter.call(input, value); | |
| const init = { bubbles: true, cancelable: true }; | |
| input.dispatchEvent(new Event('change', init)); | |
| }; |
This file contains hidden or 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
| class ExpandedPromise<T> extends Promise<T> { | |
| resolve: (value: T | PromiseLike<T>) => void; | |
| reject: (reason?: any) => void; | |
| status: 'pending' | 'fulfilled' | 'rejected' = 'pending'; | |
| constructor() { | |
| const callbacks: { | |
| resolve?: ExpandedPromise<T>['resolve'], | |
| reject?: ExpandedPromise<T>['reject'], |
This file contains hidden or 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 { createElement, CSSProperties, FC } from 'react'; | |
| export type CSSBoxProps = CSSProperties & { className?: string }; | |
| export const CSSBox: FC<CSSBoxProps> = ({ children, className, ...style }) => { | |
| return createElement('div', { className, style }, children); | |
| }; |
This file contains hidden or 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 { useMemo, useRef } from 'react'; | |
| export type UseValuesChangeWatcherResult<T extends Record<string, unknown>> = { | |
| [K in keyof T]?: { | |
| oldValue: unknown; | |
| newValue: unknown; | |
| }; | |
| }; | |
| const compareFn = <T extends [string, unknown]>(a: T, b: T) => a[0].localeCompare(b[0]); |
This file contains hidden or 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 { useMemo, useRef } from 'react'; | |
| import { useScope } from './useScope'; | |
| export type UseThrottlerCallback = (...args: any[]) => void; | |
| export const useThrottler = <T extends UseThrottlerCallback>(callback: T, delay: number): T & { clear: () => void } => { | |
| const scope = useScope({ callback, delay }); | |
| const timeout = useRef<number>(0); | |
| return useMemo(() => { |