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

[Hooks] [Docs] Warn against mutating state in useState #1646

Closed
sudhirj opened this issue Feb 7, 2019 · 0 comments
Closed

[Hooks] [Docs] Warn against mutating state in useState #1646

sudhirj opened this issue Feb 7, 2019 · 0 comments

Comments

@sudhirj
Copy link

sudhirj commented Feb 7, 2019

Given this change facebook/react#14752 mutating state (arrays or objects) no longer works at all. New objects must be constructed every time with Object.assign, or if arrays are used they must be cloned, mutated and returned.

Examples of doing that with both objects and arrays would be helpful, especially with the form that takes a function:

const [list, setList] = useState([])
setList((l) => {
  l.push(1)
  return l
}

https://twitter.com/sudhirj/status/1093586382713348096

@sudhirj sudhirj closed this as completed Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant