@samitouri / QOS-React-2 / commits / 5d7563f706

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

Josh Duck committed Jan 30, 2014 at 14:51 UTC 5d7563f7060df9f9983e69efcece473991a92147
1 file changed +3 -1
src/core/ReactComponent.js
+3 -1
@@ -51,6 +51,8 @@ var ComponentLifeCycle = keyMirror({
51 var ownerHasExplicitKeyWarning = {};
52 var ownerHasPropertyWarning = {};
53
54 +var NUMERIC_PROPERTY_REGEX = /^\d+$/;
55 +
56 /**
57 * Warn if the component doesn't have an explicit key assigned to it.
58 * This component is in an array. The array could grow and shrink or be
@@ -105,7 +107,7 @@ function validateExplicitKey(component) {
107 * @param {ReactComponent} component Component that requires a key.
108 */
109 function validatePropertyKey(name) {
108 - if (!isNaN(Number(name))) {
110 + if (NUMERIC_PROPERTY_REGEX.test(name)) {
111 // Name of the component whose render method tried to pass children.
112 var currentName = ReactCurrentOwner.current.constructor.displayName;
113 if (ownerHasPropertyWarning.hasOwnProperty(currentName)) {