Answer the question
In order to leave comments, you need to log in
How to add id to lists array in redux?
On each call, I would like to add the string id , obtained from action.payload , to the lists array.
This code creates a new lists array when called, thus overwriting the value that was already there:
const initialUserState = {
borders:[{ title: '', boardId: '1' ,lists: [] }]
}
export const boardsReducer = (state = initialUserState, action) => {
switch (action.type)
{
case 'ADD_LIST':
const {boardId, id} = action.payload
const board = state[boardId]
return {
...state,
[boardId]: { ...board, ['lists']: [id] }
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question