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

Linter complains when using arrow function for refs #528

Closed
mrscobbler opened this issue Aug 31, 2016 · 7 comments
Closed

Linter complains when using arrow function for refs #528

mrscobbler opened this issue Aug 31, 2016 · 7 comments
Milestone

Comments

@mrscobbler
Copy link
Contributor

I'm using arrow function for refs as explained in the docs here: https://facebook.github.io/react/docs/more-about-refs.html

but the linter complains with this:

217:54 warning Arrow function should not return assignment

Is there an issue with the way the docs describe how to use arrow functions with refs? Should the docs be updated?

@vjeux
Copy link
Contributor

vjeux commented Aug 31, 2016

You are probably writing

<TextInput ref={(c) => this._input = c} />

if you add {} around the function body it should remove the warning:

<TextInput ref={(c) => { this._input = c; }} />

@mrscobbler
Copy link
Contributor Author

Oh yep, that was the problem. Thanks for the clarification.

@gaearon
Copy link
Contributor

gaearon commented Aug 31, 2016

I’m actually not sure we should keep this rule.
Callback refs are verbose enough by themselves, and this makes them worse.

@gaearon
Copy link
Contributor

gaearon commented Aug 31, 2016

@mrscobbler Would you like to send a PR to remove this rule? It should be in config/eslint.js. I don’t think it’s valuable enough to justify the confusion. If ESLint revisits eslint/eslint#5150 (comment) we can add it back with that option.

@gaearon gaearon added this to the 0.3.0 milestone Aug 31, 2016
@mrscobbler
Copy link
Contributor Author

Yes, sure I'll take care of it.

mrscobbler added a commit to mrscobbler/create-react-app that referenced this issue Aug 31, 2016
@mrscobbler
Copy link
Contributor Author

Just submitted a pull request: #529

@gaearon
Copy link
Contributor

gaearon commented Aug 31, 2016

Fixed via #529, will be out in the next version.
Thanks!

@gaearon gaearon closed this as completed Aug 31, 2016
stayradiated pushed a commit to stayradiated/create-react-app that referenced this issue Sep 7, 2016
feiqitian pushed a commit to feiqitian/create-react-app that referenced this issue Oct 25, 2016
@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants