Skip to content
Snippets Groups Projects
Unverified Commit 5f347bbe authored by Michael Clark's avatar Michael Clark Committed by GitHub
Browse files

Maintenance: Consolidate useMergedRef and convert to typescript (#1733)

parent 3c4f62bd
No related branches found
No related tags found
No related merge requests found
......@@ -3,39 +3,17 @@ import React, {
useEffect,
useRef,
useLayoutEffect,
useMemo,
useState,
useContext,
type RefCallback,
type MutableRefObject,
type Context,
type Ref,
} from 'react';
import { useDrag, useDrop } from 'react-dnd';
import { useMergedRefs } from '../hooks/useMergedRefs';
import { theme } from '../style';
import View from './common/View';
function useMergedRefs<T>(
ref1: RefCallback<T> | MutableRefObject<T>,
ref2: RefCallback<T> | MutableRefObject<T>,
): Ref<T> {
return useMemo(() => {
function ref(value) {
[ref1, ref2].forEach(ref => {
if (typeof ref === 'function') {
ref(value);
} else if (ref != null) {
ref.current = value;
}
});
}
return ref;
}, [ref1, ref2]);
}
type DragState = {
state: 'start-preview' | 'start' | 'end';
type?: string;
......
import { useMemo } from 'react';
import type { MutableRefObject, Ref, RefCallback } from 'react';
export function useMergedRefs(ref1, ref2) {
export function useMergedRefs<T>(
ref1: RefCallback<T> | MutableRefObject<T>,
ref2: RefCallback<T> | MutableRefObject<T>,
): Ref<T> {
return useMemo(() => {
function ref(value) {
[ref1, ref2].forEach(ref => {
......
---
category: Maintenance
authors: [MikesGlitch]
---
Consolidate useMergedRefs hook and convert it to TypeScript.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment