Allohga taqvo qiling. Va Alloh sizga ilm beradi. [2:282]
Software engineer @ OctaneJS Core Team
Dasturchi, jiddiy, kamgap, oddiy inson
Òzim haqimda kòproq ma'lumot uchun: @Diyorbek_juraev_blog
Web sahifam: https://mrdiyorbek.uz/
Post #747
94
Diyorbek.dev | 👨🏻💻 #Common_Beginner_Mistakes_with_React Question number: 2 Who can find the bug here? 😉 @Diyorbekk_dev


Answer
React relies on an state variable's identity to tell when the state has changed. When we push an item into an array, we aren't changing that array's identity, and so React can't tell that the value has changed.
How to fix it: We need to create a brand new array. Here's solution
@Diyorbekk_dev
React relies on an state variable's identity to tell when the state has changed. When we push an item into an array, we aren't changing that array's identity, and so React can't tell that the value has changed.
How to fix it: We need to create a brand new array. Here's solution
function handleAddItem(value) {
const nextItems = [...items, value];
setItems(nextItems);
}@Diyorbekk_dev










