feat: 在代码片段编辑表单中添加状态管理,更新编辑器内容处理

This commit is contained in:
ngc2207 2024-11-12 16:10:16 +08:00
parent 0d8974b9f3
commit 415aa13a33

View File

@ -1,5 +1,6 @@
"use client";
import { useState } from "react";
import { Snippet } from "@prisma/client";
import { Editor } from "@monaco-editor/react";
@ -8,6 +9,12 @@ interface SnippetEditFormProps {
}
export default function SnippetEditForm({ snippet }: SnippetEditFormProps) {
const [code, setCode] = useState(snippet.code);
const handleEditorChange = (value: string = "") => {
setCode(value);
};
return (
<div>
<Editor
@ -16,6 +23,7 @@ export default function SnippetEditForm({ snippet }: SnippetEditFormProps) {
language="c"
defaultValue={snippet.code}
options={{ minimap: { enabled: false } }}
onChange={handleEditorChange}
/>
</div>
);