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 useGetterState<T>(value: T) { | |
const [state, setState] = React.useState<T>(value) | |
const stateRef = React.useRef<T>(state) | |
React.useEffect(() => { | |
stateRef.current = state | |
}, [state]) | |
const getter = React.useCallback(function (newValue?: React.SetStateAction<T>): T { | |
// use arguments.length because it's the only way to |
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' | |
import { SpringValue, easings, useSpring } from 'react-spring' | |
/** | |
* Hook that animates height when args.animationKey changes | |
* | |
* Ex: | |
* const animatedBlock = useAnimatedHeight({ | |
* animationKey: key, | |
* }) |
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 LinkifiedString = Array<string | JSX.Element> | string | null | undefined | |
/** | |
* Turn a string into JSX with autolinks | |
*/ | |
export function getLinkifiedString(str: string | null | undefined): LinkifiedString { | |
try { | |
// Group by whitespace (wrapping regex in parens keeps matched results in the array) | |
const substrings = str?.split(/(\s+)/g) |
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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions |
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 chains from '@wagmi/chains' | |
import type { Chain } from 'wagmi' | |
const chainValues = Object.values(chains) | |
const chainMap = new Map<number, Chain>() | |
for (const chain of chainValues) { | |
chainMap.set(chain.id, chain) | |
} |
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"; | |
function getMediaQuery(): MediaQueryList { | |
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)"); | |
return mediaQuery; | |
} | |
function subscribe(onStoreChange: () => void): () => void { | |
const mediaQuery = getMediaQuery(); | |
mediaQuery.addEventListener("change", onStoreChange); |
OlderNewer