Javascript: react/no-string-refs recommendations conflict with no-return-assign

Created on 2 Aug 2016  路  3Comments  路  Source: airbnb/javascript

I've just upgraded to the latest version and one of issues the came up was with react/no-string-refs.

The docs here suggest the following:

<Foo
  ref={(ref) => this.myRef = ref}
/>

This causes a no-return-assign error. I'm not sure if it's possible but should this rule be relaxed in this case?

One way around it is wrapping the assignment in parenthesis:

<Foo
  ref={ref => (this.myRef = ref)}
/>

But that seems a bit off. Any suggestions?

Most helpful comment

You want an arrow function that doesn't have a return value - like (ref) => { this.ref = ref; }. Does that solve the issue?

All 3 comments

You want an arrow function that doesn't have a return value - like (ref) => { this.ref = ref; }. Does that solve the issue?

thanks @ljharb

thanks @ljharb

Was this page helpful?
0 / 5 - 0 ratings

Related issues

progre picture progre  路  3Comments

ar
mbifulco picture mbifulco  路  3Comments

ehrudxo picture ehrudxo  路  4Comments

tpiros picture tpiros  路  3Comments

felixsanz picture felixsanz  路  3Comments