RTK query is htting localhost instead of baseUrl

Error:

services/posts.js:

import { createApi, fetchBaseQuery } from ‘@reduxjs/toolkit/query/react’;

export const gettingPosts = createApi({
reducerPath:“gettingPosts”,
baseQuery : fetchBaseQuery({
baseURL:“https://jsonplaceholder.typicode.com/”,
}),

endpoints:(builder)=>({
    getAllPosts:builder.query({
        query:()=>({
            url:'posts',
            method:'GET'
        })
    })
})

})

export const { useGetAllPostsQuery } = gettingPosts;

Store.js:

import { configureStore } from ‘@reduxjs/toolkit’;
import { setupListeners } from ‘@reduxjs/toolkit/query’;

import {gettingPosts} from ‘…/services/posts’;

export const store = configureStore({
reducer:{
[gettingPosts.reducerPath]:gettingPosts.reducer
},
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware().concat(gettingPosts.middleware),
})

setupListeners(store.dispatch)

components/Allposts.jsx

import React,{useEffect} from ‘react’;
import {useGetAllPostsQuery} from ‘…/services/posts.js’;

const AllPosts = () => {
const displayData = useGetAllPostsQuery();
console.log(displayData)

return (
<>
</>
)
}

export default AllPosts

Instead of hitting this baseURL:“https://jsonplaceholder.typicode.com/”,
its hitting to my local host:3000 … I don’t know why?

See this:

No one knows ? what the problem is ?

Try using baseUrl and not baseURL

Other than that I’m not sure, I haven’t used this lib.

It worked !!! thank you somuchhhh :)))

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.