Use memo on Editor
This commit is contained in:
parent
03d479f348
commit
876591a8c8
1 changed files with 10 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
||||||
import React, { useRef } from "react";
|
import React, { useCallback, useRef } from "react";
|
||||||
|
|
||||||
import Editor from "@monaco-editor/react";
|
import Editor from "@monaco-editor/react";
|
||||||
import { useTheme } from "@saleor/macaw-ui";
|
import { useTheme } from "@saleor/macaw-ui";
|
||||||
|
@ -19,6 +19,14 @@ export const CodeEditor = ({ initialTemplate, onChange, value, language }: Props
|
||||||
editorRef.current = editor;
|
editorRef.current = editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleOnChange = useCallback(
|
||||||
|
(value?: string) => {
|
||||||
|
console.log("ON CHANGE");
|
||||||
|
onChange(value ?? "");
|
||||||
|
},
|
||||||
|
[value]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Editor
|
<Editor
|
||||||
|
@ -29,9 +37,7 @@ export const CodeEditor = ({ initialTemplate, onChange, value, language }: Props
|
||||||
defaultLanguage={language}
|
defaultLanguage={language}
|
||||||
defaultValue={initialTemplate}
|
defaultValue={initialTemplate}
|
||||||
onMount={handleEditorDidMount}
|
onMount={handleEditorDidMount}
|
||||||
onChange={(value) => {
|
onChange={handleOnChange}
|
||||||
onChange(value ?? "");
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue