mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Fix warning for numeric properties
Number('.1') === 0.1, and react uses dot-prefixed keys
for children. Whoops. Nuke the non-numeric requirement, and just
check a regex. This seems performant enough in micro-benchmarks:
http://jsperf.com/numericlike
This commit is contained in:
committed by
Paul O’Shannessy
parent
4cbc4b58f6
commit
5d7563f706
@@ -51,6 +51,8 @@ var ComponentLifeCycle = keyMirror({
|
||||
var ownerHasExplicitKeyWarning = {};
|
||||
var ownerHasPropertyWarning = {};
|
||||
|
||||
var NUMERIC_PROPERTY_REGEX = /^\d+$/;
|
||||
|
||||
/**
|
||||
* Warn if the component doesn't have an explicit key assigned to it.
|
||||
* This component is in an array. The array could grow and shrink or be
|
||||
@@ -105,7 +107,7 @@ function validateExplicitKey(component) {
|
||||
* @param {ReactComponent} component Component that requires a key.
|
||||
*/
|
||||
function validatePropertyKey(name) {
|
||||
if (!isNaN(Number(name))) {
|
||||
if (NUMERIC_PROPERTY_REGEX.test(name)) {
|
||||
// Name of the component whose render method tried to pass children.
|
||||
var currentName = ReactCurrentOwner.current.constructor.displayName;
|
||||
if (ownerHasPropertyWarning.hasOwnProperty(currentName)) {
|
||||
|
||||
Reference in New Issue
Block a user