You can use Ref component to get a reference to the rendered element, and then attach the event listener to the dom node
https://github.com/solidjs-community/solid-primitives/tree/main/packages/refs#ref
#is there any way to wrap a component in a click handler?
5 messages · Page 1 of 1 (latest)
I don't think so, a click handler must be attached to a dom element, you cannot use a fragment to attach an event listener since this is just a workaround to the fact that JSX doesn't support having children as an array of elements. When the JSX is compiled to HTML, the fragment is removed and no DOM element is created.
If you want your component to be clickable, why not pass a click callback and in your component have a div or any other element that has a onClick?
There's an example here: https://stackblitz.com/edit/solid-vite-unocss-bpcuue?file=index.tsx
unfortunately it doesn't seem to have an onClick 😦 It only. Looking at the signature of Refs it only has refs, added, removed and onChange
this, but just in the ref callback