Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new option for generic forwardRefs #710

Merged
merged 3 commits into from
Mar 27, 2024
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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,22 @@ function ClickableListInner<T>(
export const ClickableList = forwardRef(ClickableListInner);
```

##### Option 3 - Call signature

```ts
// Add to `index.d.ts`
interface ForwardRefWithGenerics extends React.FC<WithForwardRefProps<Option>> {
<T extends Option>(props: WithForwardRefProps<T>): ReturnType<
React.FC<WithForwardRefProps<T>>
>;
}

export const ClickableListWithForwardRef: ForwardRefWithGenerics =
forwardRef(ClickableList);
```

Credits: https://stackoverflow.com/a/73795494

#### More Info

- https://medium.com/@martin_hotell/react-refs-with-typescript-a32d56c4d315
Expand Down
16 changes: 16 additions & 0 deletions docs/basic/getting-started/forward-create-ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ function ClickableListInner<T>(
export const ClickableList = forwardRef(ClickableListInner);
```

### Option 3 - Call signature

```ts
// Add to `index.d.ts`
interface ForwardRefWithGenerics extends React.FC<WithForwardRefProps<Option>> {
<T extends Option>(props: WithForwardRefProps<T>): ReturnType<
React.FC<WithForwardRefProps<T>>
>;
}

export const ClickableListWithForwardRef: ForwardRefWithGenerics =
forwardRef(ClickableList);
```

Credits: https://stackoverflow.com/a/73795494

## More Info

- https://medium.com/@martin_hotell/react-refs-with-typescript-a32d56c4d315
Expand Down
Loading