From 8b2c89309079bb1b402b58bead752a9ecd73011c Mon Sep 17 00:00:00 2001 From: Endre Vegh Date: Fri, 16 Aug 2024 15:31:51 +0200 Subject: [PATCH] fix: move onchange inside event handler --- .../src/components/Editor/index.tsx | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/react-live/src/components/Editor/index.tsx b/packages/react-live/src/components/Editor/index.tsx index fb028af..6553d54 100644 --- a/packages/react-live/src/components/Editor/index.tsx +++ b/packages/react-live/src/components/Editor/index.tsx @@ -24,16 +24,21 @@ const CodeEditor = (props: Props) => { setCode(props.code); }, [props.code]); - useEditable(editorRef, (text) => setCode(text.slice(0, -1)), { - disabled: props.disabled, - indentation: tabMode === "indentation" ? 2 : undefined, - }); + useEditable( + editorRef, + (text) => { + const t = text.slice(0, -1); + setCode(t); - useEffect(() => { - if (props.onChange) { - props.onChange(code); + if (props.onChange) { + props.onChange(t); + } + }, + { + disabled: props.disabled, + indentation: tabMode === "indentation" ? 2 : undefined, } - }, [code]); + ); return (