Skip to content

Commit

Permalink
refactor: replace withOnyx usage with useOnyx
Browse files Browse the repository at this point in the history
  • Loading branch information
pac-guerreiro committed Sep 17, 2024
1 parent 347ec96 commit 992cdfb
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/components/TestToolMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ApiUtils from '@libs/ApiUtils';
Expand All @@ -17,18 +17,21 @@ import TestCrash from './TestCrash';
import TestToolRow from './TestToolRow';
import Text from './Text';

type TestToolMenuOnyxProps = {
/** User object in Onyx */
user: OnyxEntry<UserOnyx>;
};

type TestToolMenuProps = TestToolMenuOnyxProps & {
type TestToolMenuProps = {
/** Network object in Onyx */
network: OnyxEntry<NetworkOnyx>;
};
const USER_DEFAULT: UserOnyx = {shouldUseStagingServer: undefined, isSubscribedToNewsletter: false, validated: false, isFromPublicDomain: false, isUsingExpensifyCard: false};
const USER_DEFAULT: UserOnyx = {
shouldUseStagingServer: undefined,
isSubscribedToNewsletter: false,
validated: false,
isFromPublicDomain: false,
isUsingExpensifyCard: false,
isDebugModeEnabled: false,
};

function TestToolMenu({user = USER_DEFAULT, network}: TestToolMenuProps) {
function TestToolMenu({network}: TestToolMenuProps) {
const [user = USER_DEFAULT] = useOnyx(ONYXKEYS.USER);
const shouldUseStagingServer = user?.shouldUseStagingServer ?? ApiUtils.isUsingStagingApi();
const isDebugModeEnabled = !!user?.isDebugModeEnabled;
const styles = useThemeStyles();
Expand Down Expand Up @@ -107,10 +110,4 @@ function TestToolMenu({user = USER_DEFAULT, network}: TestToolMenuProps) {

TestToolMenu.displayName = 'TestToolMenu';

export default withNetwork()(
withOnyx<TestToolMenuProps, TestToolMenuOnyxProps>({
user: {
key: ONYXKEYS.USER,
},
})(TestToolMenu),
);
export default withNetwork()(TestToolMenu);

0 comments on commit 992cdfb

Please sign in to comment.