Skip to main content
Version: v2.3

How to load your own state slice

When loading your own state slice into ipa-core, the slice file must be added into the following location: packages/ipa-core/src/redux/slices

We will use an example of the Modal slice to illustrate how to configure a state slice in Redux.

This file was added into packages/ipa-core/src/redux/slices

import { createSlice } from "@reduxjs/toolkit";
const initialState = {    component: undefined,    props: undefined,    open: false,}
const slice = createSlice({    name: 'modal',    initialState,    reducers: {        setModal: (state, {payload: {component, props, open}}) => {            state.component = component            state.props = props            if(_.isBoolean(open)) {                state.open = open            }        },        setOpen: (state, {payload}) => {            state.open = payload;        },        destroy: (state) => {            state.component = initialState.component;            state.props = initialState.props;            state.open = initialState.open;        },    }})
export default slice.reducer;
export const actions = slice.actions;

We then must add this to our main.js file located at:packages/ipa-core/src/redux

import * as modal from './slices/modal'
const redux = {   ...    Modals: {        ...modal.actions    }}
export default redux

We also add to add it to our frameworkReducers object in store.js located at: packages/ipa-core/src/redux

import modal from './slices/modal'
const frameworkReducers = {    ...    modal}