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

Allow nested destructuring with react/hook-use-state #3443

Closed
philer-jambit opened this issue Sep 27, 2022 · 1 comment · Fixed by #3449
Closed

Allow nested destructuring with react/hook-use-state #3443

philer-jambit opened this issue Sep 27, 2022 · 1 comment · Fixed by #3449

Comments

@philer-jambit
Copy link

philer-jambit commented Sep 27, 2022

State is not always flat and sometimes it can make sense to destructure it directly. Example:

const [{foo, bar, baz}, setFooBarBaz] = useState({foo: "omg", bar: "wtf", baz: "bbq"})
const [[index, value], setValueWithIndex] = useState([0, "hello"])

Note that in these cases the setter name can not be symmetrical to the destructured variables.

It would be nice if react/hook-use-state permitted this use case (maybe optional?).

Either way, thanks for the great work! 👍

@ljharb
Copy link
Member

ljharb commented Sep 27, 2022

That definitely seems like a reasonable option to add ("allowDestructuredState"?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants