import {configureStore, createSlice} from '@reduxjs/toolkit'; const initialCounterState = {counter: 0, showCounter: true}; const initialAuthState = {userName: "", isLoggedIn: false}; const counterSlice = createSlice({ name: "counter", initialState: initialCounterState, reducers: { increment(state, action) { state.counter += action.payload }, decrement(state, action) { state.counter -= action.payload }, toggle(state, action) { state.showCounter = !state.showCounter } } }) const authSlice = createSlice({ name: "auth", initialState: initialAuthState, reducers: { login(state, action) { state.userName = action.payload.userName; state.isLoggedIn = true; }, logout(state, action) { state.userName = ""; state.isLoggedIn = false; } } }); export const counterActions = counterSlice.actions; export const authActions = authSlice.actions; export const store = configureStore({ reducer: { counter: counterSlice.reducer, auth: authSlice.reducer, } });
References
https://stackoverflow.com/questions/67577835/same-action-triggering-in-multiple-slices-redux-toolkit