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

string refs are considered legacy #208

Open
jgkim opened this issue Aug 3, 2016 · 7 comments
Open

string refs are considered legacy #208

jgkim opened this issue Aug 3, 2016 · 7 comments
Assignees

Comments

@jgkim
Copy link

jgkim commented Aug 3, 2016

According to the official documentation, string refs will likely be deprecated in the future, and callback refs are preferred.

Although string refs are not deprecated, they are considered legacy, and will likely be deprecated at some point in the future. Callback refs are preferred.

Cf. https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md

@alvaromb
Copy link
Collaborator

alvaromb commented Aug 5, 2016

We should change how the refs are handled. Thoughts, @gcanti?

@gcanti
Copy link
Owner

gcanti commented Aug 5, 2016

Do RN log some warnings about this?

@alvaromb
Copy link
Collaborator

alvaromb commented Aug 5, 2016

There are no warnings while the app is running or in the console, but they'll be deprecated soon.

@gcanti
Copy link
Owner

gcanti commented Aug 5, 2016

"Soon" means react v16 I guess, as removing string refs is a breaking change. We can wait for an actual deprecation (+ possibly other breaking changes coming in the v16 release)

@alvaromb alvaromb self-assigned this Jan 24, 2018
@Dreyer
Copy link

Dreyer commented Mar 19, 2018

Bumping this React 16.2 is out and this might be changing in 16.3 with the introduction of React.createRef() and deprecation is apparently "scheduled" for 16.4 (source).

Legacy API: String Refs

If you worked with React before, you might be familiar with an older API where the ref attribute is a string, like "textInput", and the DOM node is accessed as this.refs.textInput. We advise against it because string refs have some issues, are considered legacy, and are likely to be removed in one of the future releases. If you’re currently using this.refs.textInput to access refs, we recommend the callback pattern instead.

https://reactjs.org/docs/refs-and-the-dom.html#legacy-api-string-refs

@JCMais
Copy link

JCMais commented Apr 10, 2018

It's already showing a warning btw

@microxoft
Copy link

Hello, this warning is constantly showing in all these components. I don't know when will it be definitely deprecated, but it kind of bothers to see these warnings poping up.

Would you please consider uppering this issue's priority?

Here is the warning message:

Warning: Component "DatePicker" contains the string ref "input". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://fb.me/react-strict-mode-string-ref

Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants