Skip to content

Commit 80cff7c

Browse files
committed
Add stable default values references
1 parent fb07a10 commit 80cff7c

34 files changed

Lines changed: 124 additions & 65 deletions

src/components/ArchivedReportFooter.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import * as ReportActionsUtils from '@libs/ReportActionsUtils';
99
import * as ReportUtils from '@libs/ReportUtils';
1010
import CONST from '@src/CONST';
1111
import ONYXKEYS from '@src/ONYXKEYS';
12-
import type {Report} from '@src/types/onyx';
12+
import type {PersonalDetailsList, Report} from '@src/types/onyx';
13+
import {getEmptyObject} from '@src/types/utils/EmptyObject';
1314
import Banner from './Banner';
1415

1516
type ArchivedReportFooterProps = {
@@ -21,7 +22,7 @@ function ArchivedReportFooter({report}: ArchivedReportFooterProps) {
2122
const styles = useThemeStyles();
2223
const {translate} = useLocalize();
2324

24-
const [personalDetails = {}] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
25+
const [personalDetails = getEmptyObject<PersonalDetailsList>()] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
2526
const [reportClosedAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {canEvict: false, selector: ReportActionsUtils.getLastClosedReportAction});
2627
const originalMessage = ReportActionsUtils.isClosedAction(reportClosedAction) ? ReportActionsUtils.getOriginalMessage(reportClosedAction) : null;
2728
const archiveReason = originalMessage?.reason ?? CONST.REPORT.ARCHIVE_REASON.DEFAULT;

src/components/KYCWall/BaseKYCWall.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import {setKYCWallSource} from '@userActions/Wallet';
1717
import CONST from '@src/CONST';
1818
import ONYXKEYS from '@src/ONYXKEYS';
1919
import ROUTES from '@src/ROUTES';
20+
import type {BankAccountList} from '@src/types/onyx';
2021
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
22+
import {getEmptyObject} from '@src/types/utils/EmptyObject';
2123
import viewRef from '@src/types/utils/viewRef';
2224
import type {AnchorPosition, DomRect, KYCWallProps, PaymentMethod} from './types';
2325

@@ -48,7 +50,7 @@ function KYCWall({
4850
const [userWallet] = useOnyx(ONYXKEYS.USER_WALLET, {canBeMissing: true});
4951
const [walletTerms] = useOnyx(ONYXKEYS.WALLET_TERMS, {canBeMissing: true});
5052
const [fundList] = useOnyx(ONYXKEYS.FUND_LIST, {canBeMissing: true});
51-
const [bankAccountList = {}] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});
53+
const [bankAccountList = getEmptyObject<BankAccountList>()] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});
5254
const [reimbursementAccount] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {canBeMissing: true});
5355

5456
const anchorRef = useRef<HTMLDivElement | View>(null);

src/components/MoneyReportHeader.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import ROUTES from '@src/ROUTES';
8585
import SCREENS from '@src/SCREENS';
8686
import type * as OnyxTypes from '@src/types/onyx';
8787
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
88+
import getEmptyArray from '@src/types/utils/getEmptyArray';
8889
import type IconAsset from '@src/types/utils/IconAsset';
8990
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
9091
import BrokenConnectionDescription from './BrokenConnectionDescription';
@@ -167,7 +168,7 @@ function MoneyReportHeader({
167168
}
168169
return reportActions.find((action): action is OnyxTypes.ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.IOU> => action.reportActionID === transactionThreadReport.parentReportActionID);
169170
}, [reportActions, transactionThreadReport?.parentReportActionID]);
170-
const [transactions = []] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {
171+
const [transactions = getEmptyArray<OnyxTypes.Transaction>()] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {
171172
selector: (_transactions) => reportTransactionsSelector(_transactions, moneyRequestReport?.reportID),
172173
canBeMissing: true,
173174
});

src/components/Reactions/MiniQuickEmojiReactions.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {emojiPickerRef, showEmojiPicker} from '@userActions/EmojiPickerAction';
1616
import {callFunctionIfActionIsAllowed} from '@userActions/Session';
1717
import CONST from '@src/CONST';
1818
import ONYXKEYS from '@src/ONYXKEYS';
19+
import type {ReportActionReactions} from '@src/types/onyx';
20+
import {getEmptyObject} from '@src/types/utils/EmptyObject';
1921
import type {BaseQuickEmojiReactionsProps} from './QuickEmojiReactions/types';
2022

