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.

User slice setup

User slice setup

Welcome back. We have to implement our user slice here. So far we have our user type created and our user state type created and we had our initial state set up. We also have a fetch users function which is using JSON placeholder typico.com. If you go to this URL and scroll down, you are going to see the resources here. This API gives us 10 users, 200 to-dos and photos etc. We are interested in users here. You can do it for the other API routes too, if you like. If we click on users, then you can see this is the data that is going to be returned. So we have name, e-mail and id fields. We can also have show other fields as well and you can do that as a practice for your component once we are going to set up it and you can enhance it for the other items too. Let's get back to the code and set up our user slice now. We are going to have a user slice variable and over here we are going to call our create slice function. This is going to take the name users. It will have the initial state.…

Contents