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.

Custom hook and component setup

Custom hook and component setup

Before moving forward, I'm going to show you another way you can do that. If you are not comfortable with the previous way of creating a slice and just exporting the actions from there, then what you can do is you can have another way of handling things. You can describe what happened for your actions, like not how to handle it. So in case you have a long file which is going to have a lot of actions and all the actions can have a good line of code for defining the business logic. In that case, you'll have a lengthy file. So to avoid that, we can have another way of doing things. The actions, as we know, are to submit a request form or perform an action which needs to be happened on the slice. It gets auto-generated from the create slice function if we are using it, which we are using because our code example is pretty simple. And moving forward, when we are going to have complex examples, we will be using the other approach. So the other approach is basically to have a separate action…

Contents