Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,21 @@ export const FancyButton = forwardRef(

If you are grabbing the props of a component that forwards refs, use [`ComponentPropsWithRef`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/a05cc538a42243c632f054e42eab483ebf1560ab/types/react/index.d.ts#L770).

`ref` as a prop:

React 19, you can access ref as prop for function components.

```tsx
function MyInput({ placeholder, ref }) {
return <input placeholder={placeholder} ref={ref} />;
}

// In parent
<MyInput ref={ref} />;
```

Read more [`ref` as a prop](https://react.dev/blog/2024/12/05/react-19#ref-as-a-prop).

#### Generic forwardRefs

Read more context in https://fettblog.eu/typescript-react-generic-forward-refs/:
Expand Down
15 changes: 15 additions & 0 deletions docs/basic/getting-started/forward-create-ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ export const FancyButton = forwardRef(

If you are grabbing the props of a component that forwards refs, use [`ComponentPropsWithRef`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/a05cc538a42243c632f054e42eab483ebf1560ab/types/react/index.d.ts#L770).

`ref` as a prop:

React 19, you can access ref as prop for function components.

```tsx
function MyInput({ placeholder, ref }) {
return <input placeholder={placeholder} ref={ref} />;
}

// In parent
<MyInput ref={ref} />;
```

Read more [`ref` as a prop](https://react.dev/blog/2024/12/05/react-19#ref-as-a-prop).

## Generic forwardRefs

Read more context in https://fettblog.eu/typescript-react-generic-forward-refs/:
Expand Down