import { useEffect, useRef } from "react"; import Image from "next/image"; import { Tweet } from "react-tweet"; import useTheme from "../../hooks/useTheme"; import { styled } from "../../lib/styles/stitches.config"; import type { ComponentPropsWithoutRef, ElementRef } from "react"; const Wrapper = styled("div", { minHeight: "300px", // help with layout shift "& .react-tweet-theme": { "--tweet-container-margin": "1.5rem auto", }, }); export type TweetEmbedProps = ComponentPropsWithoutRef & { className?: string; }; const TweetEmbed = ({ id, className, ...rest }: TweetEmbedProps) => { const containerRef = useRef>(null); const { activeTheme } = useTheme(); useEffect(() => { if (containerRef.current) { // setting 'data-theme' attribute of parent div changes the tweet's theme (no re-render necessary) containerRef.current.dataset.theme = activeTheme; } }, [activeTheme]); return ( , // eslint-disable-next-line jsx-a11y/alt-text MediaImg: (props) => , }} {...rest} /> ); }; export default TweetEmbed;