From 5d7563f7060df9f9983e69efcece473991a92147 Mon Sep 17 00:00:00 2001 From: Josh Duck Date: Thu, 30 Jan 2014 14:51:51 -0800 Subject: [PATCH] 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 --- src/core/ReactComponent.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/ReactComponent.js b/src/core/ReactComponent.js index b9775231a9..c3e6df3d7c 100644 --- a/src/core/ReactComponent.js +++ b/src/core/ReactComponent.js @@ -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)) {