From 5d3a972e4ee1aaa44b774e7a53be02831b02ac02 Mon Sep 17 00:00:00 2001 From: Sebastian Qvarfordt Date: Thu, 4 Jun 2020 11:44:01 +0200 Subject: [PATCH] Only set locations if component is still mounted --- .../catalog/src/components/CatalogPage/CatalogPage.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx b/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx index 5951365b6e..25d2618a9a 100644 --- a/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx +++ b/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx @@ -26,7 +26,7 @@ import { pageTheme, useApi, } from '@backstage/core'; -import { useAsync } from 'react-use'; +import { useAsync, useMountedState } from 'react-use'; import CatalogTable from '../CatalogTable/CatalogTable'; import { CatalogFilter, @@ -57,6 +57,7 @@ const CatalogPage: FC<{}> = () => { const [selectedFilter, setSelectedFilter] = useState( defaultFilter, ); + const isMounted = useMountedState(); const onFilterSelected = useCallback( selected => setSelectedFilter(selected), @@ -77,9 +78,11 @@ const CatalogPage: FC<{}> = () => { (location): Location[] => location.filter(l => !!l) as Array, ) - .then(setLocations); + .then(location => { + if (isMounted()) setLocations(location); + }); } - }, [value, catalogApi]); + }, [value, catalogApi, isMounted]); const actions = [ (rowData: Component) => ({