Reputation: 2218
I have a function like below 'SHOW_ALL' will return all values that is working correctly. 'SHOW_COMPLETED' & 'SHOW_ACTIVE' is not working as expected.
const getVisibleTodos = (todos, filter) => {
console.log("todos",todos);
switch (filter) {
case SHOW_ALL:
return todos;
case SHOW_COMPLETED:
return todos.rowData.filter(item => item.status === 'Completed');
case SHOW_ACTIVE:
return todos.rowData.filter(item => item.status === 'Active');
default:
throw new Error("Unknown filter: " + filter);
}
};
todos have value like below
const todos = {
columnDefs: [
{headerName:"Todos",field:"todos"},
{headerName:"Status",field:"status"}
],
rowData: [
{
id: 0,
todos: 'Walk the Dog',
status: 'Completed',
},
{
id:1,
todos: 'learn Redux',
status: 'Active'
}
]
}
What mistake I am doing?
Upvotes: 0
Views: 56
Reputation: 853
Return this (and for Active
of course):
{ ...todos, rowData: todos.rowData.filter(item => item.status === 'Completed')}
You forgot to return the rest of the todos
object, a columnDefs
property.
Upvotes: 2