Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import { v1 } from "uuid";
import { notificationActionTypes } from "./notification.types";
const NotificationInitialState = {
notifications: [],
};
const notificationReducer = (
state = NotificationInitialState,
{ type, payload }
) => {
switch (type) {
case notificationActionTypes.ADD_NOTIFICATION:
const newNotification = { ...payload, id: v1() };
return {
...state,
notifications: [newNotification, ...state.notifications],
};
case notificationActionTypes.REMOVE_NOTIFICATION:
const idToFilter = payload;
return {
...state,
notifications: state.notifications.filter(
(element) => element.id !== idToFilter
),
};
default:
return state;
}
};
export default notificationReducer;