How to reactively set height of a element?
The title is kinda vague so let me explain. I have a h1 tag that has 2 divs inside it.
I want to set the height of the parent h1 tag equal to height of single child div. I've kept overflow hidden so the extra div is hidden.
My component looks like this:
5 Replies
The issue is that initially when the component mounts it works as expected, but when the component unounts and comes back the resizing logic doesn't work. As you can see in the component I have a console.log, it gives the expected value on first mount but 0 on remount....
for the mount and unmount thing I'm using Switch component which tracks a signal.
a small recording to show the issue.
UPDATE:
This seems to work but can someone explain why this works? 🤔 :
instead of directly using the ref height value in
style
I update a signal in createEffect and then use it in style instead..I am also curious about this. It might have something to do with tracking since it only runs on page load. I recently had a similar issue where a resource wouldn't load when it was put in a
<Switch>
block. I had assumed that that's a tracking context but I guess not. Maybe it's similar for you with <Motion>
. I am curious what happens when you call the ref ouside of the Motion block:
the issue persists even without a motion block