diff --git a/packages/desktop-client/src/components/sort.tsx b/packages/desktop-client/src/components/sort.tsx index 56d9feebd66..375b62ced9d 100644 --- a/packages/desktop-client/src/components/sort.tsx +++ b/packages/desktop-client/src/components/sort.tsx @@ -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( - ref1: RefCallback | MutableRefObject, - ref2: RefCallback | MutableRefObject, -): Ref { - 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; diff --git a/packages/desktop-client/src/hooks/useMergedRefs.js b/packages/desktop-client/src/hooks/useMergedRefs.ts similarity index 60% rename from packages/desktop-client/src/hooks/useMergedRefs.js rename to packages/desktop-client/src/hooks/useMergedRefs.ts index 2ea83b5187e..ebf6647fdf2 100644 --- a/packages/desktop-client/src/hooks/useMergedRefs.js +++ b/packages/desktop-client/src/hooks/useMergedRefs.ts @@ -1,6 +1,10 @@ import { useMemo } from 'react'; +import type { MutableRefObject, Ref, RefCallback } from 'react'; -export function useMergedRefs(ref1, ref2) { +export function useMergedRefs( + ref1: RefCallback | MutableRefObject, + ref2: RefCallback | MutableRefObject, +): Ref { return useMemo(() => { function ref(value) { [ref1, ref2].forEach(ref => { diff --git a/upcoming-release-notes/1733.md b/upcoming-release-notes/1733.md new file mode 100644 index 00000000000..89ac13a6c1f --- /dev/null +++ b/upcoming-release-notes/1733.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [MikesGlitch] +--- + +Consolidate useMergedRefs hook and convert it to TypeScript.