NPM Star
Collections
  1. Home
  2. Compare
  3. react-redux vs redux-toolkit
NPM Compare

Compare NPM packages statistics, trends, and features

CollectionsVS Code extensionChrome extensionTermsPrivacyLinkTreeIndiehackersBig Frontendqiuyumi

React-Redux vs Redux Toolkit: State Management Solutions

React-Redux is the official package that helps React applications connect with Redux state management. Redux Toolkit is a newer, more user-friendly package that simplifies Redux development by including useful tools and reducing boilerplate code. While React-Redux focuses on connecting React and Redux, Redux Toolkit provides a complete solution with built-in best practices and helper functions.

State Managementreduxreactstate-managementstorehooks

Detailed Comparison

Technical Analysis

featureComparison

React-Redux provides a way to connect React components to a Redux store, while Redux Toolkit provides a set of tools to simplify Redux development, including a configureStore function, a createReducer function, and a createApi function.

typescriptSupport

Both packages support TypeScript, with react-redux requiring additional configuration and redux-toolkit providing built-in support.

browserCompatibility

Both packages are compatible with modern browsers, including Chrome, Firefox, and Edge.

dependencies

React-Redux depends on React and Redux, while Redux Toolkit depends on Redux.

performance

Both packages have similar performance characteristics, with Redux Toolkit providing some optimization features out of the box.

Ecosystem Analysis

frameworkCompatibility

Both packages are compatible with React, but Redux Toolkit is also compatible with other frameworks like Angular and Vue.

communityActivity

React-Redux has a larger community and more active maintainers, while Redux Toolkit has a smaller but still active community.

documentationQuality

Both packages have high-quality documentation, with Redux Toolkit providing more comprehensive guides and tutorials.

maintenanceStatus

Both packages are actively maintained, with React-Redux having a more frequent release cycle.

Performance Comparison

bundleSizeAnalysis

Redux Toolkit has a slightly larger bundle size due to its additional features.

runtimePerformance

Both packages have similar runtime performance, with Redux Toolkit providing some optimization features.

loadingTime

Both packages have similar loading times, with Redux Toolkit providing some optimization features.

memoryUsage

Both packages have similar memory usage, with Redux Toolkit providing some optimization features.

Code Examples

Basic React-Redux Example

1import React from 'react';
2import { connect } from 'react-redux';
3
4const Counter = ({ count, increment }) => {
5  return (
6    <div>
7      <p>Count: {count}</p>
8      <button onClick={increment}>Increment</button>
9    </div>
10  );
11};
12
13const mapStateToProps = state => ({ count: state.count });
14const mapDispatchToProps = dispatch => ({ increment: () => dispatch({ type: 'INCREMENT' }) });
15
16export default connect(mapStateToProps, mapDispatchToProps)(Counter);

This example shows how to connect a React component to a Redux store using react-redux.

Basic Redux Toolkit Example

1import { configureStore } from '@reduxjs/toolkit';
2import { counterReducer } from './counterReducer';
3
4const store = configureStore({
5  reducer: {
6    counter: counterReducer
7  }
8});

This example shows how to create a Redux store using Redux Toolkit's configureStore function.

Recommendation

Summary

Both packages are suitable for building Redux applications, but Redux Toolkit provides more features and optimizations out of the box.

Details

  • Redux Toolkit provides a more streamlined development experience
  • Redux Toolkit provides more features for managing side effects and caching

Similar Packages

zustand

90%

A tiny state management solution that uses hooks. It's much simpler than Redux and requires way less code to get started. Perfect for small to medium React applications.

It's a great alternative because it's easier to learn than Redux, has zero dependencies, and doesn't need any wrapping Provider components. You can start using it in minutes without complex setup.

State Management

recoil

85%

Facebook's own state management library that works with atoms (small pieces of state) and selectors. It's built specifically for React and handles complex state requirements really well.

