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

Support React 19 ref as prop #550

Merged
merged 4 commits into from
Dec 6, 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
6 changes: 2 additions & 4 deletions src/react/VList.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ it("should pass attributes to element", () => {

it("should pass index to items", () => {
const Item = forwardRef<HTMLDivElement, CustomItemComponentProps>(
({ children, index, style }, ref) => {
({ index, ...rest }, ref) => {
return (
<div ref={ref} style={style} data-index={index}>
{children}
</div>
<div ref={ref} data-index={index} {...rest} />
);
}
);
Expand Down
6 changes: 2 additions & 4 deletions src/react/WindowVirtualizer.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ afterEach(cleanup);

it("should pass index to items", () => {
const Item = forwardRef<HTMLDivElement, CustomItemComponentProps>(
({ children, index, style }, ref) => {
({ index, ...rest }, ref) => {
return (
<div ref={ref} style={style} data-index={index}>
{children}
</div>
<div ref={ref} data-index={index} {...rest} />
);
}
);
Expand Down
20 changes: 12 additions & 8 deletions src/react/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CSSProperties, ReactNode } from "react";
import { ComponentType, CSSProperties, LegacyRef, ReactNode } from "react";

export type ViewportComponentAttributes = Pick<
React.HTMLAttributes<HTMLElement>,
Expand All @@ -9,12 +9,14 @@ export type ViewportComponentAttributes = Pick<
export interface CustomContainerComponentProps {
style: CSSProperties;
children: ReactNode;
/**
* only available after React 19
*/
ref?: LegacyRef<any>;
}

export type CustomContainerComponent = React.ForwardRefExoticComponent<
React.PropsWithoutRef<CustomContainerComponentProps> &
React.RefAttributes<any>
>;
export type CustomContainerComponent =
ComponentType<CustomContainerComponentProps>;

/**
* Props of customized item component for {@link Virtualizer} or {@link WindowVirtualizer}.
Expand All @@ -23,8 +25,10 @@ export interface CustomItemComponentProps {
style: CSSProperties;
index: number;
children: ReactNode;
/**
* only available after React 19
*/
ref?: LegacyRef<any>;
}

export type CustomItemComponent = React.ForwardRefExoticComponent<
React.PropsWithoutRef<CustomItemComponentProps> & React.RefAttributes<any>
>;
export type CustomItemComponent = ComponentType<CustomItemComponentProps>;
Loading