import { useEffect, useRef } from "react"; import classNames from "classnames"; import useThrottle from "../hooks/useThrottle"; interface Props { code: string; device: "mobile" | "desktop"; } function Preview({ code, device }: Props) { const iframeRef = useRef(null); // Don't update code more often than every 200ms. const throttledCode = useThrottle(code, 200); useEffect(() => { if (iframeRef.current) { iframeRef.current.srcdoc = throttledCode; } }, [throttledCode]); return (
); } export default Preview;