Redux Toolkit Is A Game Changer

Michael Chen
Nov 1, 2020

Hello Slices

Redux Toolkit is like that one new chef that is always smiling and gives you extra heaping scoops of beef while the old Redux is like that mean and grumpy lady that scoops the food and shakes the serving spoon so some food falls back into the tray.

I remember the first time I used Redux, I was a bit annoyed with all the boilerplate code required to set it up. We had to separate the actions and reducers to keep everything organized and we had to manually add a bunch of add-ons to get some basic features working. Redux Toolkit changed the state management game with its featured packed toolkit.

  • It cuts out a lot of the boilerplate from traditional Redux.
  • It includes a lot of the utilities we need to simplify a lot of the common use cases, like setting up stores, reducers, thunk, and dev tools
  • It is also built using TypeScript so integration with it is very nice.
  • It allows mutating state directly without making a copy.
  • Features and slices

Instead of having multiple directories for actions and reducers, in Redux Toolkit, we can put everything in a single directory. It’s convention to name that directory features. With new powerful libraries built in, we can create slices of state inside that features directory. Example features/users/UserSlice.js.

createSlice() is a new feature that accepts an initial state, an object full of reducer functions, and a “slice name”, and automatically generates action creators and action types that correspond to the reducers and state.

--

--