'How can i refresh store redux toolkit after logout
I'm trying to reset all reducer in my store using redux toolkit after logout. But all my attempts were unsuccessful. How can I do it?
Solution 1:[1]
I usually follow this style. Keep an initial state for the store.
Revert back to that initial state when logout.
Example:
const User = {
name: "",
username: ""
}
export const authSlice = createSlice({
name: "User",
initialState: User,
reducers: {
setUserInfo: (state, { payload }) => {
// Setting User Data
},
logoutUser: () => User
}
});
or simply reload the page so that redux state gets empty.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shri Hari L |
