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

23 lines
428 B
JavaScript
Raw Normal View History

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