Allow null and undefined values in non-frag object passed to PropTypes.node
Paul O’Shannessy committed
Mar 5, 2015 at 15:14 UTC
0e797dffe4ef4ffe83df51283b2f3886c1bd2125
2 files changed
+8
-3
src/classic/types/ReactPropTypes.js
+2
-1
@@ -292,6 +292,7 @@ function isNode(propValue) {
292
switch (typeof propValue) {
293
case 'number':
294
case 'string':
295
+ case 'undefined':
296
return true;
297
case 'boolean':
298
return !propValue;
@@ -299,7 +300,7 @@ function isNode(propValue) {
300
if (Array.isArray(propValue)) {
301
return propValue.every(isNode);
302
}
302
- if (ReactElement.isValidElement(propValue)) {
303
+ if (propValue === null || ReactElement.isValidElement(propValue)) {
304
return true;
305
}
306
propValue = ReactFragment.extractIfFragment(propValue);
src/classic/types/__tests__/ReactPropTypes-test.js
+6
-2
@@ -384,7 +384,9 @@ describe('ReactPropTypes', function() {
384
k30: <MyComponent />,
385
k31: frag({k310: <a />}),
386
k32: 'Another string'
387
- })
387
+ }),
388
+ k4: null,
389
+ k5: undefined
390
}));
391
expect(console.warn.calls).toEqual([]);
392
@@ -397,7 +399,9 @@ describe('ReactPropTypes', function() {
399
k30: <MyComponent />,
400
k31: {k310: <a />},
401
k32: 'Another string'
400
- }
402
+ },
403
+ k4: null,
404
+ k5: undefined
405
});
406
});
407