import React, { useEffect, useState } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; declare global { interface Window { instgrm?: { Embeds: { process: () => void; }; }; } } const posts = [ 'https://www.instagram.com/p/DSOFijljukL/', 'https://www.instagram.com/p/DSGh7rMjVes/', 'https://www.instagram.com/p/DRIIUECj4f6/', 'https://www.instagram.com/p/DJOvmvcIoo7/', 'https://www.instagram.com/p/DJOu5b7IL4t/', 'https://www.instagram.com/p/DIQnhO0oJgw/', 'https://www.instagram.com/p/DIJUVqbI4EH/', 'https://www.instagram.com/p/DHlvDNyIDRa/', 'https://www.instagram.com/p/DHlub_iojwv/', 'https://www.instagram.com/p/DJOvdVLIZpM/', ]; const InstagramFeed: React.FC = () => { const [selectedPost, setSelectedPost] = useState(null); // Double the list for seamless infinite marquee scroll const duplicatedPosts = [...posts, ...posts]; useEffect(() => { // Process Instagram embeds whenever the component mounts or the lightbox opens if (window.instgrm) { window.instgrm.Embeds.process(); } else { const script = document.createElement('script'); script.src = '//www.instagram.com/embed.js'; script.async = true; document.body.appendChild(script); } }, [selectedPost]); return ( <>
Follow Along

From the Studio

@knuth.ceramics →
{/* Infinite Carousel */}
{duplicatedPosts.map((permalink, idx) => (
{/* Invisible Overlay to capture clicks. Because iframes block events, we put a div above it. On hover it reveals a subtle mask to indicate interactivity. */}
setSelectedPost(permalink)} >

View Post

{/* The Instagram Embed itself. By omitting data-instgrm-captioned we hide the caption/hashtags directly. */}
))}
{/* Lightbox Modal */} {selectedPost && ( setSelectedPost(null)} > e.stopPropagation()} > {/* Close button inside modal container */} {/* Instagram Embed WITH caption shown in the Lightbox */}
)}
); }; export default InstagramFeed;