DEV Community

JesseNReynolds
JesseNReynolds

Posted on

In which I Sing the Praises of Redux Toolkit

Using Redux to store data that will be used across components has obvious advantages, but it also comes with some specific (at least potential) drawbacks.

Configuring, accessing, and updating the store all become significantly more dense as the store grows. This leads to an increasingly complex configuration and larger and larger chunks of boilerplate, not to mention the increase in potential for bugs that could become harder to trackdown in a dense and not inherently well managed codebase.

Enter Redux Toolkit.

First let's talk about some bonuses:

  • Redux Toolkit adds an immutability (courtesy of Immer) layer to take some of the mental overhead out of writing dispatches

  • Redux Toolkit by default utilizes Redux Devtools to make it easy to view state and its changes during development.

Redux Toolkit makes it easy to configure the store and easy to access and update only the parts of the store that any component needs to interact with. Each top-level segment of the store can be extracted to its own file, and much of the boilerplate can be abstracted away. These segments are referred to as slices. By thinking of each of these as their own mini store, and compartmentalizing them, we can separate the concerns of the various parts of the store and then bring them together easily when we configureStore. Since we can do so without the need for a root reducer, any troubleshooting later is that little bit less taxing.

By bringing convention to the whole system, we can more quickly navigate to the code we're looking for, and make modifications to the codebase with less lines of code and less potential for errors. Those cleaner sections of code will also be easier for other developers to find, understand, and add to later. Our system will be easier to develop with, since we can use Redux DevTools to watch our state.

I realize I haven't shown any references in this post, that's because I could not hope to give a better understanding of using Redux Toolkit than the documentation does by going through a sample project. Please, if you are starting a project and plan to use Redux, have a look at Redux Toolkit. Consider if it's right for your project. The ease of use, scalability, and convenience have absolutely made me a fan.

Top comments (0)