How do I write a redux reducer?

How do I write a reducer? That would be possible to add and remove boards, lists, todos
const initialState = {
 'Actions': {
 id: 'Business',
 title: 'Cases',
 lists: [
{
 id: 'Businesses/Tests',
 title: 'Tests',
 todos: [
{
 id: 'Businesses/Tests/Open',
 title: 'Open',
 activ: true
}
]
}
]
}
};
March 23rd 20 at 19:45
1 answer
March 23rd 20 at 19:47
Not clear task.
do 3 reducer for each entity, here's an example for one.

const initialState = [{
 id: 1,
 name: "test1"
},

{
 id: 2,
 name: "ั‚ะตัั‚2"
}
]

function boardReducer(state = initialState, action) {
 switch (action.type) {
 case 'ADD_BOARD':
 return [state..., {
 id: Math.random(),
 name: action.payload
}]
 case 'EDIT_BOARD':
 return state.map((item) => item.id === action.payload.id ? { ...item.action.payload.name
 } : item)
 case 'DELETE_BOARD':
 return state.filter((item) => item.id !== action.payload)

default:
 return state
}
}

Find more questions by tags Redux