Redux-dunk — A better effect middleware for redux

Effect middleware for redux, inspired by loop and thunk

Najib Ghadri
2 min readFeb 13, 2022

Schedule async functions from reducers to run after reducers using dispatch-getstate store api.

But why creating yet another library?

https://xkcd.com/927/

Background and motivation

Redux is an extremely popular state management library for JS applications, however, side-effect handling seems to be one side of it where the community has never really settled on a single preferred solution. There’s redux-thunk, which is famously only 14 lines long, then redux-loop, redux-saga, redux-observable, and many more.

What is redux-dunk?

Out of all of the previously mentioned side-effect libraries there is one architecture that seemed to me and many others at Prezi to be the most sensible. It’s the one that redux-loop also follows and it looks like this:

Combined redux and redux-dunk/loop architecture

This means you can schedule async functions that run after the reducer and can trigger new state changes with dispatch. Optionally you can get the current state in the effect, both in dunk and loop using getState.

As said redux-dunk has similarities with redux-loop, but here are the differences:

  1. Dunk is a much smaller library, helpers included
  2. Dunk is written in TypeScript
  3. Simpler, more flexible Effect API (just dispatch and getState, gives you everything you need)
  4. Easy testing with Jest and redux-mock-store
  5. Dunk is just a middleware, not an enhancer, it’s architecture is simpler too

Dunk is being used at Prezi in frontend applications such as the latest integrated version of https://prezi.com/video.

For more in-depth information visit the repo 😉:

--

--