The redux state that i want to update look like this:
const store = createStore(allReducers, {
todos: [{
id: "gpja3p5vz8vz6734p6d3is"
items: [{data: "d", stroke: 0, id: "dme30447zagz2jl6a2ipgo", todos_id: "gpja3p5vz8vz6734p6d3is"}]
},
{
id: "fasfasfdgsh"
items: [{data: "d", stroke: 0, id: "dme30447zagz2jl6a2ipgo", todos_id: "gpja3p5vz8vz6734p6d3is"}]
}]
})
I have an array with objects (action.payload).I want to push every single one of these objects to the end of the todos items array
arr[
{data: "d", stroke: 0, id: "dsa", todos_id: "gpja3p5vz8vz6734p6d3is"}
{data: "d", stroke: 0, id: "gfds", todos_id: "gpja3p5vz8vz6734p6d3is"}
{data: "d", stroke: 0, id: "gdfs", todos_id: "gpja3p5vz8vz6734p6d3is"}
]
I been trying to solve this for so many hours but I cant solve it so can someone please help me?
I have tried alot
case 'newItems':
let state = [
...rState.map(todo => {
if (todo.id === 'm8o99m6bb3n4jbms87ln') {
return [...todo.items, ['asd']]
} else return todo
})
]
return state
case 'newItems':
var todoItem = rState.map(todo => {
if (todo.id === action.payload.todos_id) {
return {
...todo,
items: action.map(item => {
return {
...item,
item
}
})
}
}
return todo
})
return todoItem
and so on