DEV Community

Discussion on: Immer vs Ramda - two approaches towards writing Redux reducers

Collapse
 
markerikson profile image
Mark Erikson

As it turns out, you can use Redux Toolkit even if you're not using a Redux store!

A reducer is, ultimately, just a function. It doesn't matter if that function is implemented using vanilla JS, Immer, Ramda, Lodash/FP, or something else.

I've used Redux Toolkit's createSlice API multiple times to create reducers that were only meant for use with the useReducer hook in a React component, in apps that weren't using a Redux store at all.

If you're looking at using Immer to write a reducer, you should seriously consider just using createSlice instead of calling produce yourself. createSlice adds minimal extra runtime overhead beyond Immer by itself, and works great with TypeScript as well.

Thread Thread
 
fkrasnowski profile image
Franciszek Krasnowski

Yeah, it's a great tool indeed. I've included your thoughts in the article