소스 검색

fix error

AykutSarac 3 년 전
부모
커밋
d58a6a86e3
1개의 변경된 파일13개의 추가작업 그리고 12개의 파일을 삭제
  1. 13 12
      src/containers/JsonEditor/index.tsx

+ 13 - 12
src/containers/JsonEditor/index.tsx

@@ -26,10 +26,7 @@ const aceOptions: IAceOptions = {
 };
 };
 
 
 const JsonEditor: React.FC = () => {
 const JsonEditor: React.FC = () => {
-  const {
-    states: { json, settings },
-    dispatch,
-  } = useConfig();
+  const { json, settings, dispatch } = useConfig();
   const [editorWidth, setEditorWidth] = React.useState("auto");
   const [editorWidth, setEditorWidth] = React.useState("auto");
   const [value, setValue] = React.useState("");
   const [value, setValue] = React.useState("");
   const [error, setError] = React.useState({
   const [error, setError] = React.useState({
@@ -56,21 +53,25 @@ const JsonEditor: React.FC = () => {
 
 
   React.useEffect(() => {
   React.useEffect(() => {
     if (settings.autoformat) {
     if (settings.autoformat) {
-      setValue(JSON.stringify(JSON.parse(json), null, 2));
-    } else {
-      setValue(json);
+      return setValue(JSON.stringify(JSON.parse(json), null, 2));
     }
     }
+
+    setValue(json);
   }, [settings.autoformat, json]);
   }, [settings.autoformat, json]);
 
 
   React.useEffect(() => {
   React.useEffect(() => {
     const formatTimer = setTimeout(() => {
     const formatTimer = setTimeout(() => {
       try {
       try {
         if (value) {
         if (value) {
-          parseJson(json);
-          dispatch({
-            type: ConfigActionType.SET_JSON,
-            payload: value,
-          });
+          const parsedJson = parseJson(value);
+
+          if (settings.autoformat) {
+            setValue(JSON.stringify(parsedJson, null, 2));
+          } else {
+            setValue(value);
+          }
+
+          dispatch({ type: ConfigActionType.SET_JSON, payload: value });
         }
         }
 
 
         setError((err) => ({ ...err, message: "" }));
         setError((err) => ({ ...err, message: "" }));