-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy path300-refactor-ref-react-19.mdc
More file actions
49 lines (38 loc) · 943 Bytes
/
Copy path300-refactor-ref-react-19.mdc
File metadata and controls
49 lines (38 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
---
description: PLAN to refactor React 19 Ref
globs: *.tsx
---
## Context
React 19 is out and `forwardRef` is now longer needed to use `ref` in any React components. We can now just pass `ref` props :
```tsx
const MyButton = ({ ref, ...props }: ComponentProps<"button">) => {
return <button ref={ref} {...props} />;
};
```
## Goal
You need to refactor a component **that was using `forwardRef`** to use the new `ref` props.
## Example
BEFORE :
```tsx
type SomeCustomProps = {
color: "red" | "blue";
} & ComponentPropsWithoutRef<"div">;
export const MyCustomComponent = forwardRef<HTMLDivElement, SomeCustomProps>(
({ color, ...props }, ref) => {
return <div ref={ref} {...props} />;
},
);
```
AFTER :
```tsx
type SomeCustomProps = {
color: "red" | "blue";
} & ComponentProps<"div">;
export const MyCustomComponent = ({
color,
ref,
...props
}: SomeCustomProps) => {
return <div ref={ref} {...props} />;
};
```