Skip to content

Commit 2e8b475

Browse files
authored
Merge pull request Expensify#64735 from callstack-internal/VickyStash/refactor/remove-initialValue-from-useOnyx
Remove initialValue from useOnyx hook
2 parents bf868bc + a773a37 commit 2e8b475

60 files changed

Lines changed: 169 additions & 126 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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, {initialValue: {}});
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/FloatingActionButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function FloatingActionButton({onPress, isActive, accessibilityLabel, role, isTo
4646
const borderRadius = styles.floatingActionButton.borderRadius;
4747
const fabPressable = useRef<HTMLDivElement | View | Text | null>(null);
4848
const {shouldUseNarrowLayout} = useResponsiveLayout();
49-
const [isSidebarLoaded] = useOnyx(ONYXKEYS.IS_SIDEBAR_LOADED, {initialValue: false, canBeMissing: true});
49+
const [isSidebarLoaded = false] = useOnyx(ONYXKEYS.IS_SIDEBAR_LOADED, {canBeMissing: true});
5050
const isHomeRouteActive = useIsHomeRouteActive(shouldUseNarrowLayout);
5151
const {renderProductTrainingTooltip, shouldShowProductTrainingTooltip, hideProductTrainingTooltip} = useProductTrainingContext(
5252
CONST.PRODUCT_TRAINING_TOOLTIP_NAMES.GLOBAL_CREATE_TOOLTIP,

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import ROUTES from '@src/ROUTES';
8686
import SCREENS from '@src/SCREENS';
8787
import type * as OnyxTypes from '@src/types/onyx';
8888
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
89+
import getEmptyArray from '@src/types/utils/getEmptyArray';
8990
import type IconAsset from '@src/types/utils/IconAsset';
9091
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
9192
import BrokenConnectionDescription from './BrokenConnectionDescription';
@@ -168,15 +169,14 @@ function MoneyReportHeader({
168169
}
169170
return reportActions.find((action): action is OnyxTypes.ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.IOU> => action.reportActionID === transactionThreadReport.parentReportActionID);
170171
}, [reportActions, transactionThreadReport?.parentReportActionID]);
171-
const [transactions = []] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {
172+
const [transactions = getEmptyArray<OnyxTypes.Transaction>()] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {
172173
selector: (_transactions) => reportTransactionsSelector(_transactions, moneyRequestReport?.reportID),
173-
initialValue: [],
174174
canBeMissing: true,
175175
});
176176
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${isMoneyRequestAction(requestParentReportAction) && getOriginalMessage(requestParentReportAction)?.IOUTransactionID}`, {
177177
canBeMissing: true,
178178
});
179-
const [dismissedHoldUseExplanation, dismissedHoldUseExplanationResult] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, {initialValue: true, canBeMissing: true});
179+
const [dismissedHoldUseExplanation, dismissedHoldUseExplanationResult] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, {canBeMissing: true});
180180
const isLoadingHoldUseExplained = isLoadingOnyxValue(dismissedHoldUseExplanationResult);
181181
const [invoiceReceiverPolicy] = useOnyx(
182182
`${ONYXKEYS.COLLECTION.POLICY}${chatReport?.invoiceReceiver && 'policyID' in chatReport.invoiceReceiver ? chatReport.invoiceReceiver.policyID : undefined}`,

src/components/MoneyRequestHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
8282

8383
const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false);
8484
const [downloadErrorModalVisible, setDownloadErrorModalVisible] = useState(false);
85-
const [dismissedHoldUseExplanation, dismissedHoldUseExplanationResult] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, {initialValue: true, canBeMissing: false});
85+
const [dismissedHoldUseExplanation, dismissedHoldUseExplanationResult] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, {canBeMissing: false});
8686
const shouldShowLoadingBar = useLoadingBarVisibility();
8787
const isLoadingHoldUseExplained = isLoadingOnyxValue(dismissedHoldUseExplanationResult);
8888
const styles = useThemeStyles();

src/components/MoneyRequestReportView/MoneyRequestReportTransactionsNavigation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import useOnyx from '@hooks/useOnyx';
55
import {clearActiveTransactionThreadIDs} from '@libs/actions/TransactionThreadNavigation';
66
import Navigation from '@navigation/Navigation';
77
import navigationRef from '@navigation/navigationRef';
8-
import CONST from '@src/CONST';
98
import ONYXKEYS from '@src/ONYXKEYS';
109
import ROUTES from '@src/ROUTES';
1110
import SCREENS from '@src/SCREENS';
11+
import getEmptyArray from '@src/types/utils/getEmptyArray';
1212

1313
type MoneyRequestReportRHPNavigationButtonsProps = {
1414
currentReportID: string;
1515
};
1616

1717
function MoneyRequestReportTransactionsNavigation({currentReportID}: MoneyRequestReportRHPNavigationButtonsProps) {
18-
const [reportIDsList = CONST.EMPTY_ARRAY] = useOnyx(ONYXKEYS.TRANSACTION_THREAD_NAVIGATION_REPORT_IDS, {
18+
const [reportIDsList = getEmptyArray<string>()] = useOnyx(ONYXKEYS.TRANSACTION_THREAD_NAVIGATION_REPORT_IDS, {
1919
canBeMissing: true,
2020
});
2121

src/components/MoneyRequestReportView/MoneyRequestReportView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe
9090

9191
const reportID = report?.reportID;
9292
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true});
93-
const [isComposerFullSize] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportID}`, {initialValue: false, canBeMissing: true});
93+
const [isComposerFullSize = false] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportID}`, {canBeMissing: true});
9494
const {reportPendingAction, reportErrors} = getReportOfflinePendingActionAndErrors(report);
9595
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.chatReportID)}`, {canBeMissing: true});
9696

