aleksandrchusovitin/frontend-project-lvl4

View on GitHub
src/store/slices/modalSlice.js

Summary

Maintainability
A
0 mins
Test Coverage
/* eslint-disable no-param-reassign */
import { createSlice } from '@reduxjs/toolkit';

const initialState = {
  isOpened: false,
  modalType: null,
};

const modalSlice = createSlice({
  name: 'modal',
  initialState,
  reducers: {
    openModal: (state, action) => {
      state.modalType = action.payload;
      state.isOpened = true;
    },
    closeModal: (state) => {
      state.modalType = null;
      state.isOpened = false;
    },
  },
});

const { actions, reducer } = modalSlice;

export { actions };
export default reducer;