Skip to content
Discussion options

You must be logged in to vote

onClick is a bad example here because it is one of the built-in props that React will apply to native HTML elements, including custom elements. https://react.dev/reference/react-dom/components/common#common-props

Change the prop to handleClick instead and you'll see it no longer works.
Because React sets unrecognized props as attributes instead, non-string properties will break.

Here's an example showing the problematic interactions:
https://lit.dev/playground/#sample=examples%2Freact-basics&gist=57ef2beeef182272d12fddf930dd3fc9

I renamed onClick to handleClick and the button no longer toggles the state. I also made a <simple-card> custom element that takes a data object, which doesn't wo…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@pociej
Comment options

@augustjk
Comment options

@justinfagnani
Comment options

@henrijoss
Comment options

@justinfagnani
Comment options

Answer selected by pociej
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants