From 78b6736d003486a32d469846729be90811b08c19 Mon Sep 17 00:00:00 2001 From: Alem Tuzlak Date: Tue, 17 Dec 2024 18:44:22 +0100 Subject: [PATCH] fix: Remove setState calls when component is unmounted --- 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") {