Skip to content

Commit

Permalink
Merge pull request #46308 from callstack-internal/memoize-formatPhone…
Browse files Browse the repository at this point in the history
…Number

memoize formatPhoneNumber method
  • Loading branch information
chiragsalian authored Jul 26, 2024
2 parents 3ff64b9 + 6af8610 commit b7dabee
Showing 1 changed file with 4 additions and 1 deletion.
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

0 comments on commit b7dabee

Please sign in to comment.