What is the right way to programatically update the code of the MonacoEditorReactComp? #1186
Unanswered
rhumbertgz
asked this question in
Q&A
Replies: 2 comments 2 replies
-
Hi @rhumbertgz . You can try updateModel on the wrapper instead to pass your updated code. This avoids recreating the react component each time; which I believe is leading to your flickering. |
Beta Was this translation helpful? Give feedback.
1 reply
-
FYI, I have a feeling like this should be put up as an issue on the monaco-components repo, as the correct people in charge of the package will be notified. Even though we make use of the package, the Langium team doesn't really work on the monaco components package. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
The
UserConfig
property of theMonacoEditorReactComp
allows us to initialise the content of the editor usingwrapperConfig
/editorAppConfig
/ code property.For example:
I would like to push an external update to the current editor code, let's consider a button that add a new
console.log('Hello')
to the editor.My first attempt was using the
useState
hook:const [content, setContent ] = useState(initialCode);
And then call the
setContent
inside of theonClickHandler
of the button, but this cause a restart of the editor getting a flickering in the UI.Then I found that I can access the current value of the editor as follow:
and I tried to update the value of the editor inside of a useEffect with
content
as dependency. In this case, I initialised thewrapperConfig
/editorAppConfig
/ code property with an empty stringeditor?.setValue(content);
That approach was worst fully crashing the editor.
In the bellow gif you can see the flickering issue using my first approach. Due to the quality of the gif only on the four addition of the
console.log
you can see the flickering of the strings.Does anyone know the right way to update the code of the editor in a programatically/manual way?
Here is the code of my demo. It is basically a modification of the
reactTs.ts
example available inmonaco-components
repositoryreactTs.ts
EditorDemo.ts
Beta Was this translation helpful? Give feedback.
All reactions