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
[Docs] [Question] Refs - Callback vs String #6250
Comments
If you define ref as a string, it will be available on The string refs are eventually going to be deprecated. Callback refs were introduced later but they cover all use cases of string refs and don’t have some of their downsides. I suggest you to always use callback refs in the new code you write. In the future, please consider asking questions on StackOverflow. We don’t officially consider issue tracker to be a support forum, and unfortunately GitHub search does not work as well as StackOverflow search, so it’s likely somebody is going to ask this again. Whereas if you posted this on StackOverflow, it’s likely you’d get a good answer, your question would get voted up, and more people would have learned from it and found it in the future. |
Thank you again @gaearon. I'll use StackOverflow next time. |
No problem! Please feel free to submit a pull request to the documentation if you feel like we could make it more obvious that we recommend the callback ref pattern in the new code. |
string refs are considered legacy and the callback approach is the recommended way forward. https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md String refs will eventually go away in React core. facebook/react#4174 facebook/react#6350 facebook/react#6250 ReactCurrentOwner is the only remaining piece of shared global state in React internals. String refs are the primary reason it is still around. The benefit of adopting this now (pre-deprecation) is to be ahead of the curve when that does happen.
string refs are considered legacy and the callback approach is the recommended way forward. https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md String refs will eventually go away in React core. facebook/react#4174 facebook/react#6350 facebook/react#6250 ReactCurrentOwner is the only remaining piece of shared global state in React internals. String refs are the primary reason it is still around. The benefit of adopting this now (pre-deprecation) is to be ahead of the curve when that does happen.
string refs are considered legacy and the callback approach is the recommended way forward. https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md String refs will eventually go away in React core. facebook/react#4174 facebook/react#6350 facebook/react#6250 ReactCurrentOwner is the only remaining piece of shared global state in React internals. String refs are the primary reason it is still around. The benefit of adopting this now (pre-deprecation) is to be ahead of the curve when that does happen.
I was reading the docs again, it's not clear to me the difference between defining a ref as a callback vs string:
<input ref={input => this._input = input} />
vs<input ref="input" />
Can someone clarify to me please?
The text was updated successfully, but these errors were encountered: