From 36c5a1a5bc42ebc1884a6568011b277dd00f0173 Mon Sep 17 00:00:00 2001 From: Alem Tuzlak Date: Thu, 9 Jan 2025 10:34:45 +0100 Subject: [PATCH] fix: Remove setState calls when component is unmounted (#172) --- src/client/components/jsonRenderer.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/client/components/jsonRenderer.tsx b/src/client/components/jsonRenderer.tsx index ff32ce9..815c0f3 100644 --- a/src/client/components/jsonRenderer.tsx +++ b/src/client/components/jsonRenderer.tsx @@ -51,7 +51,13 @@ const JsonRenderer = ({ data, expansionLevel }: JsonRendererProps) => { const [json, setJson] = useState(originalData) useEffect(() => { - setJson(data) + let mounted = true + if (mounted) { + setJson(data) + } + return () => { + mounted = false + } }, [data]) if (typeof json === "string") {