mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Warn if using Maps as children
We're not sure if this is the way we want to support this API. It creates two ways of doing things. It is convenient to avoid needing to explicitly redefine the key of Maps. However, this use case isn't as common as having an iterable where the key is on the value, not the key.
This commit is contained in:
@@ -396,6 +396,8 @@ describe('traverseAllChildren', function() {
|
||||
});
|
||||
|
||||
it('should use keys from entry iterables', function() {
|
||||
spyOn(console, 'warn');
|
||||
|
||||
var threeDivEntryIterable = {
|
||||
'@@iterator': function() {
|
||||
var i = 0;
|
||||
@@ -445,6 +447,13 @@ describe('traverseAllChildren', function() {
|
||||
'.$#3:0',
|
||||
2
|
||||
);
|
||||
|
||||
expect(console.warn.argsForCall.length).toBe(1);
|
||||
expect(console.warn.argsForCall[0][0]).toContain(
|
||||
'Warning: Using Maps as children is not yet fully supported. It is an ' +
|
||||
'experimental feature that might be removed. Convert it to a sequence ' +
|
||||
'/ iterable of keyed ReactElements instead.'
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -17,6 +17,7 @@ var ReactInstanceHandles = require('ReactInstanceHandles');
|
||||
|
||||
var getIteratorFn = require('getIteratorFn');
|
||||
var invariant = require('invariant');
|
||||
var warning = require('warning');
|
||||
|
||||
var SEPARATOR = ReactInstanceHandles.SEPARATOR;
|
||||
var SUBSEPARATOR = ':';
|
||||
@@ -34,6 +35,8 @@ var userProvidedKeyEscaperLookup = {
|
||||
|
||||
var userProvidedKeyEscapeRegex = /[=.:]/g;
|
||||
|
||||
var didWarnAboutMaps = false;
|
||||
|
||||
function userProvidedKeyEscaper(match) {
|
||||
return userProvidedKeyEscaperLookup[match];
|
||||
}
|
||||
@@ -158,6 +161,15 @@ function traverseAllChildrenImpl(
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (__DEV__) {
|
||||
warning(
|
||||
didWarnAboutMaps,
|
||||
'Using Maps as children is not yet fully supported. It is an ' +
|
||||
'experimental feature that might be removed. Convert it to a ' +
|
||||
'sequence / iterable of keyed ReactElements instead.'
|
||||
);
|
||||
didWarnAboutMaps = true;
|
||||
}
|
||||
// Iterator will provide entry [k,v] tuples rather than values.
|
||||
while (!(step = iterator.next()).done) {
|
||||
var entry = step.value;
|
||||
|
||||
Reference in New Issue
Block a user