Skip to content

Commit 69bdc03

Browse files
author
Andrew Jiang
committed
chore: use composeRef instead of useImpertativeHandle
1 parent 7bea0ff commit 69bdc03

File tree

14 files changed

+45
-74
lines changed

14 files changed

+45
-74
lines changed

packages/fern-docs/components/src/FernInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const FernInput = forwardRef<HTMLInputElement, FernInputProps>(
5959
<div className={cn("fern-input-group", className)}>
6060
{leftIcon && <span className="fern-input-icon">{leftIcon}</span>}
6161
<input
62-
ref={composeRefs(forwardedRef, inputRef)}
62+
ref={composeRefs(inputRef, forwardedRef)}
6363
{...props}
6464
className={cn("fern-input", inputClassName)}
6565
onChange={composeEventHandlers(

packages/fern-docs/components/src/FernNumericInput.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useEventCallback } from "@fern-ui/react-commons";
2+
import { composeRefs } from "@radix-ui/react-compose-refs";
23
import cn from "clsx";
34
import { Minus, Plus } from "iconoir-react";
45
import {
@@ -7,7 +8,6 @@ import {
78
forwardRef,
89
useCallback,
910
useEffect,
10-
useImperativeHandle,
1111
useRef,
1212
useState,
1313
} from "react";
@@ -35,11 +35,9 @@ export const FernNumericInput = forwardRef<
3535
disallowFloat,
3636
...props
3737
},
38-
ref
38+
forwardedRef
3939
) {
4040
const inputRef = useRef<HTMLInputElement>(null);
41-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
42-
useImperativeHandle(ref, () => inputRef.current!);
4341

4442
const [internalValue, setInternalValue] = useState<number>();
4543
const timeout = useRef<ReturnType<typeof setTimeout> | null>(null);
@@ -127,7 +125,7 @@ export const FernNumericInput = forwardRef<
127125
/>
128126
)}
129127
<input
130-
ref={inputRef}
128+
ref={composeRefs(inputRef, forwardedRef)}
131129
type="number"
132130
className={cn("fern-input", inputClassName)}
133131
value={internalValue ?? value}

packages/fern-docs/components/src/FernTextarea.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1+
import { composeRefs } from "@radix-ui/react-compose-refs";
12
import cn from "clsx";
2-
import {
3-
ComponentProps,
4-
forwardRef,
5-
useEffect,
6-
useImperativeHandle,
7-
useRef,
8-
} from "react";
3+
import { ComponentProps, forwardRef, useEffect, useRef } from "react";
94

