I am trying to reset my entire redux store using redux-persist persistor.purge(). It seems resetState is not being called as no alert. what is happening? or how to achieve the logout?
resetSlice.js
import { createSlice } from '@reduxjs/toolkit';
import { persistor } from 'app/store';
const resetSlice = createSlice({
name: 'reset',
initialState: null,
reducers: {
resetState: (state) => {
alert('purging...');
persistor.purge();
return null; // Ensure you return a new state to reset the entire Redux state
}
},
});
export const { resetState } = resetSlice.actions;
export default resetSlice.reducer;
reducer.js
import ...
const appReducer = combineReducers({
auth,
...
})
const rootReducer = (state, action) => {
if (action.type === 'resetState') {
return appReducer(undefined, action);
}
return appReducer(state, action);
};
export default rootReducer;
calling:
const handleLogout = () => {
dispatch(resetState());
console.log('Reset action dispatched');
window.location.href = '/';
};
The way I'm currently using it is in my store.js I added
and then in my slice reducers I have