IntersectionObserver
Hi, do you have any idea how to do this better? solidjs doesn't seem to like me coding like this.
20 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
This seems unnecessary. Why not just break this out of the JSX
https://primitives.solidjs.community/package/intersection-observer might be of interest
this is what I use
because I need $scroll_container to exist
inside the
entries => ...
callback?would the use:intersectionObserver work if I did this?
I don't think
$scroll_container
will exist inside the {() => {...}}
child; pretty sure the child gets evaluated before the ref
gets assignedIt seems to work though, it activates on scroll, surprisingly.
Glad it works! If there's something surprising, we can try to explain why it works
Yes, that's why I feel like I'm using a hack but I don't see how to do it properly with the solidjs intersection-observer package.
Did you try:
scroll_container does not exist, so it does not work.
what do you mean it doesn't exist?
I added the needed
let $scroll_container
at the top$scroll_container is defined that after the construction of the makeIntersectionObserver it does not exist.
oh, I see
I don't think you need
root: $scroll_container
that's what use:intersectionObserver
doesif I don't use root it activates on the global scroll, and the global scroll doesn't move.
sorry, I think I'm mistaken - yeah
ok, I don't see a nicer way to write the code than what you did 🙂
Maybe worth asking in #solid-primitives ...
Good question I will ask that.
It seems like there's a chicken-and-egg scenario where you need the root to give to
makeIntersectionObserver
, and you need makeIntersectionObserver
to use the directive on the children.yes exactly