Redux Thunk

Thunk middleware that lets Redux action creators return functions instead of plain objects

Library
npm
v3.1.0
17,656 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
46 /100 Fair
Development Activity 0
Maintenance 20
Community 64
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
83 /100 Excellent
Architecture 80
Code Quality 88
Innovation 70
Learning Curve 95

Redux Thunk is the canonical middleware for writing asynchronous and conditional logic in Redux applications. Instead of dispatching only plain action objects, it lets action creators return a function (a “thunk”) that receives dispatch, getState, and an optional injected extra argument, enabling API calls, delayed dispatches, and conditional dispatch logic to live alongside the rest of an app’s Redux code.

Maintained by the Redux core team, it ships as a single small middleware factory with full TypeScript support and is included by default in Redux Toolkit’s configureStore. Its minimal surface area — one function, one composition pattern — has made it the default recommendation for basic async side effects in Redux, with more complex flows typically graduating to Redux Saga or RTK Query only when needed.

What You Get

  • A thunk middleware export that intercepts function-type dispatches and invokes them with dispatch, getState, and an extra argument
  • A withExtraArgument() factory for injecting a custom dependency (e.g. an API client) into every thunk
  • Full TypeScript types for ThunkAction, ThunkDispatch, and ThunkMiddleware generics
  • Zero runtime dependencies beyond Redux itself
  • Automatic inclusion in Redux Toolkit’s configureStore default middleware

Common Use Cases

  • Dispatching an async action creator that performs an API call and dispatches success/failure actions
  • Conditionally dispatching an action only if certain state conditions are met
  • Injecting a mockable API service as an extra argument for easier testing of async logic
  • Composing multiple async action creators together via returned Promises for sequential control flow

Under The Hood

Architecture - The entire library is a single higher-order function (createThunkMiddleware) in src/index.ts that returns standard Redux middleware: it checks whether the dispatched action is a function, and if so calls it with (dispatch, getState, extraArgument) instead of forwarding it down the middleware chain, otherwise passing plain actions through untouched. Tech Stack - Written in TypeScript, built to dual CJS/ESM output (dist/cjs, dist/redux-thunk.mjs) via a Rollup-based build, with redux as the only peer dependency and no runtime dependencies of its own. Code Quality - Tests run via Vitest with --typecheck enabled so type-level behavior is verified alongside runtime behavior, plus ESLint and Prettier enforced through lint/format:check scripts gating prepublishOnly. API Design - The API is deliberately minimal — one named export (thunk) for the common case and one factory (withExtraArgument) for the customized case — which keeps the learning curve very low and the composition pattern (return a function, get dispatch/getState) trivial to teach.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers