File size: 542 Bytes
5d33320
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { useEffect } from 'react';
import { useInView } from 'framer-motion';
import { useAudio } from '../context/AudioContext';

export const useSectionAudio = (ref: React.RefObject<HTMLElement>, audioUrl: string | null) => {
    const isInView = useInView(ref, { amount: 0.5 }); // Trigger when 50% visible
    const { setSectionAudio, isMuted } = useAudio();

    useEffect(() => {
        if (isInView && !isMuted) {
            setSectionAudio(audioUrl);
        }
    }, [isInView, audioUrl, setSectionAudio, isMuted]);
};