diff --git a/packages/react-reconciler/src/ReactStrictModeWarnings.js b/packages/react-reconciler/src/ReactStrictModeWarnings.js index de37ab620336c..9b7b6c1dd2eb8 100644 --- a/packages/react-reconciler/src/ReactStrictModeWarnings.js +++ b/packages/react-reconciler/src/ReactStrictModeWarnings.js @@ -46,6 +46,14 @@ if (__DEV__) { const didWarnAboutDeprecatedLifecycles = new Set(); const didWarnAboutUnsafeLifecycles = new Set(); + const setToSortedString = set => { + const array = []; + set.forEach(value => { + array.push(value); + }); + return array.sort().join(', '); + }; + ReactStrictModeWarnings.discardPendingWarnings = () => { pendingComponentWillMountWarnings = []; pendingComponentWillReceivePropsWarnings = []; @@ -69,9 +77,7 @@ if (__DEV__) { const formatted = lifecycle.replace('UNSAFE_', ''); const suggestion = LIFECYCLE_SUGGESTIONS[lifecycle]; - const sortedComponentNames = Array.from(componentNames) - .sort() - .join(', '); + const sortedComponentNames = setToSortedString(componentNames); lifecyclesWarningMesages.push( `${formatted}: Please update the following components to use ` + @@ -123,9 +129,7 @@ if (__DEV__) { didWarnAboutDeprecatedLifecycles.add(fiber.type); }); - const sortedNames = Array.from(uniqueNames) - .sort() - .join(', '); + const sortedNames = setToSortedString(uniqueNames); lowPriorityWarning( false, @@ -148,9 +152,7 @@ if (__DEV__) { didWarnAboutDeprecatedLifecycles.add(fiber.type); }); - const sortedNames = Array.from(uniqueNames) - .sort() - .join(', '); + const sortedNames = setToSortedString(uniqueNames); lowPriorityWarning( false, @@ -172,9 +174,7 @@ if (__DEV__) { didWarnAboutDeprecatedLifecycles.add(fiber.type); }); - const sortedNames = Array.from(uniqueNames) - .sort() - .join(', '); + const sortedNames = setToSortedString(uniqueNames); lowPriorityWarning( false,