Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/react-dom/src/__tests__/ReactFunctionComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' +
Expand Down Expand Up @@ -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' +
Expand Down Expand Up @@ -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 **)',
Expand Down
3 changes: 2 additions & 1 deletion packages/react-reconciler/src/ReactChildFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 **)',
);
Expand Down