Created by Facebook (like React), it's great for large applications that need to manage lots of data. It's especially good at handling derived state and async data.

State Management

jotai

80%

A state management tool that breaks down your state into small atomic pieces. It's like Lego blocks for your app's data, where you can combine small pieces to build bigger things.

It's perfect for those who find Redux too complicated. It works great with React's concurrent features and has a very simple API that feels natural with React hooks.

State Management

mobx

75%

A battle-tested library that makes state management simple and scalable. It uses observable patterns to automatically track and update your app's state.

It's simpler than Redux but just as powerful. Changes to state are automatically reflected in your app without manual updates, which means less code to write and maintain.

State Management

React Redux

Official React bindings for Redux. Performant and flexible.

GitHub Workflow Status npm version npm downloads #redux channel on Discord

Installation

Create a React Redux App

The recommended way to start new apps with React and Redux is by using our official Redux+TS template for Vite, or by creating a new Next.js project using Next's with-redux template.

Both of these already have Redux Toolkit and React-Redux configured appropriately for that build tool, and come with a small example app that demonstrates how to use several of Redux Toolkit's features.

# Vite with our Redux+TS template # (using the `degit` tool to clone and extract the template) npx degit reduxjs/redux-templates/packages/vite-template-redux my-app # Next.js using the `with-redux` template npx create-next-app --example with-redux my-app

An Existing React App

React Redux 8.0 requires React 16.8.3 or later (or React Native 0.59 or later).

To use React Redux with your React app, install it as a dependency:

# If you use npm: npm install react-redux # Or if you use Yarn: yarn add react-redux

You'll also need to install Redux and set up a Redux store in your app.

This assumes that you’re using npm package manager with a module bundler like Webpack or Browserify to consume CommonJS modules.

If you don’t yet use npm or a modern module bundler, and would rather prefer a single-file UMD build that makes ReactRedux available as a global object, you can grab a pre-built version from cdnjs. We don’t recommend this approach for any serious application, as most of the libraries complementary to Redux are only available on npm.

Documentation

The React Redux docs are published at https://react-redux.js.org .

How Does It Work?

The post The History and Implementation of React-Redux explains what it does, how it works, and how the API and implementation have evolved over time.

There's also a Deep Dive into React-Redux talk that covers some of the same material at a higher level.

License

MIT

redux-toolkit

introduction

提供实用的工具函数,改善使用redux的开发体验,提供代码可读性。

  • createReducer a functional way to write reducer
  • createAction a simple way to write action
  • debugMiddleware a useful debug middleware

installation

mnpm install redux-toolkit

Usage

import { createAction, createReducer, debugMiddleware } from 'redux-toolkit'

createReducer

避免使用switch碰到的问题:

  • 不用担心各个case下的变量冲突问题
  • 可以解构action 和 state
  • 使用箭头函数
  • 当swtich case 过多时,object 的速度会比 switch 更快
  • 不再会被 break 和 default 恶心

下面是一个简单的reducer例子

import { ADD_TODO, DELETE_TODO, EDIT_TODO, COMPLETE_TODO, COMPLETE_ALL, CLEAR_COMPLETED } from '../constants/ActionTypes';

const initialState = [{
  text: 'Use Redux',
  completed: false,
  id: 0
}];

export default createReducer({
  [ADD_TODO]: (state, { text }) => [{
    id: state.reduce((maxId, todo) => Math.max(todo.id, maxId), -1) + 1,
    completed: false,
    text
  }, ...state],

  [DELETE_TODO]: (state, { id }) => state.filter(todo =>
    todo.id !== action.id
  ),

  [EDIT_TODO]: (state, { id, text }) => state.map(todo =>
    todo.id === id ?
      Object.assign({}, todo, { text }) :
      todo
  ),

  [COMPLETE_ALL]: state => {
    const areAllMarked = state.every(todo => todo.completed);
    return state.map(todo => Object.assign({}, todo, {
      completed: !areAllMarked
    }));
  },

  [CLEAR_COMPLETED]: state => state.filter(todo => todo.completed === false)
}, initialState)

