Skip to content

Instantly share code, notes, and snippets.

View MurkyMeow's full-sized avatar
🌺
Types without borders

MurkyMeow

🌺
Types without borders
  • Moscow
  • 03:58 (UTC +03:00)
View GitHub Profile
type NumberRange<N extends number, A extends number[] = []> =
A['length'] extends N ? A : NumberRange<N, [...A, A['length']]>
type Upto10 = NumberRange<10> // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
// If TS is too lazy to unwind a deep recursion (depth = 46):
type Upto46_ = NumberRange<46> // Type instantiation is excessively deep and possibly infinite
// We can reduce it's depth by specifying a bigger initial array (now depth = 36):
@MurkyMeow
MurkyMeow / Component.tsx
Last active February 20, 2024 13:52
useHover react hook
export const Component = () => {
const servicesRef = useRef<HTMLAnchorElement>(null);
const isServicesHovered = useHover(servicesRef);
return (
<Popover.Root open={isServicesHovered}>
<Popover.Trigger asChild>
<Link href="/" ref={servicesRef}>
Services
</Link>