Only set locations if component is still mounted

This commit is contained in:
Sebastian Qvarfordt
2020-06-04 11:44:01 +02:00
parent 241a5a8944
commit 5d3a972e4e
@@ -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<CatalogFilterItem>(
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<Location>,
)
.then(setLocations);
.then(location => {
if (isMounted()) setLocations(location);
});
}
}, [value, catalogApi]);
}, [value, catalogApi, isMounted]);
const actions = [
(rowData: Component) => ({