Skip to content

Commit

Permalink
Update useMergedRefs
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-jeremy committed Apr 2, 2024
1 parent 87bfbd5 commit c22517e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ const AmountInput = memo(function AmountInput({
const [value, setValue] = useState(0);
const inputRef = useRef<HTMLInputElement>();

// Need to update useMergedRefs to support Ref.
const mergedInputRef = useMergedRefs<HTMLInputElement>(
props.inputRef as MutableRefObject<HTMLInputElement>,
inputRef as MutableRefObject<HTMLInputElement>,
props.inputRef,
inputRef,
);

const initialValue = Math.abs(props.value);
Expand Down
8 changes: 7 additions & 1 deletion packages/desktop-client/src/hooks/useMergedRefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import { useCallback } from 'react';
import type { MutableRefObject, Ref, RefCallback } from 'react';

export function useMergedRefs<T>(
...refs: (RefCallback<T> | MutableRefObject<T> | Ref<T> | null | undefined)[]
...refs: (
| RefCallback<T | null | undefined>
| MutableRefObject<T | null | undefined>
| Ref<T | null | undefined>
| null
| undefined
)[]
): Ref<T> {
return useCallback(
(value: T) => {
Expand Down

0 comments on commit c22517e

Please sign in to comment.