Slide 15
Slide 15 text
const todosReducer = (
state = {loading: false, todos: [], error: null},
action
) => {
switch (action.type) {
case 'FETCH_TODOS_INIT': {
return { ...state, loading: true};
}
case 'FETCH_TODOS_SUCCESS': {
return { ...state, loading: false, todos: action.todos};
}
case 'FETCH_TODOS_FAIL': {
return { ...state, loading: false, error: action.error};
}
}
};
Redux - reducer