We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reading the state.doc returned from useCodeMirror always returns an empty document, even when I write something in the editor!
state.doc
useCodeMirror
The text was updated successfully, but these errors were encountered:
@Pitel Example: https://codesandbox.io/embed/react-codemirror-example-codemirror-6-hook-state-is-not-updated-193-hbj1d?fontsize=14&hidenavigation=1&theme=dark
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 { view, setContainer } = useCodeMirror({ container: editor.current, extensions: [javascript()], value: code }); useEffect(() => { if (editor.current) { setContainer(editor.current); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [editor.current]); function handle() { console.log(">>>>", view.viewState.state.doc); } return ( <div> <button type="button" onClick={() => handle()}> Button </button> <div ref={editor} /> </div> ); }
Sorry, something went wrong.
Oh, so the state is just the inital state, and current state is accessed throug view. Got it. 👍
state
view
No branches or pull requests
Reading the
state.doc
returned fromuseCodeMirror
always returns an empty document, even when I write something in the editor!The text was updated successfully, but these errors were encountered: