Skip to content

Instantly share code, notes, and snippets.

@amazzalel-habib
Created April 14, 2019 12:51
Show Gist options
  • Save amazzalel-habib/bc332452b579b6cae6c2234594713b8d to your computer and use it in GitHub Desktop.
Save amazzalel-habib/bc332452b579b6cae6c2234594713b8d to your computer and use it in GitHub Desktop.
import * as React from 'react';
import * as monaco from 'monaco-editor-core';
interface IEditorPorps {
language: string;
}
const Editor: React.FC<IEditorPorps> = (props: IEditorPorps) => {
let divNode;
const assignRef = React.useCallback((node) => {
// On mount get the ref of the div and assign it the divNode
divNode = node;
}, []);
React.useEffect(() => {
if (divNode) {
const editor = monaco.editor.create(divNode, {
language: props.language,
minimap: { enabled: false },
autoIndent: true
});
}
}, [assignRef])
return <div ref={assignRef} style={{ height: '90vh' }}></div>;
}
export { Editor };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment