Create-react-app: Linter complains when using arrow function for refs

Created on 31 Aug 2016  路  7Comments  路  Source: facebook/create-react-app

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?

bug

Most helpful comment

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; }} />

All 7 comments

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.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Evan-GK picture Evan-GK  路  3Comments

alleroux picture alleroux  路  3Comments

jnachtigall picture jnachtigall  路  3Comments

fson picture fson  路  3Comments

barcher picture barcher  路  3Comments