From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Reducer setup

Reducer setup

Welcome back, in this video we are going to learn about the slice now. As we have a slice as a specific piece of information like a departmental information. In RTK library we can group the state, reducers and actions for one feature all together. So there are no specific reducer that we have to create. We can create that if our use case defines that. But we can have one slice file and in that slice file, we get to have the reducers and actions imported from this. We can create a slice using the create slice function from the library. And similarly, we can provide it the initial state the way we were doing in Redux. And then we have an additional property of reducers. We can define functions here instead of having switch case statements. And over here, all the functions automatically becomes your actions. As you can see in this example, this counter slice dot actions is actually going to get its values from this functions defined here. And lastly, from this state, you can export back…

Contents