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
4 changes: 2 additions & 2 deletions types/react/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ declare namespace React {
}

interface ForwardRefRenderFunction<T, P = {}> {
(props: PropsWithChildren<P>, ref: Ref<T>): ReactElement | null;
(props: PropsWithChildren<P>, ref: ((instance: T | null) => void) | MutableRefObject<T | null> | null): ReactElement | null;
displayName?: string;
// explicit rejected with `never` required due to
// https://github.com/microsoft/TypeScript/issues/36826
Expand All @@ -575,7 +575,7 @@ declare namespace React {
}

/**
* @deprecated Use ForwardRefRenderingFunction. forwardRef doesn't accept a
* @deprecated Use ForwardRefRenderFunction. forwardRef doesn't accept a
* "real" component.
*/
interface RefForwardingComponent <T, P = {}> extends ForwardRefRenderFunction<T, P> {}
Expand Down
11 changes: 11 additions & 0 deletions types/react/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,17 @@ function RefCarryingComponent() {
},
);
}
const ForwardingRefComponent2 = React.forwardRef<HTMLElement>((props, ref) => {
return React.createElement('div', {
ref(e: HTMLDivElement) {
if (typeof ref === 'function') {
ref(e);
} else if (ref) {
ref.current = e;
}
}
});
});

const MemoizedForwardingRefComponent = React.memo(ForwardingRefComponent);
const LazyComponent = React.lazy(() => Promise.resolve({ default: RefComponent }));
Expand Down