now everything works with React ToolKit
This commit is contained in:
@@ -1,19 +1,20 @@
|
||||
import { SET_ALERT, REMOVE_ALERT } from '../actions/types';
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
|
||||
const initialState = [];
|
||||
|
||||
function alertReducer(state = initialState, action) {
|
||||
const { type, payload } = action;
|
||||
const alertSlice = createSlice({
|
||||
name: "alert",
|
||||
initialState,
|
||||
reducers: {
|
||||
setAlert(state, action) {
|
||||
return [...state, action.payload];
|
||||
},
|
||||
removeAlert(state, action) {
|
||||
return state.filter((alert) => alert.id !== action.payload);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
switch (type) {
|
||||
case SET_ALERT:
|
||||
return [...state, payload];
|
||||
case REMOVE_ALERT:
|
||||
return state.filter((alert) => alert.id !== payload);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
export const { setAlert, removeAlert } = alertSlice.actions;
|
||||
|
||||
|
||||
export default alertReducer;
|
||||
export default alertSlice.reducer;
|
||||
|
||||
Reference in New Issue
Block a user