-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please adjust your tutorial to remove createRequest
#1
Comments
Hi, |
It is still mentioned on the article at https://blog.openreplay.com/leverage-rapidapi-data-with-redux-toolkit/ - could you please change it there, too? Also, my suggestion would be more along the lines of: const cryptoNewsHeader = {
"Accept": "application/vnd.api+json",
'X-BingApis-SDK': 'true',
'X-RapidAPI-Key': '129b2fc319msh341b23a0412e0abp1dab02jsn64e71a25960c',
'X-RapidAPI-Host': process.env.REACT_APP_RAPIDAPI_KE
}
export const cryptoNewsApi = createApi({
reducerPath: 'cryptoNewsApi',
- baseQuery: fetchBaseQuery({baseUrl: 'https://bing-news-search1.p.rapidapi.com/'}),
+ baseQuery: fetchBaseQuery({
+ baseUrl: 'https://bing-news-search1.p.rapidapi.com/',
+ headers: cryptoNewsHeader
+ }),
endpoints: (builder) => ({
getCryptosNews: builder.query({
query: (newsCategory) => ({
url: `/news/search?q=${newsCategory}`,
method: 'GET',
- headers: cryptoNewsHeader
}),
})
})
}); |
Hi, I will reach out to the editor to update the code I did what you just corrected but I didn't get the data I was fetching until I did just this:
|
Oh wow. That actually should work and is a bug that was never reported to us 🤦 Meanwhile, this should do it: export const cryptoNewsApi = createApi({
reducerPath: 'cryptoNewsApi',
baseQuery: fetchBaseQuery({
baseUrl: 'https://bing-news-search1.p.rapidapi.com/',
prepareHeaders(headers) {
headers.set("Accept", "application/vnd.api+json")
headers.set("X-BingApis-SDK", "application/vnd.api+json")
headers.set("X-RapidAPI-Key", process.env.REACT_APP_RAPIDAPI_KEY)
headers.set("X-RapidAPI-Host", 'bing-news-search1.p.rapidapi.com')
return headers
}
}),
endpoints: (builder) => ({
getCryptosNews: builder.query({
query: (newsCategory) => ({
url: `/news/search?q=${newsCategory}`,
method: 'GET',
}),
})
})
}); and I'll go and fix that on our side... |
Ok, this one works. Thanks. |
Hi,
I'm the author of RTK Query.
Please do not use that kind of
createRequest
helper function as you are showing here:crypto-news-site/src/services/cryptoNewsApi.js
Line 10 in 1e99a60
That is taken from a tutorial that grossly misunderstands what
baseQuery
is made for (and spreading to other tutorials now).Essentially,
baseQuer
y is already acreateRequest
function like this - the return value of an endpoint'squery
function will be passed as first argument intobaseQuery
, which will in the case offetchBaseQuery
then callfetch
.So please use
fetchBaseQuery
correctly instead here:I would greatly appreciate it if you could change that up in this tutorial as this is essentially a bad practice and we do not want it to spread.
The text was updated successfully, but these errors were encountered: