Modernizing Redux Logic with Redux Toolkit (Integrate Redux Toolkit and optimize store configuration) #5867
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
# Redux Toolkit Integration
What this PR does
This PR updates Redux store configuration to use Redux Toolkit, simplifying setup and leveraging built-in optimizations.
Changes
createStore
withconfigureStore
from Redux Toolkitthunk
middleware import (now included by default)Open questions and concerns
For now, I have simply replaced
createStore
withconfigureStore
. This follows the suggestion from the Redux migration guide on the official Redux website, which states:For more details, refer to the Redux documentation:
https://redux.js.org/usage/migrating-to-modern-redux#modernizing-redux-logic-with-redux-toolkit
a) Immutable and Serializable Checks
I have currently set
immutableCheck
andserializableCheck
(provided by Redux Toolkit) tofalse
. This decision was made because state mutations and non-serializable values were detected in our existing code, as shown in the screenshots below:I chose this approach for the following reasons:
dashboard functions as intended
.b) Addressing Mutation and Serialization Issues
An important question to consider is whether we should address these mutation and serialization issues now or in the future, especially given the large number of reducers and actions that need to be checked for state mutations.
For example, we can enable mutation checks when resolving or detecting these issues by setting
enableMutationChecks
totrue
. Then, pick an existing slice reducer and its associated actions, and ensure there is no state mutation (RTK will automatically detect it). Replace them with RTK'screateSlice
. Repeat this process for one reducer at a time. After resolving all the state mutations, we can thenpermanently re-enable these checks
i.e (development-mode checks for common mistakes like accidental mutations and non-serializable values).c) Redux DevTools in Production
I have also disabled Redux DevTools for production, but I'm not sure if this will be helpful.
Any suggestions regarding these three issues would be greatly appreciated. Thank you.