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?
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; }} />
Oh yep, that was the problem. Thanks for the clarification.
I鈥檓 actually not sure we should keep this rule.
Callback refs are verbose enough by themselves, and this makes them worse.
@mrscobbler Would you like to send a PR to remove this rule? It should be in config/eslint.js
. I don鈥檛 think it鈥檚 valuable enough to justify the confusion. If ESLint revisits https://github.com/eslint/eslint/issues/5150#issuecomment-182544061 we can add it back with that option.
Yes, sure I'll take care of it.
Just submitted a pull request: https://github.com/facebookincubator/create-react-app/pull/529
Fixed via #529, will be out in the next version.
Thanks!
Most helpful comment
You are probably writing
if you add
{}
around the function body it should remove the warning: