I want to clear the local storage when I click the logout button. I am using the redux persist with the redux toolkit. Here in the Redux Toolkit documentation, it is stated that, add the code to the specific slice, but I am confused about how to add the purge code. Kindly give an easy solution. It will be very helpful if a sandbox is provided as an example.
The exact phrase from the documentation is:
Additionally, you can purge any persisted state by adding an extra reducer to the specific slice that you would like to clear when calling persistor. purge(). This is especially helpful when you are looking to clear persisted state on a dispatched logout action.
And the code is:
import { PURGE } from "redux-persist";
...
extraReducers: (builder) => {
builder.addCase(PURGE, (state) => {
customEntityAdapter.removeAll(state);
});
}