I would just import the plugin into the hook like you're doing. It doesn't hurt anything to import a plugin multiple times. I would also rename the hook to useOpacityManager so React knows it's a hook.
I would use refs instead of class names as well:
import { useEffect, useRef } from "react";
import { gsap } from "gsap/dist/gsap";
import { ScrollTrigger } from "gsap/dist/ScrollTrigger";
gsap.registerPlugin(ScrollTrigger);
export default function useOpacityManager() {
const trigger = useRef();
const content = useRef();
useEffect(() => {
gsap.to(
content.current,
5,
{
scrollTrigger: {
trigger: trigger.current,
start: "top center",
end: "bottom center",
scrub: true,
markers: true,
},
yoyo: true,
repeat: 1,
opacity: 1,
y: 0,
},
0
);
return () => {
ScrollTrigger.kill();
};
}, []);
return [trigger, content];
}
and then in the component:
const [triggerRef, contentRef] = useOpacityManager();
<TriggerComponent ref={triggerRef} />
<ContentComponent ref={contentRef} />
Hopefully that makes sense.