createAction

提供更简单的方法去创建actionCreator。下面是通过actionCreator和普通方法进行对比。

创建没有payload的action

createAction('showAll');

function() {
  return {
    type: 'showAll'
  }
}

只有一个携带值

当只有一个需要传递给reducer的值时,接受一个key。

createAction('add', 'value');

function(value) {
  return {
    type: 'add',
    payload: {
      value: value
    }
  };
}

传递多个值

接受一个keys数组,会将参数按顺序放置在action的payload属性中。

createAction('add', ['num1', 'num2']);

function (num1, num2) {
  return {
    type: 'add',
    payload: {
      num1: num1,
      num2: num2  
    }
  };
}

根据函数创建action

接受一个将参数处理为payload的函数

createAction('add', (num1, num2) => {
  number1: num1,
  number2: num2,
  other: num1 * num2
})

function (num1, num2) {
  var getAction = (num1, num2) => {
    number1: num1,
    number2: num2,
    other: num1 * num2
  };
  return {
    type: 'add',
    payload: getAction(num1, num2)
  };
}

debugMiddleware

提供一个debug的middleware

features

  • if dispatched action don't match FSA rules, will throw Error
  • print the info of actions
  • print the old state after action dispatched
StarsIssuesVersionUpdatedⓘLast publish dateCreatedⓘPackage creation dateSizeⓘMinified + Gzipped size
R
react-redux
23,486269.2.06 months ago10 years agoinstall size 4.1 KB
R
redux-toolkit
201.1.23 years ago10 years agoinstall size 3.6 KB

Dependencies Comparison

react-redux

Dependencies

@types/use-sync-external-store^0.0.6
use-sync-external-store^1.4.0

Dev Dependencies

@microsoft/api-extractor^7.47.0
@reduxjs/toolkit^2.2.5
@testing-library/dom^10.4.0
@testing-library/jest-dom^6.6.3
@testing-library/react^16.1.0
@types/node^20.14.2
@types/prop-types^15.7.12
@types/react^19.0.1
@types/react-dom^19.0.1
codecov^3.8.3
cross-env^7.0.3
eslint^8.57.0
eslint-config-prettier^9.1.0
eslint-import-resolver-typescript^3.6.1
eslint-plugin-import^2.29.1
eslint-plugin-prettier^5.1.3
eslint-plugin-react^7.34.2
jsdom^25.0.1
prettier^3.3.3
react^19.0.0
react-dom^19.0.0
redux^5.0.1
rimraf^5.0.7
tsup^8.3.5
typescript^5.5.4
typescript-eslint^7.12.0
vitest^1.6.0

Peer Dependencies

@types/react^18.2.25 || ^19
react^18.0 || ^19
redux^5.0.0

redux-toolkit

Dependencies

debug^2.2.0
flux-standard-action^0.6.0
invariant^2.1.1
lodash^3.10.1

Dev Dependencies

Peer Dependencies

Who's Using These Packages

react-redux

docker-web-gui
docker-web-gui

A simple web based GUI for managing Docker containers and images

lore
lore

Respectfully opinionated convention-driven framework for building React applications. Built on React, Webpack, Redux, and React Router.

baker
baker

Mobile MVP Toolkit

arranger
arranger

Data portal API and component generation

pola-web
pola-web

Pola pomoże Ci odnaleźć polskie wyroby. Zabierając Polę na zakupy odnajdujesz produkty “z duszą” i wspierasz polską gospodarkę.

redux-toolkit

Kaffee
Kaffee

Java Management Extension Client for Monitoring Kafka Metrics

Soombook
Soombook
muxic
muxic
amazon-clone
amazon-clone

Amazon clone built with Next.js and TailwindCSS 🔥