From 1876e38aa9d56d9424049c5e0424b851d2a30c2a Mon Sep 17 00:00:00 2001 From: rektdeckard Date: Sat, 10 Oct 2020 18:05:21 -0400 Subject: [PATCH] SearchInput: skip state updates after unmount --- src/components/SearchInput/SearchInput.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/SearchInput/SearchInput.tsx b/src/components/SearchInput/SearchInput.tsx index d6d15d5..f407d25 100644 --- a/src/components/SearchInput/SearchInput.tsx +++ b/src/components/SearchInput/SearchInput.tsx @@ -15,10 +15,12 @@ const SearchInput: React.FC = () => { /* eslint-disable react-hooks/exhaustive-deps */ useEffect(() => { + let isMounted = true; if (value !== query) { - setValue(query); + isMounted && setValue(query); ReactGA.event({ category: "Search", action: "Tag", label: query }); } + return () => void (isMounted = false); }, [query]); /* eslint-enable react-hooks/exhaustive-deps */