2123
type MiniQuickEmojiReactionsProps = BaseQuickEmojiReactionsProps & {
@@ -38,7 +40,7 @@ function MiniQuickEmojiReactions({reportAction, reportActionID, onEmojiSelected,
3840
const ref = useRef<View>(null);
3941
const {translate, preferredLocale} = useLocalize();
4042
const [preferredSkinTone = CONST.EMOJI_DEFAULT_SKIN_TONE] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {canBeMissing: true});
41-
const [emojiReactions = {}] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {canBeMissing: true});
43+
const [emojiReactions = getEmptyObject<ReportActionReactions>()] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {canBeMissing: true});
4244

4345
const openEmojiPicker = () => {
4446
onPressOpenPicker();

src/components/Reactions/QuickEmojiReactions/BaseQuickEmojiReactions.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {getLocalizedEmojiName, getPreferredEmojiCode} from '@libs/EmojiUtils';
1111
import {callFunctionIfActionIsAllowed} from '@userActions/Session';
1212
import CONST from '@src/CONST';
1313
import ONYXKEYS from '@src/ONYXKEYS';
14+
import type {ReportActionReactions} from '@src/types/onyx';
15+
import {getEmptyObject} from '@src/types/utils/EmptyObject';
1416
import type {BaseQuickEmojiReactionsProps} from './types';
1517

1618
function BaseQuickEmojiReactions({
@@ -24,7 +26,7 @@ function BaseQuickEmojiReactions({
2426
const styles = useThemeStyles();
2527
const {preferredLocale} = useLocalize();
2628
const [preferredSkinTone = CONST.EMOJI_DEFAULT_SKIN_TONE] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {canBeMissing: true});
27-
const [emojiReactions = {}] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {canBeMissing: true});
29+
const [emojiReactions = getEmptyObject<ReportActionReactions>()] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {canBeMissing: true});
2830

2931
return (
3032
<View style={styles.quickReactionsContainer}>

src/components/Search/SearchAutocompleteList.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Str} from 'expensify-common';
22
import type {ForwardedRef} from 'react';
33
import React, {forwardRef, useCallback, useEffect, useMemo, useState} from 'react';
4+
import type {OnyxCollection} from 'react-native-onyx';
45
import * as Expensicons from '@components/Icon/Expensicons';
56
import {usePersonalDetails} from '@components/OnyxProvider';
67
import {useOptionsList} from '@components/OptionListContextProvider';
@@ -39,7 +40,9 @@ import StringUtils from '@libs/StringUtils';
3940
import Timing from '@userActions/Timing';
4041
import CONST from '@src/CONST';
4142
import ONYXKEYS from '@src/ONYXKEYS';
43+
import type {Policy, Report} from '@src/types/onyx';
4244
import type PersonalDetails from '@src/types/onyx/PersonalDetails';
45+
import {getEmptyObject} from '@src/types/utils/EmptyObject';
4346
import {getSubstitutionMapKey} from './SearchRouter/getQueryWithSubstitutions';
4447
import type {SearchFilterKey, UserFriendlyKey} from './types';
4548

@@ -154,7 +157,7 @@ function SearchAutocompleteList(
154157
const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true});
155158
const [recentSearches] = useOnyx(ONYXKEYS.RECENT_SEARCHES, {canBeMissing: true});
156159
const personalDetails = usePersonalDetails();
157-
const [reports = {}] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true});
160+
const [reports = getEmptyObject<NonNullable<OnyxCollection<Report>>>()] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true});
158161
const taxRates = getAllTaxRates();
159162

160163
const {options, areOptionsInitialized} = useOptionsList();
@@ -248,7 +251,7 @@ function SearchAutocompleteList(
248251
return getAutocompleteRecentCategories(allRecentCategories);
249252
}, [allRecentCategories]);
250253

251-
const [policies = {}] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: false});
254+
const [policies = getEmptyObject<NonNullable<OnyxCollection<Policy>>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: false});
252255
const [currentUserLogin] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.email, canBeMissing: false});
253256

254257
const workspaceList = useMemo(

src/components/Search/SearchPageHeader/SearchFiltersBar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import ONYXKEYS from '@src/ONYXKEYS';
3939
import ROUTES from '@src/ROUTES';
4040
import type {SearchAdvancedFiltersForm} from '@src/types/form';
4141
import FILTER_KEYS from '@src/types/form/SearchAdvancedFiltersForm';
42+
import type {CurrencyList} from '@src/types/onyx';
43+
import {getEmptyObject} from '@src/types/utils/EmptyObject';
4244
import type {SearchHeaderOptionValue} from './SearchPageHeader';
4345

4446
type SearchFiltersBarProps = {
@@ -66,7 +68,7 @@ function SearchFiltersBar({queryJSON, headerButtonsOptions}: SearchFiltersBarPro
6668
const [userCardList] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true});
6769
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: false});
6870
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true});
69-
const [currencyList = {}] = useOnyx(ONYXKEYS.CURRENCY_LIST, {canBeMissing: true});
71+
const [currencyList = getEmptyObject<CurrencyList>()] = useOnyx(ONYXKEYS.CURRENCY_LIST, {canBeMissing: true});
7072
const [policyTagsLists] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS, {canBeMissing: true});
7173
const [policyCategories] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES, {canBeMissing: true});
7274
const [workspaceCardFeeds] = useOnyx(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST, {canBeMissing: true});

