Skip to content

Instantly share code, notes, and snippets.

@Rajatgms
Created August 3, 2020 14:54
Show Gist options
  • Save Rajatgms/8cfad2081f292a896cee7d42b3411a90 to your computer and use it in GitHub Desktop.
Save Rajatgms/8cfad2081f292a896cee7d42b3411a90 to your computer and use it in GitHub Desktop.
createSlice
import { createSlice } from '@reduxjs/toolkit';
const initialAlert = {
variant: '',
message: '',
};
const notifySlice = createSlice({
name: 'notify',
initialState: initialAlert,
reducers: {
success: (state, action) => (
{ variant: 'success', message: action.payload }
),
error: (state, action) => (
{ variant: 'danger', message: action.payload }
),
reset: () => initialAlert,
},
});
const {actions, reducer} = notifySlice;
export const {success, error, reset} = actions;
export default reducer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment