Answer the question
In order to leave comments, you need to log in
How to update only one object in a state array?
Good afternoon.
I teach React, I consolidate my knowledge with practice - I write my own small application, ToDo List.
I wanted to implement the functionality of updating an already created item, but I absolutely can’t figure out how to do it right.
For the time being, I use a blank of the type:
const initialItems = [
{ message: 'Задача 1' , key: 1 },
{ message: 'Задача 2' , key: 2 },
{ message: 'Задача 3' , key: 3 }
]
...
{arrMessage.map(card, => (
<Card
card={card}
// сюда из компонента Card передаю данные карточки
cardTransfer={onItemClick}
key={card.key}
/>
))}
...
function onItemClick(card) {
setButton('Update');
setAreaVisible(true);
setAreaValue(card.message);
// пустота
}
Answer the question
In order to leave comments, you need to log in
Did you not understand a piece of code?
onItemHintClick = (index, e) =>
this.setState(({ items }) => ({
items: [
...items,
[index]: {
...items[index],
htogle: !items[index].htogle,
},
],
}));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question