Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add small improvements related to introducing React strict mode #44155

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@
"react-web-config": "^1.0.0",
"react-webcam": "^7.1.1",
"react-window": "^1.8.9",
"semver": "^7.5.2",
"shim-keyboard-event-key": "^1.0.3"
"semver": "^7.5.2"
},
"devDependencies": {
"@actions/core": "1.10.0",
Expand Down
4 changes: 2 additions & 2 deletions src/components/TextInput/TextInputClearButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {forwardRef} from 'react';
import React from 'react';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import {PressableWithoutFeedback} from '@components/Pressable';
Expand Down Expand Up @@ -40,4 +40,4 @@ function TextInputClearButton({onPressButton}: TextInputClearButtonProps) {

TextInputClearButton.displayName = 'TextInputClearButton';

export default forwardRef(TextInputClearButton);
export default TextInputClearButton;
63 changes: 13 additions & 50 deletions src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
import {useEffect} from 'react';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import useActiveWorkspace from '@hooks/useActiveWorkspace';
import usePermissions from '@hooks/usePermissions';
import {getPolicyEmployeeListByIdWithoutCurrentUser} from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetailsList, Policy, Report, ReportMetadata} from '@src/types/onyx';
import type {Policy, Report, ReportMetadata} from '@src/types/onyx';
import type {ReportScreenWrapperProps} from './ReportScreenWrapper';

type ReportScreenIDSetterComponentProps = {
/** Available reports that would be displayed in this navigator */
reports: OnyxCollection<Report>;

/** The policies which the user has access to */
policies: OnyxCollection<Policy>;

/** The personal details of the person who is logged in */
personalDetails: OnyxEntry<PersonalDetailsList>;

/** Whether user is a new user */
isFirstTimeNewExpensifyUser: OnyxEntry<boolean>;

/** The report metadata */
reportMetadata: OnyxCollection<ReportMetadata>;

/** The accountID of the current user */
accountID?: number;
};

type ReportScreenIDSetterProps = ReportScreenIDSetterComponentProps & ReportScreenWrapperProps;
type ReportScreenIDSetterProps = ReportScreenWrapperProps;

/**
* Get the most recently accessed report for the user
Expand Down Expand Up @@ -57,11 +37,18 @@ const getLastAccessedReportID = (
return lastReport?.reportID;
};

// This wrapper is reponsible for opening the last accessed report if there is no reportID specified in the route params
function ReportScreenIDSetter({route, reports, policies, navigation, isFirstTimeNewExpensifyUser = false, reportMetadata, accountID, personalDetails}: ReportScreenIDSetterProps) {
// This wrapper is responsible for opening the last accessed report if there is no reportID specified in the route params
function ReportScreenIDSetter({route, navigation}: ReportScreenIDSetterProps) {
const {canUseDefaultRooms} = usePermissions();
const {activeWorkspaceID} = useActiveWorkspace();

const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {allowStaleData: true});
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true});
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const [isFirstTimeNewExpensifyUser] = useOnyx(ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER, {initialValue: false});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB but you initialValue is kind of outdated for useOnyx. IMO this is a clearer way to achieve the same thing, and the resultant type is boolean instead of boolean | undefined.

Suggested change
const [isFirstTimeNewExpensifyUser] = useOnyx(ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER, {initialValue: false});
const [isFirstTimeNewExpensifyUser = false] = useOnyx(ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey thanks, I will keep this in mind moving forward.
This was an experiment in rewriting, so I wanted to be very 1-to-1 in regards to withOnyx -> useOnyx

const [reportMetadata] = useOnyx(ONYXKEYS.COLLECTION.REPORT_METADATA, {allowStaleData: true});
const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.accountID});

useEffect(() => {
// Don't update if there is a reportID in the params already
if (route?.params?.reportID) {
Expand Down Expand Up @@ -101,28 +88,4 @@ function ReportScreenIDSetter({route, reports, policies, navigation, isFirstTime

ReportScreenIDSetter.displayName = 'ReportScreenIDSetter';

export default withOnyx<ReportScreenIDSetterProps, ReportScreenIDSetterComponentProps>({
reports: {
key: ONYXKEYS.COLLECTION.REPORT,
allowStaleData: true,
},
policies: {
key: ONYXKEYS.COLLECTION.POLICY,
allowStaleData: true,
},
isFirstTimeNewExpensifyUser: {
key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER,
initialValue: false,
},
reportMetadata: {
key: ONYXKEYS.COLLECTION.REPORT_METADATA,
allowStaleData: true,
},
accountID: {
key: ONYXKEYS.SESSION,
selector: (session) => session?.accountID,
},
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
})(ReportScreenIDSetter);
export default ReportScreenIDSetter;
2 changes: 0 additions & 2 deletions src/setup/platformSetup/index.website.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {AppRegistry} from 'react-native';
// This is a polyfill for InternetExplorer to support the modern KeyboardEvent.key and KeyboardEvent.code instead of KeyboardEvent.keyCode
import 'shim-keyboard-event-key';
import checkForUpdates from '@libs/checkForUpdates';
import DateUtils from '@libs/DateUtils';
import Visibility from '@libs/Visibility';
Expand Down
Loading