Skip to content

Commit 66c4741

Browse files
committed
Memoize getTextFilter
1 parent aa9cc6b commit 66c4741

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/components/shared/TableFilters.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import DropDown from "./DropDown";
3131
import { AsyncThunk } from "@reduxjs/toolkit";
3232
import ButtonLikeAnchor from "./ButtonLikeAnchor";
3333
import { ParseKeys } from "i18next";
34+
import { Resource } from "../../slices/tableSlice";
3435

3536
/**
3637
* This component renders the table filters in the upper right corner of the table
@@ -42,7 +43,7 @@ const TableFilters = ({
4243
}: {
4344
loadResource: AsyncThunk<any, void, any>,
4445
loadResourceIntoTable: () => AppThunk,
45-
resource: string,
46+
resource: Resource,
4647
}) => {
4748
const { t } = useTranslation();
4849
const dispatch = useAppDispatch();

src/selectors/tableFilterSelectors.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { createSelector } from "@reduxjs/toolkit";
12
import { RootState } from "../store";
3+
import { Resource } from "../slices/tableSlice";
24

35
/**
46
* This file contains selectors regarding table filters
@@ -12,7 +14,10 @@ export const getSecondFilter = (state: RootState) => state.tableFilters.secondFi
1214
export const getCurrentFilterResource = (state: RootState) => state.tableFilters.currentResource;
1315
export const getFilters = (state: RootState, resource: string) =>
1416
state.tableFilters.data.filter(obj => obj.resource === resource);
15-
export const getTextFilter = (state: RootState, resource: string) => {
16-
const textFilter = state.tableFilters.textFilter.find(obj => obj.resource === resource);
17-
return textFilter?.text ?? "";
18-
};
17+
export const getTextFilter = createSelector(
18+
[getAllTextFilter, (state, resource: Resource) => resource],
19+
(textFilter, resource) => {
20+
const textFilte = textFilter.find(obj => obj.resource === resource);
21+
return textFilte?.text ?? "";
22+
},
23+
);

0 commit comments

Comments
 (0)