-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Conversation
This is a stab at supporting forwardRef and ref-as-prop (react 19). By defaulting to CustomItemComponentProps ref type to div, this *shouldn't* have breaking changes for most users. Note: I also abstracted the types to encourage users to spread onto the custom element. This may be helpful for changes passing other attributes in the future?
btw, here is a sneak preview of how clean custom virtua item is, with React 19! import { CustomItemComponentProps } from "virtua";
/**
* Add data-index to each item for programmatic scrolling
*/
export function IndexedVirtuaItem({
index,
...rest
}: CustomItemComponentProps) {
return <div data-index={index} {...rest} />;
} |
pending on inokawa/virtua#550
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
This change looks good but it seems that React 19 type has more breaking changes than forwardRef (ex. argument of useRef), and not sure it's stable. So I'd like to release breaking changes to support React 19 at once after 19.0.0 is released. Thanks!
No problem. FWIW, I am using virtua on my project with React 19 and it works great (except for this typing issue)! Would you like me to close this for now or leave it open? |
Yeah, it's ok to leave it as is. I might change my mind and merge. I'm glad to hear virtua worked on React 19! |
src/react/types.ts
Outdated
export type CustomItemComponent = React.ForwardRefExoticComponent< | ||
React.PropsWithoutRef<CustomItemComponentProps> & React.RefAttributes<any> | ||
>; | ||
export type CustomItemComponent<R extends React.ElementType = 'div'> = React.FunctionComponent<CustomItemComponentProps<R>>; |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
e26ecfb
to
12af5e5
Compare
Finally React 19 was released. I revisited here and I've published @types/react@19 support in |
This is a stab at supporting forwardRef and ref-as-prop (react 19).
By defaulting to CustomItemComponentProps ref type to div, this shouldn't have breaking changes for most users.
Note: I also abstracted the types to encourage users to spread onto the custom element. This may be helpful for changes passing other attributes in the future?
If this isn't the approach you want to take, I fully understand (IhavenoideawhatIamdoing), this is mostly to get the conversation started.