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

[React 19] Custom element event naming issue in React 19 with TypeScript #32258

Open
wsuwt opened this issue Jan 29, 2025 · 3 comments
Open

[React 19] Custom element event naming issue in React 19 with TypeScript #32258

wsuwt opened this issue Jan 29, 2025 · 3 comments
Labels

Comments

@wsuwt
Copy link

wsuwt commented Jan 29, 2025

Summary

Hi React team,

First off, thank you for making custom elements fully compatible with React 19! It’s been a great experience writing less code while leveraging custom elements.

I came across an issue when using a custom element with events in a React TSX file (as shown in the picture below). TypeScript throws an error when the event name doesn’t contain a hyphen (-). However, based on the test cases here, it looks like event names should be valid as long as they follow the on- prefix.

Image

Would love to hear your thoughts on this—happy to provide more details if needed!

Repository: https://github.com/wsuwt/react-v19-ts-custom-element

@wsuwt wsuwt added the React 19 label Jan 29, 2025
@eps1lon
Copy link
Collaborator

eps1lon commented Jan 29, 2025

You should file this against @lit/react. This library provides the types for the props of foo-bar in your example.

@wsuwt
Copy link
Author

wsuwt commented Jan 29, 2025

Thanks @eps1lon but the library uses React types under the hood.

type ElementProps<I> = Partial<Omit<I, keyof HTMLElement>>;
export type WebComponentProps<I extends HTMLElement> = React.DetailedHTMLProps<React.HTMLAttributes<I>, I> & ElementProps<I>;

@eps1lon
Copy link
Collaborator

eps1lon commented Jan 31, 2025

Something is declaring the onfoobar-click prop but not onfoobarclick. That declaration must happen outside of @types/react

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

No branches or pull requests

2 participants