mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Mention forwardRef() in <Fn ref={...} /> errors and warnings (#14644)
This commit is contained in:
@@ -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
@@ -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
@@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
+3
-1
@@ -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 **)',
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user