Skip to content

Commit 5d7563f

Browse files
joshduckzpao
authored andcommitted
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
1 parent 4cbc4b5 commit 5d7563f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/core/ReactComponent.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ var ComponentLifeCycle = keyMirror({
5151
var ownerHasExplicitKeyWarning = {};
5252
var ownerHasPropertyWarning = {};
5353

54+
var NUMERIC_PROPERTY_REGEX = /^\d+$/;
55+
5456
/**
5557
* Warn if the component doesn't have an explicit key assigned to it.
5658
* This component is in an array. The array could grow and shrink or be
@@ -105,7 +107,7 @@ function validateExplicitKey(component) {
105107
* @param {ReactComponent} component Component that requires a key.
106108
*/
107109
function validatePropertyKey(name) {
108-
if (!isNaN(Number(name))) {
110+
if (NUMERIC_PROPERTY_REGEX.test(name)) {
109111
// Name of the component whose render method tried to pass children.
110112
var currentName = ReactCurrentOwner.current.constructor.displayName;
111113
if (ownerHasPropertyWarning.hasOwnProperty(currentName)) {

0 commit comments

Comments
 (0)