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
// 1. run Playwright with ui | |
// 2. paste this code in console | |
// 3. there is a new PIN button next to Playwright logo | |
window.PlaywrightStalker?.stop(); | |
window.PlaywrightStalker = ((d = document) => { | |
const $ = (sel) => d.querySelector(sel); | |
const $$ = (sel) => Array.from(d.querySelectorAll(sel)); | |
const delay = (ms = 1) => new Promise((r) => setTimeout(r, ms)); | |
const h = (node, props) => Object.assign(d.createElement(node), props); |
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
/** | |
* Clone value deeply, ignore custom classes, symbols and functions | |
* @param value | |
* @return cloneOfValue | |
*/ | |
export function deepClone<T>(value: T): T { | |
if (typeof value !== 'object' || !value) { | |
return value; | |
} |
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 { useState } from "react"; | |
export function useUpdate(): [number, () => void] { | |
const [state, setState] = useState(0); | |
return [state, () => setState(Date.now())]; | |
} |
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 { useMemo } from "react"; | |
import { useArrayHash } from "./useArrayHash"; | |
export function useMemoizedArray<T1, T2 = T1>( | |
array: T1[], | |
hashKey: keyof T1, | |
): [T2[], string]; | |
export function useMemoizedArray<T1, T2 = T1>( |
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
export function useArrayHash<T>(array: T[], key: keyof T): string { | |
return array.map((x) => x[key]).join(""); | |
} |
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 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 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, any>, | |
children?: (string | number | boolean | Node)[], | |
): HTMLElementTagNameMap[K]; | |
export function el<T extends HTMLElement>( | |
nodeName: string, | |
props?: Record<string, any>, | |
children?: (string | number | boolean | Node)[], |
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
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 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 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)); | |
}; |
NewerOlder