diff --git a/src/hooks/useReportWithTransactionsAndViolations.ts b/src/hooks/useReportWithTransactionsAndViolations.ts index f9308165fc85f..caf854dd97406 100644 --- a/src/hooks/useReportWithTransactionsAndViolations.ts +++ b/src/hooks/useReportWithTransactionsAndViolations.ts @@ -1,6 +1,5 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import {reportTransactionsSelector} from '@libs/ReportUtils'; -import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Report, Transaction, TransactionViolation} from '@src/types/onyx'; import useOnyx from './useOnyx'; @@ -9,18 +8,24 @@ const DEFAULT_TRANSACTIONS: Transaction[] = []; const DEFAULT_VIOLATIONS: Record = {}; function useReportWithTransactionsAndViolations(reportID?: string): [OnyxEntry, Transaction[], OnyxCollection] { - const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID ?? CONST.DEFAULT_NUMBER_ID}`); + const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: false}); const [transactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, { selector: (_transactions) => reportTransactionsSelector(_transactions, reportID), + canBeMissing: true, }); - const [violations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, { - selector: (allViolations) => - Object.fromEntries( - Object.entries(allViolations ?? {}).filter(([key]) => - transactions?.some((transaction) => transaction.transactionID === key.replace(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, '')), + const [violations] = useOnyx( + ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, + { + selector: (allViolations) => + Object.fromEntries( + Object.entries(allViolations ?? {}).filter(([key]) => + transactions?.some((transaction) => transaction.transactionID === key.replace(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, '')), + ), ), - ), - }); + canBeMissing: true, + }, + [transactions], + ); return [report, transactions ?? DEFAULT_TRANSACTIONS, violations ?? DEFAULT_VIOLATIONS]; }