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.

Generated hooks and example

Generated hooks and example

Welcome back, last video we discussed the users API, how we can create it and now we have to discuss the generated hooks. I have this code setup here for you. So inside our previous code base, we have added a users API dot ts file inside the users folder in Redux Toolkit. It is using a createAPI function which we have to import from ReduxJS Toolkit query slash react. Please be noted that if your import path is only till query and not react, then you won't get access to the generated hooks. For the generated hooks, you have to import it after query, you have to add react. So let's dive into it. We have our reducer path, which we have to provide a string name. Usually this is an API, but over here we can give the other name. Then we have the base query which means the base URL which is going to be the same for all the queries. Then we have to use the fetchBaseQuery function from the same path and the baseUrl property has to be set to your API base URL path. Then for the user's resource,…

Contents