({
className = "",
section,
children,
}: SectionProps)
| 25 | }); |
| 26 | |
| 27 | export default function Section({ |
| 28 | className = "", |
| 29 | section, |
| 30 | children, |
| 31 | }: SectionProps) { |
| 32 | const [, setRef] = useDynamicRefs(); |
| 33 | const containerRef = setRef(`section-${section}`); |
| 34 | const { sectionsVisibles, setSectionsVisibles } = useContext(SectionsContext); |
| 35 | |
| 36 | const intersection = |
| 37 | containerRef && |
| 38 | useIntersection(containerRef, { |
| 39 | threshold: 0.2, |
| 40 | }); |
| 41 | |
| 42 | const isVisible = intersection?.isIntersecting; |
| 43 | |
| 44 | useEffect(() => { |
| 45 | if (isVisible && !sectionsVisibles.includes(section)) { |
| 46 | setSectionsVisibles([...sectionsVisibles, section]); |
| 47 | } else if (false === isVisible && sectionsVisibles.includes(section)) { |
| 48 | setSectionsVisibles( |
| 49 | sectionsVisibles.filter( |
| 50 | (sectionVisible: string) => sectionVisible !== section |
| 51 | ) |
| 52 | ); |
| 53 | } |
| 54 | }, [isVisible, setSectionsVisibles, sectionsVisibles, section]); |
| 55 | |
| 56 | return ( |
| 57 | <section |
| 58 | key={section} |
| 59 | className={className} |
| 60 | ref={containerRef} |
| 61 | id={section} |
| 62 | > |
| 63 | {children} |
| 64 | </section> |
| 65 | ); |
| 66 | } |
nothing calls this directly
no test coverage detected