Skip to content

Commit

Permalink
fix: darkmode on initial load
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejonas committed Jul 3, 2019
1 parent 623fe08 commit b9982cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const App: React.FC = () => {
}, 5000);

useEffect(() => {
if (results) {
if (results && editor) {
editor.setValue(results);
setParsedSchema(results);
}
Expand Down Expand Up @@ -86,7 +86,7 @@ const App: React.FC = () => {
};
const [editor, updateDimensions] = useMonaco(
monacoEl,
undefined,
UISchema.appBar["ui:darkMode"],
_.debounce(handleMonacoEditorOnChange, 500),
[UISchema],
);
Expand Down
9 changes: 4 additions & 5 deletions src/hooks/useMonaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as monaco from "monaco-editor";

const useMonaco = (
monacoRef: React.RefObject<HTMLElement>,
didMount?: (editor: monaco.editor.IStandaloneCodeEditor) => any,
darkMode: boolean,
onChange?: (event: monaco.editor.IModelContentChangedEvent, schema: string) => any,
watchers?: any[],
) => {
Expand All @@ -16,11 +16,10 @@ const useMonaco = (
useEffect(() => {
let onChangeRef: monaco.IDisposable;
if (monacoRef && monacoRef.current) {
const e = monaco.editor.create(monacoRef.current);
const e = monaco.editor.create(monacoRef.current, {
theme: darkMode ? "vs-dark" : "vs",
});
setEditor(e);
if (didMount) {
didMount(editor);
}
onChangeRef = e.onDidChangeModelContent((event: monaco.editor.IModelContentChangedEvent) => {
if (onChange) {
const v = e.getValue();
Expand Down

0 comments on commit b9982cd

Please sign in to comment.