Path: blob/master/src/packages/frontend/components/code-editor.tsx
1503 views
/*1A lightweight react code editor component that can be2used in Next.js.34You have to have this line in nextjs's _app.tsx:56import "@uiw/react-textarea-code-editor/dist.css";78And it also has to be somewhere in the frontend code, so9this will work there.1011TODO: To make this editable I just used a quick Input component from antd,12which sucks compared to what codemirror provides. But it's only temporary.13Codemirror is harder due to compat with nextjs and we'll do that later.14*/1516import { ElementType, useEffect, useState } from "react";1718export default function CodeEditor(props) {19const [Editor, setEditor] = useState<ElementType | null>(null);2021// We lazy load the Editor because we want to support using this in nextjs.22useEffect(() => {23(async () => {24setEditor((await import("@uiw/react-textarea-code-editor")).default);25})();26}, []);2728if (Editor == null) {29return <div>Loading...</div>;30}3132return <Editor {...props} />;33}343536