Hi!
I’ve building a real-time multiplayer code editor with web sockets and I could use some help.
I’ve tried using a React component for CodeMirror (@uiw/react-codemirror) and the vanilla V6 itself. I can’t figure out a way to get the origin input type (i.e., “+input”, “setValue”) — are there any ways around this?
Here are my snippets:
The React Version
import CodeMirror from "@uiw/react-codemirror";
import { ViewUpdate, EditorView } from "@codemirror/view";
const CodeMirrorEditor: FC = () => {
const onChange = useCallback((value: string, viewUpdate: ViewUpdate) => {
console.log(viewUpdate);
}, []);
return (
<CodeMirror
value="console.log('hello world!');"
height="200px"
extensions={[javascript({ jsx: true })]}
onChange={onChange}
/>
)
}
The Vanilla V6
import Codemirror from "codemirror";
const CodeMirrorEditor: FC = () => {
const editor = useRef<any>();
const { setContainer } = useCodeMirror({
container: editor.current,
extensions: [javascript()],
value: 'console.log("yay")',
});
return (
<textarea ref={editor} id="realtimeEditor"></textarea>
)
}
Thank you for your time.