Complex Objects Mutation

PHOTO EMBED

Tue Dec 26 2023 23:54:54 GMT+0000 (Coordinated Universal Time)

Saved by @Marcelluki

const [array, setArray] = React.useState(['One', 'Two', 'Three']);

// this is not the correct way!
array.push('Four');
setArray(array); 

// this is the right way
setArray([...array, 'Four']);
content_copyCOPY

https://tripleten.com/trainer/web/lesson/5adbf722-17fb-4637-89b0-6a8f144d3de9/task/9d9d6270-839b-42c9-9dce-dfe4eb4b808a/