src/components/SelectionList/Search/TransactionGroupListItem.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, {useMemo} from 'react';
22
import {View} from 'react-native';
3+
import type {OnyxCollection} from 'react-native-onyx';
34
import type {ValueOf} from 'type-fest';
45
import type {SearchGroupBy} from '@components/Search/types';
56
import BaseListItem from '@components/SelectionList/BaseListItem';
@@ -27,6 +28,8 @@ import {setActiveTransactionThreadIDs} from '@userActions/TransactionThreadNavig
2728
import CONST from '@src/CONST';
2829
import ONYXKEYS from '@src/ONYXKEYS';
2930
import ROUTES from '@src/ROUTES';
31+
import type {Policy} from '@src/types/onyx';
32+
import {getEmptyObject} from '@src/types/utils/EmptyObject';
3033
import CardListItemHeader from './CardListItemHeader';
3134
import MemberListItemHeader from './MemberListItemHeader';
3235
import ReportListItemHeader from './ReportListItemHeader';
@@ -48,7 +51,7 @@ function TransactionGroupListItem<TItem extends ListItem>({
4851
const theme = useTheme();
4952
const styles = useThemeStyles();
5053
const {translate} = useLocalize();
51-
const [policies = {}] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, canBeMissing: true});
54+
const [policies = getEmptyObject<NonNullable<OnyxCollection<Policy>>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, canBeMissing: true});
5255
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${groupItem?.policyID}`];
5356
const isEmpty = groupItem.transactions.length === 0;
5457
const isDisabledOrEmpty = isEmpty || isDisabled;

src/components/ValidateCodeActionModal/ValidateCodeForm/BaseValidateCodeForm.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ import {clearValidateCodeActionError} from '@userActions/User';
2323
import CONST from '@src/CONST';
2424
import type {TranslationPaths} from '@src/languages/types';
2525
import ONYXKEYS from '@src/ONYXKEYS';
26+
import type {Account} from '@src/types/onyx';
2627
import type {Errors, PendingAction} from '@src/types/onyx/OnyxCommon';
27-
import {isEmptyObject} from '@src/types/utils/EmptyObject';
28+
import {getEmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject';
2829

2930
type ValidateCodeFormHandle = {
3031
focus: () => void;
@@ -112,7 +113,7 @@ function BaseValidateCodeForm({
112113
const [formError, setFormError] = useState<ValidateCodeFormError>({});
113114
const [validateCode, setValidateCode] = useState('');
114115
const inputValidateCodeRef = useRef<MagicCodeInputHandle>(null);
115-
const [account = {}] = useOnyx(ONYXKEYS.ACCOUNT, {
116+
const [account = getEmptyObject<Account>()] = useOnyx(ONYXKEYS.ACCOUNT, {
116117
canBeMissing: true,
117118
});
118119

src/hooks/usePaymentOptions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import Navigation from '@navigation/Navigation';
1515
import {isCurrencySupportedForDirectReimbursement} from '@userActions/Policy/Policy';
1616
import CONST from '@src/CONST';
1717
import ONYXKEYS from '@src/ONYXKEYS';
18-
import type {LastPaymentMethodType} from '@src/types/onyx';
19-
import {isEmptyObject} from '@src/types/utils/EmptyObject';
18+
import type {BankAccountList, FundList, LastPaymentMethodType} from '@src/types/onyx';
19+
import {getEmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject';
2020
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
2121
import useLocalize from './useLocalize';
2222
import useOnyx from './useOnyx';
@@ -80,8 +80,8 @@ function usePaymentOptions({
8080
});
8181

8282
const isLoadingLastPaymentMethod = isLoadingOnyxValue(lastPaymentMethodResult);
83-
const [bankAccountList = {}] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});
84-
const [fundList = {}] = useOnyx(ONYXKEYS.FUND_LIST, {canBeMissing: true});
83+
const [bankAccountList = getEmptyObject<BankAccountList>()] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});
84+
const [fundList = getEmptyObject<FundList>()] = useOnyx(ONYXKEYS.FUND_LIST, {canBeMissing: true});
8585
const lastPaymentMethodRef = useRef(lastPaymentMethod);
8686

8787
useEffect(() => {

0 commit comments

Comments
 (0)