Answer the question
In order to leave comments, you need to log in
Doesn't push into an array?
The user has:
boards: [
0: {title: "trello-clone", background: "rgb(205 90 145)", cards: [{title: "3"}]}
]
cards
- this is an array in boards, I need to push there, but the array is simply updated. const user = JSON.parse(localStorage.getItem('user'));
const [card, setCard] = React.useState(user.boards.map(item => item.cards));
function createCard() {
user.boards.map(item => {
item.cards = [];
})
user.boards.map(item => {
item.cards.push({title: titleCard});
})
setTitleCard('');
localStorage.setItem('user', JSON.stringify(user));
setCard(user.boards.map(item => item.cards));
}
Answer the question
In order to leave comments, you need to log in
Maybe something like this?
function createCard() {
const item.cards = [];
user.boards.map(item => {
item.cards.push({title: titleCard});
})
setTitleCard('');
localStorage.setItem('user', JSON.stringify(user));
setCard(user.boards.map(item => item.cards));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question