Skip to content

Commit c55c34e

Browse files
authored
Move React Map child check to behind flags or __DEV__ (#17995)
1 parent 901d76b commit c55c34e

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

packages/react/src/ReactChildren.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,18 @@ function traverseAllChildrenImpl(
159159
} else {
160160
const iteratorFn = getIteratorFn(children);
161161
if (typeof iteratorFn === 'function') {
162-
if (iteratorFn === children.entries) {
163-
if (disableMapsAsChildren) {
164-
invariant(
165-
false,
166-
'Maps are not valid as a React child (found: %s). Consider converting ' +
167-
'children to an array of keyed ReactElements instead.',
168-
children,
169-
);
170-
}
162+
if (disableMapsAsChildren) {
163+
invariant(
164+
iteratorFn !== children.entries,
165+
'Maps are not valid as a React child (found: %s). Consider converting ' +
166+
'children to an array of keyed ReactElements instead.',
167+
children,
168+
);
169+
}
170+
171+
if (__DEV__) {
171172
// Warn about using Maps as children
172-
if (__DEV__) {
173+
if (iteratorFn === children.entries) {
173174
if (!didWarnAboutMaps) {
174175
console.warn(
175176
'Using Maps as children is deprecated and will be removed in ' +

0 commit comments

Comments
 (0)