gitwtfhub

wtf is redux-thunk?

reduxjs/redux-thunk — explained in plain English

Analysis updated 2026-06-24

17,709TypeScriptAudience · developerComplexity · 2/5Setup · easy

TL;DR

A tiny Redux add-on that lets you write async logic like API calls as functions instead of plain action objects, so you can fetch data and dispatch updates to the store when the work finishes.

Mindmap

mindmap
  root((repo))
    What it does
      Async Redux actions
      Conditional dispatch
      Side effect handling
    How it works
      Return function not object
      Receives dispatch and getState
      Middleware intercepts
    Use cases
      API data fetching
      Chained async steps
      Mock injection in tests
    Setup
      npm install
      applyMiddleware
      Redux Toolkit built-in

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Why would anyone build with this?

REASON 1

Fetch data from an API in a Redux app and dispatch actions to update state when the request succeeds or fails.

REASON 2

Dispatch a Redux action only when a condition is true by reading current state inside a thunk function.

REASON 3

Chain multiple async steps together in one thunk, such as logging in and then fetching user data in sequence.

What's in the stack?

TypeScriptJavaScriptRedux

How it stacks up

reduxjs/redux-thunkvuejs/vitepresslangchain-ai/langchainjs
Stars17,70917,70917,665
LanguageTypeScriptTypeScriptTypeScript
Setup difficultyeasyeasymoderate
Complexity2/52/53/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you spin it up?

Difficulty · easy Time to first run · 30min

Already included in Redux Toolkit, no separate install needed if you are using configureStore from Redux Toolkit.

Wtf does this do

Redux Thunk is a small add-on for Redux, the popular state-management library for JavaScript apps. Redux on its own only knows how to handle plain, synchronous updates: you tell the store about an event by dispatching an action object, and a reducer updates the state. That works fine for simple changes, but it leaves you stuck when you need to do something like wait for a network request to come back before updating the state, or only dispatch an action if some condition is true. Redux Thunk fills that gap. The middleware lets you write action creators that return a function instead of an action object. That inner function receives the store's dispatch and getState methods as arguments, so it can look at the current state, run async logic such as an AJAX call, and then dispatch one or more real actions when the work is done. A thunk, in general programming terms, is a function that wraps an expression to delay its evaluation, and that is exactly what is happening here: the work is described once and run later, when the middleware invokes it. You can also inject a custom argument (such as an API service) into every thunk, which is convenient for swapping in a mock during tests. You would reach for Redux Thunk when you need to handle side effects in a Redux app, like fetching data, conditional dispatching, or chaining a few async steps together. If you are already using Redux Toolkit, the recommended modern Redux setup, the thunk middleware is included automatically, otherwise you install the redux-thunk package and wire it up with applyMiddleware. The codebase is written in TypeScript and published to npm.

Yoink these prompts

Prompt 1
I have a Redux store and need to fetch user data from an API. Show me how to write a redux-thunk action creator that calls /api/users and dispatches a success or error action depending on the result.
Prompt 2
How do I inject a custom API service into every redux-thunk so I can swap it out with a mock during tests? Show me the setup code.
Prompt 3
I am using Redux Toolkit, is redux-thunk already included? Show me how to write an async thunk with createAsyncThunk instead of writing one manually.
Prompt 4
What is the difference between redux-thunk and redux-saga for handling async logic? When should I use one over the other?

Frequently asked questions

wtf is redux-thunk?

A tiny Redux add-on that lets you write async logic like API calls as functions instead of plain action objects, so you can fetch data and dispatch updates to the store when the work finishes.

What language is redux-thunk written in?

Mainly TypeScript. The stack also includes TypeScript, JavaScript, Redux.

How hard is redux-thunk to set up?

Setup difficulty is rated easy, with roughly 30min to a first successful run.

Who is redux-thunk for?

Mainly developer.

View the repo → Decode another repo

This repo across BitVibe Labs

Don't trust strangers blindly. Verify against the repo.