"use client"; import Editor from "@monaco-editor/react"; import { useEffect, useRef, useState } from "react"; interface ResultViewerProps { language: "typescript" | "javascript" | "json"; value: string; } /** * Read-only Monaco pane used to render the compiled / transformed output with a * copy button. Wraps `` and adds the toast UI. */ export function ResultViewer({ language, value }: ResultViewerProps) { const [copied, setCopied] = useState(false); const copiedTimer = useRef(null); useEffect( () => () => { if (copiedTimer.current !== null) window.clearTimeout(copiedTimer.current); }, [], ); const onCopy = () => { void navigator.clipboard.writeText(value); setCopied(true); if (copiedTimer.current !== null) window.clearTimeout(copiedTimer.current); copiedTimer.current = window.setTimeout(() => { setCopied(false); copiedTimer.current = null; }, 1500); }; return (
{value && ( )}
); }