@samitouri / QOS-React / commits / 2c4221ce8b

Change string refs in function component message (#18031)

This should refer to string refs specifically. The forwardRef part doesn't make any sense in this case. I think this was just an oversight.

Sebastian Markbåge committed Feb 21, 2020 at 10:12 UTC 2c4221ce8bc5765bfddc4b32af4af602077a4a3e
3 files changed +6 -4
packages/react-dom/src/__tests__/ReactFunctionComponent-test.js
+1 -1
@@ -159,7 +159,7 @@ describe('ReactFunctionComponent', () => {
159 ReactTestUtils.renderIntoDocument(<Child test="test" />);
160 }).toThrowError(
161 __DEV__
162 - ? 'Function components cannot have refs.'
162 + ? 'Function components cannot have string refs. We recommend using useRef() instead.'
163 : // It happens because we don't save _owner in production for
164 // function components.
165 'Element ref was specified as a string (me) but no owner was set. This could happen for one of' +
packages/react-reconciler/src/ReactChildFiber.js
+4 -2
@@ -163,8 +163,10 @@ function coerceRef(
163 const ownerFiber = ((owner: any): Fiber);
164 invariant(
165 ownerFiber.tag === ClassComponent,
166 - 'Function components cannot have refs. ' +
167 - 'Did you mean to use React.forwardRef()?',
166 + 'Function components cannot have string refs. ' +
167 + 'We recommend using useRef() instead. ' +
168 + 'Learn more about using refs safely here: ' +
169 + 'https://fb.me/react-strict-mode-string-ref',
170 );
171 inst = ownerFiber.stateNode;
172 }
scripts/error-codes/codes.json
+1 -1
@@ -307,7 +307,7 @@
307 "306": "Element type is invalid. Received a promise that resolves to: %s. Lazy element type must resolve to a class or function.%s",
308 "307": "Hooks can only be called inside the body of a function component. (https://fb.me/react-invalid-hook-call)",
309 "308": "Context can only be read while React is rendering. In classes, you can read it in the render method or getDerivedStateFromProps. In function components, you can read it directly in the function body, but not inside Hooks like useReducer() or useMemo().",
310 - "309": "Function components cannot have refs. Did you mean to use React.forwardRef()?",
310 + "309": "Function components cannot have string refs. We recommend using useRef() instead. Learn more about using refs safely here: https://fb.me/react-strict-mode-string-ref",
311 "310": "Rendered more hooks than during the previous render.",
312 "311": "Should have a queue. This is likely a bug in React. Please file an issue.",
313 "312": "Rendered more hooks than during the previous render",