Skip to content

Commit ed10bb9

Browse files
committed
Revert "fix: remove redundant useEffect"
This reverts commit 105e742.
1 parent bcc4d6e commit ed10bb9

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/Common/CodeEditor/CodeEditor.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,15 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
193193
editorRef.current.layout()
194194
}, [width, windowHeight])
195195

196-
const setCode = (value: string) => {
197-
dispatch({ type: 'setCode', value })
196+
useEffect(() => {
198197
if (onChange) {
199-
onChange(value)
198+
onChange(state.code)
200199
}
201-
}
200+
}, [state.code])
202201

203202
useEffect(() => {
204203
if (noParsing) {
205-
setCode(value)
204+
dispatch({ type: 'setCode', value })
206205

207206
return
208207
}
@@ -221,7 +220,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
221220
if (obj) {
222221
final = state.mode === 'json' ? JSON.stringify(obj, null, tabSize) : YAMLStringify(obj)
223222
}
224-
setCode(final)
223+
dispatch({ type: 'setCode', value: final })
225224
}, [value, noParsing])
226225

227226
useEffect(() => {
@@ -235,12 +234,12 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
235234
}, [focus])
236235

237236
function handleOnChange(newValue, e) {
238-
setCode(newValue)
237+
dispatch({ type: 'setCode', value: newValue })
239238
}
240239

241240
function handleLanguageChange(mode: 'json' | 'yaml') {
242241
dispatch({ type: 'changeLanguage', value: mode })
243-
setCode(mode === 'json' ? json : yamlCode)
242+
dispatch({ type: 'setCode', value: mode === 'json' ? json : yamlCode })
244243
}
245244

246245
const options: monaco.editor.IEditorConstructionOptions = {

0 commit comments

Comments
 (0)