I am faced with the challenge of applying an intersection observer from VueUse to multiple elements. Instead of creating separate refs for each element, which has become cumbersome due to having over 10 elements in every component, I have opted to use a directive. However, I also need to create different states because when one element intersects, the 'isVisible' state is set to true and the 'fade-in' class is applied to all elements. My goal is to apply the class only to the specific intersected element. Is there a more efficient way to create a reusable composable so that I can pass options like 'rootMargin' without needing to create a separate ref and state for each element?
<h1 :class="{ 'fade-in': isVisible }" v-intersection-observer="onIntersectionObserver"></h1>
<h2 :class="{ 'fade-in': isVisible }" v-intersection-observer="onIntersectionObserver"></h2>