Closed vdemcak closed 1 year ago
import React, { useState } from "react";
import CodeMirror from "@uiw/react-codemirror";
import { json } from "@codemirror/lang-json";
export default function App() {
const [value, setValue] = useState("{\n a:123\n}");
const onChange = React.useCallback((value, viewUpdate) => {
setValue(value);
}, []);
return (
<div>
<CodeMirror
value={value}
height="200px"
theme="dark"
extensions={[json()]}
onChange={onChange}
/>
<pre>{value}</pre>
</div>
);
}
Hello, I am currently facing several issues with my React component that incorporates a JSON editor. The problems I am encountering include:
After doing some troubleshooting, I've found that the issue lies in the component being controlled. My question is, should I only pass its value initially?
Thanks.
Here is the code:
And here is the sample usage: