Problem creating web component with solid-element
Hi, I'm trying to create an image carousel web component by wrapping an existing JS library (called Glide) within a Solid component. As a regular solid component it works fine, but when I try to convert it to a web component I get an error from the Glide saying indicating that it cannot find the root element on which to mount the image carousel. It seems the initialization which I place within the onMount hook cannot access the elements of the shadow DOM (???) The code is below. Any insights would be appreciated.
1 Reply
I solved this by using a ref (https://www.solidjs.com/tutorial/bindings_refs) instead of passing the class name to the Glide constructor. So...
new Glide('.glide', ...)
becomes new Glide(glideRef, ...)
and <div class="glide">
becomes <div ref={glideRef} class="glide">