Mention forwardRef() in <Fn ref={...} /> errors and warnings (#14644)

This commit is contained in:
Dan Abramov
2019-01-21 16:01:48 +00:00
committed by GitHub
parent a1414e8949
commit baa6d40fc8
5 changed files with 19 additions and 7 deletions
@@ -192,7 +192,9 @@ describe('ReactFunctionComponent', () => {
ReactTestUtils.renderIntoDocument(<ParentUsingStringRef />),
).toWarnDev(
'Warning: Function components cannot be given refs. ' +
'Attempts to access this ref will fail.\n\nCheck the render method ' +
'Attempts to access this ref will fail. ' +
'Did you mean to use React.forwardRef()?\n\n' +
'Check the render method ' +
'of `ParentUsingStringRef`.\n' +
' in FunctionComponent (at **)\n' +
' in div (at **)\n' +
@@ -228,7 +230,9 @@ describe('ReactFunctionComponent', () => {
ReactTestUtils.renderIntoDocument(<ParentUsingFunctionRef />),
).toWarnDev(
'Warning: Function components cannot be given refs. ' +
'Attempts to access this ref will fail.\n\nCheck the render method ' +
'Attempts to access this ref will fail. ' +
'Did you mean to use React.forwardRef()?\n\n' +
'Check the render method ' +
'of `ParentUsingFunctionRef`.\n' +
' in FunctionComponent (at **)\n' +
' in div (at **)\n' +
@@ -332,7 +336,9 @@ describe('ReactFunctionComponent', () => {
expect(() => ReactTestUtils.renderIntoDocument(<Parent />)).toWarnDev(
'Warning: Function components cannot be given refs. ' +
'Attempts to access this ref will fail.\n\nCheck the render method ' +
'Attempts to access this ref will fail. ' +
'Did you mean to use React.forwardRef()?\n\n' +
'Check the render method ' +
'of `Parent`.\n' +
' in Child (at **)\n' +
' in Parent (at **)',
+2 -1
View File
@@ -138,7 +138,8 @@ function coerceRef(
const ownerFiber = ((owner: any): Fiber);
invariant(
ownerFiber.tag === ClassComponent,
'Function components cannot have refs.',
'Function components cannot have refs. ' +
'Did you mean to use React.forwardRef()?',
);
inst = ownerFiber.stateNode;
}
+2 -1
View File
@@ -1293,7 +1293,8 @@ function validateFunctionComponentInDev(workInProgress: Fiber, Component: any) {
warning(
false,
'Function components cannot be given refs. ' +
'Attempts to access this ref will fail.%s',
'Attempts to access this ref will fail. ' +
'Did you mean to use React.forwardRef()?%s',
info,
);
}
@@ -1202,7 +1202,9 @@ describe('ReactIncrementalSideEffects', () => {
ReactNoop.render(<Foo show={true} />);
expect(ReactNoop.flush).toWarnDev(
'Warning: Function components cannot be given refs. ' +
'Attempts to access this ref will fail.\n\nCheck the render method ' +
'Attempts to access this ref will fail. ' +
'Did you mean to use React.forwardRef()?\n\n' +
'Check the render method ' +
'of `Foo`.\n' +
' in FunctionComponent (at **)\n' +
' in div (at **)\n' +
@@ -282,7 +282,9 @@ describe('ReactTestRenderer', () => {
ReactTestRenderer.create(<Baz />);
expect(() => ReactTestRenderer.create(<Foo />)).toWarnDev(
'Warning: Function components cannot be given refs. Attempts ' +
'to access this ref will fail.\n\nCheck the render method of `Foo`.\n' +
'to access this ref will fail. ' +
'Did you mean to use React.forwardRef()?\n\n' +
'Check the render method of `Foo`.\n' +
' in Bar (at **)\n' +
' in Foo (at **)',
);