I was searching the docs for the best practices for getting a ref to an element rendered by Solid. Use case: Passing an element reference to an external library.
I could probably just give it an id, create an effect, and use getElementById, but that looks like an anti-pattern in Solid.
The afterRender directive sounds like it does the job, but from the docs I cannot infer how it works, and it only exists for when and each. Is there something similar for an unconditional <div>?
Regarding getting the element reference I could simple use:
// example use of a plotting library
function Example() {
let el = <div></div>
// pass el to external library
return el;
}
but than I'm missing lifecycle handling, i.e., the external library may require to receive el only after it gets mounted. The use case is plotting libraries that can only plot into the given element after the element has become visible, because they perform internal size measurements.
I was searching the docs for the best practices for getting a ref to an element rendered by Solid. Use case: Passing an element reference to an external library.
I could probably just give it an
id, create an effect, and usegetElementById, but that looks like an anti-pattern in Solid.The
afterRenderdirective sounds like it does the job, but from the docs I cannot infer how it works, and it only exists forwhenandeach. Is there something similar for an unconditional<div>?Regarding getting the element reference I could simple use:
but than I'm missing lifecycle handling, i.e., the external library may require to receive
elonly after it gets mounted. The use case is plotting libraries that can only plot into the given element after the element has become visible, because they perform internal size measurements.