Skip to content

Commit

Permalink
fix(ui): objecteditor only runs onChange when values are modified (#4911
Browse files Browse the repository at this point in the history
)

Signed-off-by: Tianchu Zhao <evantczhao@gmail.com>
  • Loading branch information
tczhao committed Jan 20, 2021
1 parent 8c353d9 commit cd7c16b
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions ui/src/app/shared/components/object-editor/object-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ export const ObjectEditor = <T extends any>({type, value, buttons, onChange}: Pr
useEffect(() => storage.setItem('lang', lang, defaultLang), [lang]);
useEffect(() => setText(stringify(value, lang)), [value]);
useEffect(() => setText(stringify(parse(text), lang)), [lang]);
if (onChange) {
useEffect(() => {
try {
onChange(parse(text));
} catch (e) {
setError(e);
const updateText = (newValue: string) => {
if (onChange) {
{
setText(newValue);
try {
onChange(parse(newValue));
} catch (e) {
setError(e);
}
}
}, [text]);
}
}
};

useEffect(() => {
if (type && lang === 'json') {
Expand Down Expand Up @@ -88,6 +91,7 @@ export const ObjectEditor = <T extends any>({type, value, buttons, onChange}: Pr
renderIndentGuides: false,
scrollBeyondLastLine: true
}}
onChange={newValue => updateText(newValue)}
/>
</div>
<div style={{paddingTop: '1em'}}>
Expand Down

0 comments on commit cd7c16b

Please sign in to comment.