105
interface FernTextareaProps extends ComponentProps<"textarea"> {
116
onValueChange?: (value: string) => void;
@@ -15,12 +10,10 @@ interface FernTextareaProps extends ComponentProps<"textarea"> {
1510
export const FernTextarea = forwardRef<HTMLTextAreaElement, FernTextareaProps>(
1611
function FernTextarea(
1712
{ className, onValueChange, minLines = 2, ...props },
18-
ref
13+
forwardedRef
1914
) {
2015
const inputRef = useRef<HTMLTextAreaElement>(null);
2116

22-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
23-
useImperativeHandle(ref, () => inputRef.current!);
2417
const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
2518
onValueChange?.(e.target.value);
2619
props.onChange?.(e);
@@ -30,7 +23,7 @@ export const FernTextarea = forwardRef<HTMLTextAreaElement, FernTextareaProps>(
3023
<div className={cn("fern-textarea-group", className)}>
3124
<textarea
3225
{...props}
33-
ref={inputRef}
26+
ref={composeRefs(inputRef, forwardedRef)}
3427
className="fern-textarea"
3528
onChange={handleChange}
3629
/>

packages/fern-docs/search-ui/src/components/desktop/desktop-ask-ai.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export const DesktopCommandWithAskAI = forwardRef<
156156
<DesktopCommandRoot
157157
label={askAI ? "Ask AI" : "Search"}
158158
{...props}
159-
ref={composeRefs(forwardedRef, ref)}
159+
ref={composeRefs(ref, forwardedRef)}
160160
shouldFilter={!askAI}
161161
disableAutoSelection={askAI}
162162
onPopState={
@@ -487,7 +487,7 @@ const AskAIComposer = forwardRef<
487487
>
488488
<DesktopCommandInput asChild>
489489
<TextArea
490-
ref={composeRefs(forwardedRef, inputRef)}
490+
ref={composeRefs(inputRef, forwardedRef)}
491491
autoFocus
492492
placeholder="Ask AI a question..."
493493
minLines={1}

packages/fern-docs/search-ui/src/components/desktop/desktop-command-root.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const DesktopCommandRoot = forwardRef<
5252
>
5353
<Command.Root
5454
label="Search"
55-
ref={composeRefs(forwardedRef, ref)}
55+
ref={composeRefs(ref, forwardedRef)}
5656
{...props}
5757
id="fern-search-desktop-command"
5858
onKeyDown={composeEventHandlers(

packages/fern-docs/search-ui/src/components/desktop/desktop-command.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const DesktopCommand = forwardRef<
6565
<DesktopCommandRoot
6666
label="Search"
6767
{...props}
68-
ref={composeRefs(forwardedRef, ref)}
68+
ref={composeRefs(ref, forwardedRef)}
6969
onPopState={composeEventHandlers(onPopState, handlePopFilters, {
7070
checkForDefaultPrevented: false,
7171
})}

packages/fern-docs/search-ui/src/components/shared/command-link.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const CommandLink = forwardRef<
7171
return (
7272
<Command.Item {...props} value={href} asChild>
7373
<Comp
74-
ref={composeRefs(forwardedRef, ref)}
74+
ref={composeRefs(ref, forwardedRef)}
7575
href={href}
7676
target={target}
7777
rel={rel}

packages/fern-docs/ui/src/api-reference/endpoints/EndpointUrl.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import visitDiscriminatedUnion from "@fern-api/ui-core-utils/visitDiscriminatedU
44
import { CopyToClipboardButton } from "@fern-docs/components";
55
import { HttpMethodBadge } from "@fern-docs/components/badges";
66
import { useBooleanState } from "@fern-ui/react-commons";
7+
import { composeRefs } from "@radix-ui/react-compose-refs";
78
import cn from "clsx";
89
import React, {
910
PropsWithChildren,
1011
ReactElement,
11-
useImperativeHandle,
1212
useMemo,
1313
useRef,
1414
useState,
@@ -44,13 +44,10 @@ export const EndpointUrl = React.forwardRef<
4444
showEnvironment,
4545
options,
4646
},
47-
parentRef
47+
forwardedRef
4848
) {
4949
const ref = useRef<HTMLDivElement>(null);
5050

51-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
52-
useImperativeHandle(parentRef, () => ref.current!);
53-
5451
const [isHovered, setIsHovered] = useState(false);
5552
const isEditingEnvironment = useBooleanState(false);
5653

@@ -110,7 +107,10 @@ export const EndpointUrl = React.forwardRef<
110107
}, [options, environmentId, baseUrl]);
111108

112109
return (
113-
<div ref={ref} className={cn("flex items-center gap-1 pr-2", className)}>
110+
<div
111+
ref={composeRefs(ref, forwardedRef)}
112+
className={cn("flex items-center gap-1 pr-2", className)}
113+
>
114114
<HttpMethodBadge method={method} />
115115

116116
<div className={cn("flex items-center")}>

packages/fern-docs/ui/src/components/HorizontalOverflowMask.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1+
import { composeRefs } from "@radix-ui/react-compose-refs";
12
import cn from "clsx";
23
import fastdom from "fastdom";
3-
import React, {
4-
PropsWithChildren,
5-
useEffect,
6-
useImperativeHandle,
7-
useRef,
8-
useState,
9-
} from "react";
4+
import React, { PropsWithChildren, useEffect, useRef, useState } from "react";
105
import { noop } from "ts-essentials";
116

127
export const HorizontalOverflowMask = React.forwardRef<
138
HTMLDivElement,
149
PropsWithChildren<{ className?: string }>
15-
>(function HorizontalOverflowMask({ children, className }, parentRef) {
10+
>(function HorizontalOverflowMask({ children, className }, forwardedRef) {
1611
const ref = useRef<HTMLDivElement>(null);
17-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
18-
useImperativeHandle(parentRef, () => ref.current!);
1912

2013
const [showLeftMask, setShowLeftMask] = useState(false);
2114
const [hideRightMask, setHideRightMask] = useState(false);
@@ -55,7 +48,7 @@ export const HorizontalOverflowMask = React.forwardRef<
5548

5649
return (
5750
<div
58-
ref={ref}
51+
ref={composeRefs(ref, forwardedRef)}
5952
className={cn(
6053
"fern-x-overflow",
6154
{

packages/fern-docs/ui/src/header/Announcement.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { FernButton } from "@fern-docs/components";
22
import { useResizeObserver } from "@fern-ui/react-commons";
3+
import { composeRefs } from "@radix-ui/react-compose-refs";
34
import clsx from "clsx";
45
import { AnimatePresence, motion } from "framer-motion";
56
import { Xmark } from "iconoir-react";
67
import { useAtom, useAtomValue, useSetAtom } from "jotai";
7-
import { ReactElement, forwardRef, useImperativeHandle, useRef } from "react";
8+
import { ReactElement, forwardRef, useRef } from "react";
89
import {
910
ANNOUNCEMENT_CONFIG_ATOM,
1011
ANNOUNCEMENT_DISMISSED_ATOM,
@@ -32,12 +33,9 @@ const AnnouncementInternal = forwardRef<
3233
}
3334
});
3435

35-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
36-
useImperativeHandle(forwardedRef, () => ref.current!);
37-
3836
return (
3937
<motion.div
40-
ref={ref}
38+
ref={composeRefs(ref, forwardedRef)}
4139
{...props}
4240
className={clsx("overflow-hidden", className)}
4341
>

0 commit comments

Comments
 (0)