diff --git a/src/renderers/shared/shared/__tests__/ReactStatelessComponent-test.js b/src/renderers/shared/shared/__tests__/ReactStatelessComponent-test.js
index 5525b7178e..caea83e35e 100644
--- a/src/renderers/shared/shared/__tests__/ReactStatelessComponent-test.js
+++ b/src/renderers/shared/shared/__tests__/ReactStatelessComponent-test.js
@@ -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 [
, ];
}
expect(function() {
ReactTestUtils.renderIntoDocument(
);
- }).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(
);
- }).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.'
);
diff --git a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js
index 1abe88d622..ecdccd0982 100644
--- a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js
+++ b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js
@@ -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 ||