Skip to content

Redux Thunk

Redux middleware that lets action creators return functions for delayed or async logic.

Stars
17.7k
Forks
1k
Licence
MIT
Language
TypeScript
Last update
1.6 years ago
Type
Library

No commits in over a year — check for forks or alternatives before adopting.

What it is

Redux Thunk is middleware for Redux, a state management library for JavaScript apps. It lets you write functions that can read the store's state and dispatch actions, which is useful for delayed updates, conditional updates, and simple async work like API requests. The official Redux Toolkit package includes it by default.

  • Dispatch an action after a timeout using a thunk action creator
  • Fetch data from an API and dispatch success or failure actions
  • Dispatch an action only when a condition in the store is met
  • Inject a custom argument such as an API service so it can be swapped for mocks in tests

Great for

  • Developers building apps with Redux who need async logic such as API calls
  • Teams that want conditional or delayed dispatches without a larger side-effect library
  • Projects using Redux Toolkit, where the middleware is already included

Not ideal for

  • People not using Redux, since this only works as Redux middleware
  • Projects needing complex async flows like cancellation or event streams, where the README points to comparing other async middleware such as sagas or observables
Step-by-step guide: how to use Redux ThunkInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Node.js and npm or yarn

    Install with npm

    npm install redux-thunk

    Install with yarn

    yarn add redux-thunk
  2. 2

    Run it

    • If you use Redux Toolkit, no install is needed because configureStore already adds thunk middleware
    • Otherwise install the package and import the named export: import { thunk } from 'redux-thunk'
    • Add it to your store with applyMiddleware(thunk) when using createStore
    • Write an action creator that returns a function receiving dispatch and getState
  3. 3

    Get the most out of it

    • Use the extraArgument option in configureStore to inject services like an API layer
    • Use withExtraArgument() when setting up the store by hand
    • Read the Redux docs page Writing Logic with Thunks for useful patterns
    • Return Promises from thunks to coordinate async flows between dispatches

Downloads

Strengths

  • Small, focused package that does one job
  • Official Redux Toolkit integration adds it by default
  • Supports injecting custom arguments for testing and dependency swapping

Trade-offs

  • Only handles basic side-effect logic; the README recommends comparing other async middleware for complex needs
  • Requires Redux to be set up with middleware, so it adds a concept new users must learn

How it compares

ProjectStarsTypeLevelUpdatedBest for
redux-thunk (this)17.7kLibraryintermediate1.6 years agoDevelopers building apps with Redux who need async logic such as API calls
redux-saga22.4kLibraryintermediate12 days agoReact or other frontend developers already using Redux who need to manage async logic

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.