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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

aeharding
Copy link
Contributor

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.

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?
@aeharding
Copy link
Contributor Author

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} />;
}

aeharding added a commit to aeharding/voyager that referenced this pull request Nov 17, 2024
Copy link
Owner

@inokawa inokawa left a 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!

@aeharding
Copy link
Contributor Author

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?

@inokawa
Copy link
Owner

inokawa commented Nov 22, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants