Files
leporello-js/docs/examples/todos-redux/src/reducers/todos.js

21 lines
417 B
JavaScript
Raw Normal View History

2023-06-15 18:16:56 +03:00
const todos = (state = [], action) => {
if (action.type == "ADD_TODO") {
2023-06-16 00:22:31 +03:00
return [
...state,
{
id: action.id,
text: action.text,
completed: false,
},
2023-06-16 00:22:31 +03:00
]
} else if (action.type == "TOGGLE_TODO") {
2023-06-16 00:22:31 +03:00
return state.map(todo =>
todo.id === action.id ? { ...todo, completed: !todo.completed } : todo,
2023-06-16 00:22:31 +03:00
)
} else {
return state
2023-06-15 18:16:56 +03:00
}
}
export default todos