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:
Josh Duck
2014-01-30 16:54:01 -08:00
committed by Paul O’Shannessy
parent 4cbc4b58f6
commit 5d7563f706
+3 -1
View File
@@ -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)) {