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

Change string refs in function component message #18031

Merged
merged 1 commit into from
Feb 21, 2020

Conversation

sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented Feb 13, 2020

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. This case is when a string ref is used from a function component, not on a function component.

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.
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Feb 13, 2020
@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit dbadcd6:

Sandbox Source
mystifying-cloud-og6mg Configuration

@sizebot
Copy link

sizebot commented Feb 13, 2020

No significant bundle size changes to report.

Size changes (experimental)

Generated by 🚫 dangerJS against dbadcd6

@sizebot
Copy link

sizebot commented Feb 13, 2020

No significant bundle size changes to report.

Size changes (stable)

Generated by 🚫 dangerJS against dbadcd6

@devknoll
Copy link
Contributor

devknoll commented Feb 13, 2020

Wait, don't you still need to wrap a function component with forwardRef on a function component in order to pass it a ref?

Edit: nvm, seems like that's just a different error altogether.

@@ -307,7 +307,7 @@
"306": "Element type is invalid. Received a promise that resolves to: %s. Lazy element type must resolve to a class or function.%s",
"307": "Hooks can only be called inside the body of a function component. (https://fb.me/react-invalid-hook-call)",
"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().",
"309": "Function components cannot have refs. Did you mean to use React.forwardRef()?",
"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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update this doc to mention useRef?

Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems legit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants