Explorar el Código

editor fix clear issue

Aykut Saraç hace 3 años
padre
commit
692690e68b
Se han modificado 1 ficheros con 2 adiciones y 3 borrados
  1. 2 3
      src/containers/JsonEditor/index.tsx

+ 2 - 3
src/containers/JsonEditor/index.tsx

@@ -56,7 +56,7 @@ export const defaultValue = [
 export const JsonEditor: React.FC = () => {
   const [clear, setClear] = React.useState(0);
   const [json, setJson] = useLocalStorage("json", JSON.stringify(defaultValue));
-  const initialJson = React.useMemo(() => JSON.parse(json), []);
+  const initialJson = React.useMemo(() => JSON.parse(json), [clear]);
 
   React.useEffect(() => {
     if (json === "[]") setClear((c) => c + 1);
@@ -69,7 +69,7 @@ export const JsonEditor: React.FC = () => {
     if (element) {
       element.style.transform = "translate(-75%, 25%)";
     }
-  }, [json]);
+  }, []);
 
   const handleChange = (data: JsonData) => {
     if (!data.error) {
@@ -85,7 +85,6 @@ export const JsonEditor: React.FC = () => {
       locale={locale}
       height="100%"
       width="auto"
-      key={clear}
     />
   );
 };