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

memoize formatPhoneNumber method #46308

Merged
Merged
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
5 changes: 4 additions & 1 deletion src/libs/LocalePhoneNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Str} from 'expensify-common';
import Onyx from 'react-native-onyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import memoize from './memoize';
import {parsePhoneNumber} from './PhoneNumber';

let countryCodeByIP: number;
Expand All @@ -14,7 +15,7 @@ Onyx.connect({
* Returns a locally converted phone number for numbers from the same region
* and an internationally converted phone number with the country code for numbers from other regions
*/
function formatPhoneNumber(number: string): string {
function formatPhoneNumberBase(number: string): string {
if (!number) {
return '';
}
Expand Down Expand Up @@ -46,6 +47,8 @@ function formatPhoneNumber(number: string): string {
return parsedPhoneNumber.number.international;
}

const formatPhoneNumber = memoize(formatPhoneNumberBase, {monitoringName: 'formatPhoneNumber'});

export {
// eslint-disable-next-line import/prefer-default-export
formatPhoneNumber,
Expand Down
Loading