Tech »  Topic »  How to Fetch API Data With RTK (Redux-Toolkit)

How to Fetch API Data With RTK (Redux-Toolkit)


In this article, I would like to refresh our knowledge about how to manipulate API data with the Redux Toolkit. First, we need API endpoints so we can make the GET request. Use any of the APIs from [RapidAPI]:https://rapidapi.com/. The next step is to connect the redux store to the React app. We will also need a `request` variable for the URL and the headers. Lastly, we create a custom hook to retrieve the data.

In this article, I would like to refresh our knowledge about how to manipulate API data with the Redux Toolkit.

First, let us install the following package:

npm i @reduxjs/toolkit

Next, we shall import the following in our app,

import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
import { configureStore } from '@reduxjs/toolkit';

Awesome, next, we need the API endpoints so we can make the GET request. For this example, let us ...


Copyright of this story solely belongs to hackernoon.com . To see the full text click HERE