Files
helsinki/Pt6bAnecdotes/src/reducers/notificationReducer.js
T
2023-08-08 16:02:54 +03:00

24 lines
545 B
JavaScript

import { createSlice } from "@reduxjs/toolkit";
const notificationSlice = createSlice({
name: "notification",
initialState: [],
reducers: {
make(state, action, time) {
state.push(action.payload);
},
remove(state, action) {
state.pop();
},
},
});
const { make, remove} = notificationSlice.actions;
export const setNotification = (message,time) => {
return (dispatch) => {
dispatch(make(message));
setTimeout(() => dispatch(remove()), time * 1000);
};
};
export default notificationSlice.reducer;