24 lines
545 B
JavaScript
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;
|