Steve Blue
Aug 17, 2023

--

Certainty, if you'd like to use RTK query, so like this:

const api = createApi({

reducerPath: 'api',

baseQuery: fetchBaseQuery({ baseUrl: 'https://api' }),

endpoints: (builder) => ({

fetchData: builder.query({

query: () => '/data',

}),

}),

});

const { useFetchDataQuery } = api;

// store

const store = configureStore({

reducer: {

[api.reducerPath]: api.reducer,

},

middleware: (getDefaultMiddleware) =>

getDefaultMiddleware().concat(api.middleware),

});

// in component

const { data, error, isLoading } = useFetchDataQuery();

--

--

Steve Blue
Steve Blue

Written by Steve Blue

Experienced Mobile Application Developer with a demonstrated history of working in the computer software industry.

No responses yet