How to Update Redux Toolkit in React
Updating Redux Toolkit in your React application ensures you have
access to the latest performance improvements, security patches, and
modern state management features. This article provides a
straightforward, step-by-step guide on how to safely upgrade
@reduxjs/toolkit and its companion package
react-redux using npm or Yarn, while also handling
potential breaking changes.
Step 1: Check Your Current Versions
Before upgrading, identify the current versions of Redux Toolkit and
React Redux installed in your project. Open your project’s
package.json file and look under the
dependencies section:
"dependencies": {
"@reduxjs/toolkit": "^1.9.5",
"react-redux": "^8.1.1"
}Step 2: Run the Update Command
To upgrade Redux Toolkit and React Redux to their latest stable versions, run the appropriate command for your package manager in your project’s root directory.
Using npm:
npm install @reduxjs/toolkit@latest react-redux@latestUsing Yarn:
yarn add @reduxjs/toolkit@latest react-redux@latestUsing pnpm:
pnpm add @reduxjs/toolkit@latest react-redux@latestThis command updates your package.json and installs the
latest packages into your node_modules folder.
Step 3: Check for Breaking Changes
If you are performing a major version upgrade (for example, moving from Redux Toolkit v1.x to v2.x), you may encounter breaking changes.
Common changes in major updates include: * TypeScript
requirements: Newer versions of Redux Toolkit often require
updated versions of TypeScript. * Deprecated methods:
Older methods like createReducer and
createAction with object notations may be fully deprecated
in favor of the builder callback notation. * ConfigureStore
changes: Default middleware settings might be adjusted.
Review the official Redux Toolkit release notes on GitHub to identify any specific migration steps required for your codebase.
Step 4: Verify the Update
After the installation is complete, verify that the update was successful:
- Clear cache and restart: To prevent bundler issues, restart your development server. If necessary, clear your bundler’s cache (e.g., Vite, Next.js, or Create React App cache).
- Run your test suite: Execute
npm testoryarn testto ensure existing Redux integration tests still pass. - Check the browser console: Run your application locally and open the developer tools console to check for any deprecation warnings or runtime errors related to your Redux store setup.