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.

Fetch users function

Fetch users function

Welcome back, in this video we are going to set up our user slice base example using the createAsyncThunk function. So let's get started. So let's get started. We can close the existing items which we don't need. Inside the Redux toolkit, we are going to have another folder and we are going to call it users. Inside this, we can have a file which we can call as userslice.ts First, we are going to have a interface that will define what the user is actually going to have. Inside this we can have id which will be of type number. Then we can have a name field of type string and e-mail of type string. This is based on the JSON placeholder API. These fields are being returned. There are so many other fields, but for our example, we are just going to stick to three fields. Then we are going to have another interface, which will be for our user state. Inside this, we are going to have an items, which will be of type user. This will contain all the users. Then we have a loading of type boolean.…

Contents