Skip to content

Commit a83492f

Browse files
committed
avoid calling deepEqual on selector output in useArchivedReportsIdSet
1 parent 0c68091 commit a83492f

1 file changed

Lines changed: 10 additions & 23 deletions

File tree

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,23 @@
1-
import type {OnyxCollection} from 'react-native-onyx';
21
import {isArchivedReport} from '@libs/ReportUtils';
32
import type {ArchivedReportsIDSet} from '@libs/SearchUIUtils';
4-
import CONST from '@src/CONST';
53
import ONYXKEYS from '@src/ONYXKEYS';
6-
import type {ReportNameValuePairs} from '@src/types/onyx';
74
import useOnyx from './useOnyx';
85

9-
/**
10-
* Selector that extracts archived report IDs as a sorted array.
11-
* Onyx performs shallow comparison on the returned array to prevent
12-
* unnecessary re-renders without expensive deep comparison of Sets.
13-
*/
14-
const archivedReportIdsSelector = (reportNameValuePairs: OnyxCollection<ReportNameValuePairs>): string[] => {
15-
if (!reportNameValuePairs) {
16-
return [];
17-
}
18-
const ids: string[] = [];
19-
for (const [key, value] of Object.entries(reportNameValuePairs)) {
20-
if (isArchivedReport(value)) {
21-
ids.push(key);
22-
}
23-
}
24-
return ids;
25-
};
26-
276
/**
287
* Hook that returns a Set of archived report IDs
298
*/
309
function useArchivedReportsIdSet(): ArchivedReportsIDSet {
31-
const [archivedReportIds = CONST.EMPTY_ARRAY] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {selector: archivedReportIdsSelector});
10+
const [reportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS);
11+
const ids: string[] = [];
3212

33-
return new Set(archivedReportIds);
13+
if (reportNameValuePairs) {
14+
for (const [key, value] of Object.entries(reportNameValuePairs)) {
15+
if (isArchivedReport(value)) {
16+
ids.push(key);
17+
}
18+
}
19+
}
20+
return new Set(ids);
3421
}
3522

3623
export default useArchivedReportsIdSet;

0 commit comments

Comments
 (0)