‫Now that we understand the fundamentals of Redux,
‫it's time to take the next step
‫and learn about the modern way of writing Redux,
‫which is Redux Toolkit.
‫So, as I just said,
‫Redux Toolkit is the modern way of writing Redux code,
‫and it's advised by the Redux team
‫to now prefer Redux Toolkit over classic Redux.
‫That's because Redux Toolkit is an opinionated approach
‫that forces everyone to use best practices
‫that the community has learned over the years.
‫So, basically, Redux Toolkit took all these best practices
‫and placed them into this new way of writing Redux.
‫Now does this mean
‫that everything that you just learned is obsolete?
‫Well, not at all.
‫First, without these fundamentals,
‫it's very hard to understand Redux Toolkit
‫because it is built on top of classic Redux, of course.
‫And, second, both ways of writing Redux
‫are 100% compatible with each other.
‫So you can actually use classic Redux in one part of the app
‫and Redux Toolkit in another part
‫if that's what you want to do.
‫Okay, so that all sounds great, but what's the big deal?
‫So what are the actual advantages of Redux Toolkit?
‫Well, the biggest advantage is certainly
‫that Redux Toolkit allows us to write a lot less code
‫to achieve the exact same result as before.
‫So we say that we need a lot less boilerplate code,
‫which is basically code that only sets things up
‫but doesn't really do anything meaningful.
‫And so Redux Toolkit hides all that stuff,
‫like setting up middleware and the developer tools.
‫So out of the box Redux Toolkit gives us many things.
‫But the three highlights are,
‫first, it allows us to write code
‫that actually mutates state inside reducers.
‫Now behind the scenes a library called Immer
‫will convert our code back to non-mutating,
‫so like the one that we have been writing
‫up until this point,
‫but the new code that we're gonna write
‫will look as if we were mutating the state object directly.
‫And, in my opinion,
‫this is really the biggest advantage of using Redux Toolkit,
‫because if you have a pretty complex state object
‫with nested objects and arrays,
‫this can actually be a game-changer in reducing complexity.
‫Redux Toolkit also automatically creates action creators
‫from our reducers,
‫and this can be quite helpful as, again,
‫it helps us writing less code.
‫It can, however,
‫also create some additional work in some situations
‫as we will experience in practice soon.
‫And, finally, Redux Toolkit
‫will also automatically set up Thunk middleware
‫and the developer tools
‫so that we can focus on writing code
‫that actually does something in the application.
‫Alright, and this should be enough of an introduction,
‫and so let's head back to code.