Edit:
Thanks for this cheatsheet, nice to have it open when fighting with array states.
Mh, i learned to always get the old state like (dont focus on typos, just sketching):
const handleAdd = (todo) => {
setTodos((oldTodos) => {
return [...oldTodos, todo]
})
}
Why you dont use this?
Or is this approach only needed, if the new value depends on the old one?
would also be curious about the answer - but i think your approach is not a bad approach - just different. Why the author didnt took this into account would be inetersting ...
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Edit:
Thanks for this cheatsheet, nice to have it open when fighting with array states.
Mh, i learned to always get the old state like (dont focus on typos, just sketching):
const handleAdd = (todo) => {
setTodos((oldTodos) => {
return [...oldTodos, todo]
})
}
Why you dont use this?
Or is this approach only needed, if the new value depends on the old one?
would also be curious about the answer - but i think your approach is not a bad approach - just different. Why the author didnt took this into account would be inetersting ...