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

Rule react/destructruring-assignement in a constructor #1728

Closed
mathieug opened this issue Mar 16, 2018 · 6 comments
Closed

Rule react/destructruring-assignement in a constructor #1728

mathieug opened this issue Mar 16, 2018 · 6 comments

Comments

@mathieug
Copy link

The rule react/destructruring-assignement should not throw in a component constructor.

image

@ljharb
Copy link
Member

ljharb commented Mar 16, 2018

I’m confused why you’d mutate the object after assigning it (it’s much slower and messier), but yes, this is a bug - specifically, it shouldn’t warn on LHS member chains off of state or props, only RHS.

@mathieug
Copy link
Author

I need to condition which attribute I set in the state.

@leohxj
Copy link

leohxj commented Mar 19, 2018

image

same as.

@ljharb
Copy link
Member

ljharb commented Mar 19, 2018

@leohxj in that case, it’s correct. Do const { name } = this.props; before the state assignment, and do both in the constructor (iow, don’t do things in class property initializers that depend on props or state)

@leohxj
Copy link

leohxj commented Mar 19, 2018

@ljharb

ok, but why "don’t do things in class property initializers that depend on props or state" ?
I think Class properties transform can do this.

@ljharb
Copy link
Member

ljharb commented Mar 20, 2018

@leohxj of course it will work; the reason not to do it is because it makes things much less clear when reading the code.

alexzherdev added a commit to alexzherdev/eslint-plugin-react that referenced this issue Jun 14, 2018
calebeby pushed a commit to Pigmice2733/scouting-frontend that referenced this issue Jun 30, 2018
This Pull Request updates dependency [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react) from `v7.9.1` to `v7.10.0`



<details>
<summary>Release Notes</summary>

### [`v7.10.0`](https://github.com/yannickcr/eslint-plugin-react/blob/master/CHANGELOG.md#&#8203;7100---2018-06-24)
[Compare Source](jsx-eslint/eslint-plugin-react@v7.9.1...v7.10.0)
##### Added
* Allow eslint ^5 ([#&#8203;1843][] @&#8203;papandreou, @&#8203;ljharb)
* [`no-unsafe`][] rule ([#&#8203;1831][], [#&#8203;1830][] @&#8203;sergei-startsev)
* [`no-will-update-set-state`][]: Account for `UNSAFE_` methods ([#&#8203;1845][], [#&#8203;1844][] @&#8203;alexzherdev)
##### Fixed
* [`no-typos`][]: Fix static propTypes handling ([#&#8203;1827][], [#&#8203;1677][] @&#8203;alexzherdev)
* [`destructuring-assignment`][]: Allow LHS ([#&#8203;1825][], [#&#8203;1728][] @&#8203;alexzherdev)
* [`no-unused-prop-types`][]: Fix crash when encountering mixed union and intersection flow types ([#&#8203;1806][] @&#8203;yannickcr)
##### Changed
* Typo fixes in [`jsx-no-target-blank`][] ([#&#8203;1805][] @&#8203;ferhatelmas))

[#&#8203;1845]: `jsx-eslint/eslint-plugin-react#1845
[#&#8203;1844]: `jsx-eslint/eslint-plugin-react#1844
[#&#8203;1843]: `jsx-eslint/eslint-plugin-react#1843
[#&#8203;1831]: `jsx-eslint/eslint-plugin-react#1831
[#&#8203;1830]: `jsx-eslint/eslint-plugin-react#1830
[#&#8203;1827]: `jsx-eslint/eslint-plugin-react#1827
[#&#8203;1825]: `jsx-eslint/eslint-plugin-react#1825
[#&#8203;1806]: `jsx-eslint/eslint-plugin-react#1806
[#&#8203;1805]: `jsx-eslint/eslint-plugin-react#1805
[#&#8203;1728]: `jsx-eslint/eslint-plugin-react#1728
[#&#8203;1677]: `jsx-eslint/eslint-plugin-react#1677

---

</details>




---

This PR has been generated by [Renovate Bot](https://renovatebot.com).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants