Skip to content

Instantly share code, notes, and snippets.

View diegohaz's full-sized avatar

Haz diegohaz

View GitHub Profile
@diegohaz
diegohaz / use-combined-refs-new.ts
Created November 29, 2022 22:01 — forked from KurtGokhan/use-combined-refs-new.ts
useCombinedRefs - Old and new
import { ForwardedRef, useCallback } from 'react';
type OptionalRef<T> = ForwardedRef<T> | undefined;
type Cleanup = (() => void) | undefined | void;
function setRef<T>(ref: OptionalRef<T>, value: T): Cleanup {
if (typeof ref === 'function') {
const cleanup = ref(value);