Skip to content

Commit 01f26aa

Browse files
committed
Revert "Revert "fix: remove redundant useEffect""
This reverts commit ed10bb9.
1 parent ed10bb9 commit 01f26aa

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/Common/CodeEditor/CodeEditor.tsx

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

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

202203
useEffect(() => {
203204
if (noParsing) {
204-
dispatch({ type: 'setCode', value })
205+
setCode(value)
205206

206207
return
207208
}
@@ -220,7 +221,7 @@ const CodeEditor: React.FC<CodeEditorInterface> & CodeEditorComposition = React.
220221
if (obj) {
221222
final = state.mode === 'json' ? JSON.stringify(obj, null, tabSize) : YAMLStringify(obj)
222223
}
223-
dispatch({ type: 'setCode', value: final })
224+
setCode(final)
224225
}, [value, noParsing])
225226

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

236237
function handleOnChange(newValue, e) {
237-
dispatch({ type: 'setCode', value: newValue })
238+
setCode(newValue)
238239
}
239240

240241
function handleLanguageChange(mode: 'json' | 'yaml') {
241242
dispatch({ type: 'changeLanguage', value: mode })
242-
dispatch({ type: 'setCode', value: mode === 'json' ? json : yamlCode })
243+
setCode(mode === 'json' ? json : yamlCode)
243244
}
244245

245246
const options: monaco.editor.IEditorConstructionOptions = {

0 commit comments

Comments
 (0)