Problem
I am trying to use react-monaco-editor to render a json code. When I try to format the json , I was suggested the method: editor.getAction('editor.action.formatDocument').run()
. The code that I use is
const editorDidMount = (editor, monaco) => {
setTimeout(() => {
console.log(editor);
editor.getAction('editor.action.formatDocument').run()
}, 300);
};
but I get the following error: Uncaught TypeError: Cannot read property 'run' of null
Could some one please help me understand why I am missing getAction method in the editor instance.
One other thing that I noticed is that, when checking in the context-menu(right-click).. I dont see the Format Document
. Aslo the action editor.action.formatDocument
is missing in the _actions
object of the editor instance. Any help is much appreciated.