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 { useTheme } from "@saleor/macaw-ui";
|
||||
|
@ -19,6 +19,14 @@ export const CodeEditor = ({ initialTemplate, onChange, value, language }: Props
|
|||
editorRef.current = editor;
|
||||
}
|
||||
|
||||
const handleOnChange = useCallback(
|
||||
(value?: string) => {
|
||||
console.log("ON CHANGE");
|
||||
onChange(value ?? "");
|
||||
},
|
||||
[value]
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Editor
|
||||
|
@ -29,9 +37,7 @@ export const CodeEditor = ({ initialTemplate, onChange, value, language }: Props
|
|||
defaultLanguage={language}
|
||||
defaultValue={initialTemplate}
|
||||
onMount={handleEditorDidMount}
|
||||
onChange={(value) => {
|
||||
onChange(value ?? "");
|
||||
}}
|
||||
onChange={handleOnChange}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue