diff --git a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js index 9536502084..6ee4e2aac7 100644 --- a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js +++ b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js @@ -1097,7 +1097,9 @@ var ReactCompositeComponentMixin = { if (__DEV__) { var componentName = component && component.getName ? component.getName() : 'a component'; - warning(publicComponentInstance != null, + warning( + publicComponentInstance != null || + component._compositeType !== CompositeTypes.StatelessFunctional, 'Stateless function components cannot be given refs ' + '(See ref "%s" in %s created by %s). ' + 'Attempts to access this ref will fail.', diff --git a/src/renderers/testing/__tests__/ReactTestRenderer-test.js b/src/renderers/testing/__tests__/ReactTestRenderer-test.js index e562867fd2..95f7f9f4d9 100644 --- a/src/renderers/testing/__tests__/ReactTestRenderer-test.js +++ b/src/renderers/testing/__tests__/ReactTestRenderer-test.js @@ -206,6 +206,31 @@ describe('ReactTestRenderer', function() { expect(log).toEqual([null]); }); + it('warns correctly for refs on SFCs', function() { + spyOn(console, 'error'); + function Bar() { + return