S
SolidJS•2y ago
musiclover

Accessing child element size from parent.

I'm trying to use createElementSize from primitives. Problem is, It seems it doesn't wait until child is rendered. My page goes blank with error. How to get child element's size properly?
1 Reply
ekafoo
ekafoo•2y ago
Yes ref or signals instead! 😊 const [target, setTarget] = createSignal<HTMLElement>(); const size = createElementSize(target); createEffect(() => { size.width; // => number | null size.height; // => number | null }); <div ref={setTarget} />; The parent and child div does not yet exists in your example, you try to access it before the render function is runned