You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
884 B

// favoritesReducer.js
import { ADD_TO_FAVORITES, FETCH_FAVORITE, REMOVE_FROM_FAVORITES, SET_FAVORITES } from "../constants";
const initialState = {
favorites: [],
};
const FavoritesReducer = (state = initialState, action) => {
switch (action.type) {
case ADD_TO_FAVORITES:
return {
...state,
favorites: [...state.favorites, action.payload],
};
case FETCH_FAVORITE:
return {
...state,
favorites: [...state.favorites],
};
case REMOVE_FROM_FAVORITES:
return {
...state,
favorites: state.favorites.filter(item => item.id !== action.payload),
};
case SET_FAVORITES:
return {
...state,
favorites: action.payload,
};
default:
return state;
}
};
export default FavoritesReducer;