Store Configuration:
Assuming this is how your store is configured using reduxjs/toolkit:
const store = configureStore({
reducer: rootReducer,
middleware: [
...getDefaultMiddleware(),
],
})
export default store
where the rootReducer is:
const rootReducer = combineReducers({
agent: agentReducer,
customer: customerReducer
});
And where customerReducer is nested, i.e. combination of two other reducers:
const customerReducer = combineReducer({
profile,
account
})
Answer:
To reset only customer state in your Redux Store, you need to create a wrapper reducer which will simply delegate the action to your customerReducer and whenever this wrapper reducer receives a CUSTOMER/RESET type of action, it resets the customer state:
const customerReducerWrapper = (state, action) => {
if (action.type === 'CUSTOMER/RESET') {
state = undefined
}
return customerReducer(state, action)
}
const rootReducer = combineReducers({
agent: agentReducer,
customer: customerReducerWrapper
});
See: How to reset redux state?