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

Update forward-create-ref.md #776

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 6 additions & 4 deletions docs/basic/getting-started/forward-create-ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CssThemeProvider extends PureComponent<Props> {
`forwardRef`:

```tsx
import { forwardRef, ReactNode } from "react";
import { type ReactNode, forwardRef } from "react";

interface Props {
children?: ReactNode;
Expand All @@ -42,7 +42,7 @@ export const FancyButton = forwardRef<Ref, Props>((props, ref) => (
This was done [on purpose](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/43265/). You can make it immutable if you have to - assign `React.Ref` if you want to ensure nobody reassigns it:

```tsx
import { forwardRef, ReactNode, Ref } from "react";
import { type ReactNode, forwardRef, Ref } from "react";

interface Props {
children?: ReactNode;
Expand Down Expand Up @@ -133,9 +133,11 @@ export const ClickableList = forwardRef(ClickableListInner);

```ts
// Add to `index.d.ts`
interface ForwardRefWithGenerics extends React.FC<WithForwardRefProps<Option>> {
import type {FC} from 'react'; // its better to import types like this

interface ForwardRefWithGenerics extends FC<WithForwardRefProps<Option>> {
<T extends Option>(props: WithForwardRefProps<T>): ReturnType<
React.FC<WithForwardRefProps<T>>
FC<WithForwardRefProps<T>>
>;
}

Expand Down
Loading