-
Im playing arround and reading documentation of @lit/react and i see "While React can render Web Components, it cannot easily pass React props to custom element properties or event listeners." Im not sure what above means. Lets take a look at example :
Both
and everything works smooth. Could you please show me example of something that is not solvable without this @lit/react glue ? Im examining usability of lit as tool for building framework agnostic set of components. This sounds that its not in fact framework agnostic. Is same glue needed for lets say vue or svelte ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Change the prop to Here's an example showing the problematic interactions: I renamed With the element inspector you can see the object prop is getting set as an attribute as |
Beta Was this translation helpful? Give feedback.
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-propsChange 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
tohandleClick
and the button no longer toggles the state. I also made a<simple-card>
custom element that takes adata
object, which doesn't wo…