File size: 591 Bytes
a0fda44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { createSlice } from "@reduxjs/toolkit";

const initialState = [];

const notificationSlice = createSlice({
  name: "notification",
  initialState,
  reducers: {
    addNotification: (state, { payload }) => {
      const id = Date.now();
      state.push({
        ...payload,
        id,
      });
    },
    removeNotification: (state, { payload: id }) => {
      return state.filter((notif) => notif.id !== id);
    },
    clearAllNotifications: () => initialState,
  },
});

export const notificationActions = notificationSlice.actions;

export default notificationSlice.reducer;