import { useStore } from '@nanostores/react'; import { memo, useEffect, useRef, useState } from 'react'; import { workbenchStore } from '../../lib/stores/workbench'; import { IconButton } from '../ui/IconButton'; export const Preview = memo(() => { const iframeRef = useRef(null); const [activePreviewIndex] = useState(0); const previews = useStore(workbenchStore.previews); const activePreview = previews[activePreviewIndex]; const [url, setUrl] = useState(''); const [iframeUrl, setIframeUrl] = useState(); useEffect(() => { if (activePreview && !iframeUrl) { const { baseUrl } = activePreview; setUrl(baseUrl); setIframeUrl(baseUrl); } }, [activePreview, iframeUrl]); const reloadPreview = () => { if (iframeRef.current) { iframeRef.current.src = iframeRef.current.src; } }; return (
Preview
{ setUrl(event.target.value); }} />
{activePreview ? ( ) : (
No preview available
)}
); });