react-codemirror
react-codemirror copied to clipboard
useCodeMirror has an example demo? I'm not sure what he does and what scenario he's used in.
I want to get the content What to do
@qianxuanyon example: https://codesandbox.io/embed/react-codemirror-example-codemirror-6-hook-yr4vg?fontsize=14&hidenavigation=1&theme=dark
https://github.com/uiwjs/react-codemirror#support-hook
import { useEffect, useRef } from 'react';
import { useCodeMirror } from '@uiw/react-codemirror';
import { javascript } from '@codemirror/lang-javascript';
const code = "console.log('hello world!');\n\n\n";
export default function App() {
const editor = useRef();
const { setContainer } = useCodeMirror({
container: editor.current,
extensions: [javascript()],
value: code,
});
useEffect(() => {
if (editor.current) {
setContainer(editor.current);
}
}, [editor.current]);
return <div ref={editor} />;
}
I've already seen this example, and he can only get the current
and What is the difference between #314
For example, I want to get the value in the editor
I see.
// It can be taken out here
const { state,view,setContainer } = useCodeMirror({
container: editor.current,
extensions: [javascript()],
value: code,
});
What is the difference between these two settings
<CodeMirror
ref={refs}
value="console.log('hello world!');"
height="200px"
extensions={[javascript({ jsx: true })]}
/>
<div ref = {editor}></div>