Open metehansenol opened 1 month ago
I don't think Monaco should be used as a "controlled input"; I don't think it's designed to be used that way. Instead, you can use onLoad
to store a reference to the editor itself in your component's state, and then call getValue()
to get the current value whenever you need it:
const [editor, setEditor] = useState();
// example of getting the current value from the editor
const onClick = () => alert(editor?.getValue());
<MonacoEditorReactComp
userConfig={{
wrapperConfig: {
editorAppConfig: {
...
},
},
}}
onLoad={(wrapper) => setEditor(wrapper.getEditor())}
/>
Any idea how to store editor text in app state? Because when state changed
onTextChanged
event is being triggered twice because of having code also inuserConfig
and lost cursor position in editor. Examples and readme doesn't show usage with react state.