mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Remove unnecessary warning for invalid node
We have an invariant that checks the same case right afterwards. The warning was originally added in #5884 with a distinct wording. However it was later changed to the same wording as the invariant in #6008. I don't see why we would want to have both since they're saying the same thing and with (almost) the same internal stack.
This commit is contained in:
committed by
Andrew Clark
parent
33c3121f43
commit
df0532b0c3
@@ -123,30 +123,24 @@ describe('ReactStatelessComponent', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn when stateless component returns array', () => {
|
||||
spyOn(console, 'error');
|
||||
it('should throw when stateless component returns array', () => {
|
||||
function NotAComponent() {
|
||||
return [<div />, <div />];
|
||||
}
|
||||
expect(function() {
|
||||
ReactTestUtils.renderIntoDocument(<div><NotAComponent /></div>);
|
||||
}).toThrow();
|
||||
expectDev(console.error.calls.count()).toBe(1);
|
||||
expectDev(console.error.calls.argsFor(0)[0]).toContain(
|
||||
}).toThrowError(
|
||||
'NotAComponent(...): A valid React element (or null) must be returned. ' +
|
||||
'You may have returned undefined, an array or some other invalid object.'
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn when stateless component returns undefined', () => {
|
||||
spyOn(console, 'error');
|
||||
it('should throw when stateless component returns undefined', () => {
|
||||
function NotAComponent() {
|
||||
}
|
||||
expect(function() {
|
||||
ReactTestUtils.renderIntoDocument(<div><NotAComponent /></div>);
|
||||
}).toThrow();
|
||||
expectDev(console.error.calls.count()).toBe(1);
|
||||
expectDev(console.error.calls.argsFor(0)[0]).toContain(
|
||||
}).toThrowError(
|
||||
'NotAComponent(...): A valid React element (or null) must be returned. ' +
|
||||
'You may have returned undefined, an array or some other invalid object.'
|
||||
);
|
||||
|
||||
@@ -39,26 +39,9 @@ function StatelessComponent(Component) {
|
||||
StatelessComponent.prototype.render = function() {
|
||||
var Component = ReactInstanceMap.get(this)._currentElement.type;
|
||||
var element = Component(this.props, this.context, this.updater);
|
||||
warnIfInvalidElement(Component, element);
|
||||
return element;
|
||||
};
|
||||
|
||||
function warnIfInvalidElement(Component, element) {
|
||||
if (__DEV__) {
|
||||
warning(
|
||||
element === null || element === false || React.isValidElement(element),
|
||||
'%s(...): A valid React element (or null) must be returned. You may have ' +
|
||||
'returned undefined, an array or some other invalid object.',
|
||||
Component.displayName || Component.name || 'Component'
|
||||
);
|
||||
warning(
|
||||
!Component.childContextTypes,
|
||||
'%s(...): childContextTypes cannot be defined on a functional component.',
|
||||
Component.displayName || Component.name || 'Component'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function shouldConstruct(Component) {
|
||||
return !!(Component.prototype && Component.prototype.isReactComponent);
|
||||
}
|
||||
@@ -205,7 +188,13 @@ var ReactCompositeComponent = {
|
||||
// Support functional components
|
||||
if (!doConstruct && (inst == null || inst.render == null)) {
|
||||
renderedElement = inst;
|
||||
warnIfInvalidElement(Component, renderedElement);
|
||||
if (__DEV__) {
|
||||
warning(
|
||||
!Component.childContextTypes,
|
||||
'%s(...): childContextTypes cannot be defined on a functional component.',
|
||||
Component.displayName || Component.name || 'Component'
|
||||
);
|
||||
}
|
||||
invariant(
|
||||
inst === null ||
|
||||
inst === false ||
|
||||
|
||||
Reference in New Issue
Block a user