Use memo on Editor

This commit is contained in:
Krzysztof Wolski 2023-03-07 19:58:02 +01:00
parent 03d479f348
commit 876591a8c8

View file

@ -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}
/>
</>
);