src/components/ProductTrainingContext/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const ProductTrainingContext = createContext<ProductTrainingContextType>({
4949
});
5050

5151
function ProductTrainingContextProvider({children}: ChildrenProps) {
52-
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {initialValue: true, canBeMissing: true});
52+
const [isLoadingApp = true] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true});
5353
const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT, {canBeMissing: true});
5454
const hasBeenAddedToNudgeMigration = !!tryNewDot?.nudgeMigration?.timestamp;
5555
const [isOnboardingCompleted = true, isOnboardingCompletedMetadata] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {

src/components/Reactions/MiniQuickEmojiReactions.tsx

Lines changed: 4 additions & 2 deletions
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 & {
@@ -37,8 +39,8 @@ function MiniQuickEmojiReactions({reportAction, reportActionID, onEmojiSelected,
3739
const StyleUtils = useStyleUtils();
3840
const ref = useRef<View>(null);
3941
const {translate, preferredLocale} = useLocalize();
40-
const [preferredSkinTone] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {canBeMissing: true, initialValue: CONST.EMOJI_DEFAULT_SKIN_TONE});
41-
const [emojiReactions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {canBeMissing: true, initialValue: {}});
42+
const [preferredSkinTone = CONST.EMOJI_DEFAULT_SKIN_TONE] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {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: 4 additions & 2 deletions
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({
@@ -23,8 +25,8 @@ function BaseQuickEmojiReactions({
2325
}: BaseQuickEmojiReactionsProps) {
2426
const styles = useThemeStyles();
2527
const {preferredLocale} = useLocalize();
26-
const [preferredSkinTone] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {canBeMissing: true, initialValue: CONST.EMOJI_DEFAULT_SKIN_TONE});
27-
const [emojiReactions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {canBeMissing: true, initialValue: {}});
28+
const [preferredSkinTone = CONST.EMOJI_DEFAULT_SKIN_TONE] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {canBeMissing: true});
29+
const [emojiReactions = getEmptyObject<ReportActionReactions>()] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`, {canBeMissing: true});
2830

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

0 commit comments

Comments
 (0)