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 throttledCode = useThrottle(code, 200); const iframeRef = useRef(null); useEffect(() => { const iframe = iframeRef.current; if (iframe && iframe.contentDocument) { iframe.contentDocument.open(); iframe.contentDocument.write(throttledCode); iframe.contentDocument.close(); } }, [throttledCode]); return (
); } export default Preview;