Questions tagged [rtk-query]

Redux toolkit query is for data and caching in a web application. It is an optional add-on in the Redux toolkit package.

RTK Query offers a set of powerful features that help developers handle common tasks related to data fetching, caching, and synchronization with the server. Some key features of RTK Query include:

  • Automatic API request generation: RTK Query generates API request endpoints based on a configuration object that defines the URL, method, headers, and other options. It eliminates the need to write boilerplate code for making API requests.

  • Automatic caching and invalidation: RTK Query automatically caches API responses, allowing subsequent requests for the same data to be served from the cache. It also provides mechanisms for cache invalidation when the data on the server changes.

  • Data synchronization: RTK Query handles data synchronization between the client and server, ensuring that the local data remains up-to-date with the server data. It supports background data fetching and real-time updates through WebSockets.

    Advanced data manipulation and normalization: RTK Query provides built-in support for data manipulation and normalization, allowing you to transform and shape the API responses before storing them in the cache.

  • Integration with Redux: RTK Query seamlessly integrates with Redux, leveraging the Redux store for storing the cached data and managing the state of ongoing API requests. It works well alongside other Redux Toolkit features, such as the Redux store, reducers, and middleware.

Overall, RTK Query aims to simplify the process of managing remote data in a Redux-based application by providing a standardized and efficient way to handle data fetching, caching, and synchronization.

You can learn more about RTK Query and its usage in the official documentation: RTK Query

948 questions
6
votes
1 answer

Unable to run test with redux-toolkit RTK-Query: TypeError: Cannot read property 'injectEndpoints' of undefined

trying to run the first test with redux-toolkit rtk query and got error that api is undefined. What I did wrong? ● Test suite failed to run TypeError: Cannot read property 'injectEndpoints' of undefined 33 | }; 34 | > 35 |…
6
votes
1 answer

RTK Query, manage spinner on a row of a table after an invalidate tag triggered by a mutation

I have integrated RTK query in a project of mine and I'm trying to understand how to handle the UI for my tables. I already had read other StackOverflow questions (e.g. that one) but I wasn't able the find the answer to my use case. My table rows…
lucataglia
  • 728
  • 5
  • 18
6
votes
1 answer

Redux Toolkit Query Graphql + Subscriptions

I really love graphql + rtk query but I cant get the graphql subscriptions working. I almost directly copied the streaming update example from the redux documentation. But I get the error subscriptions are not supported over HTTP, use websockets…
Wiezalditzijn
  • 443
  • 3
  • 17
6
votes
3 answers

How can I get data from my store generated by RTK Query?

I'm using a very basic RTK Query hook to get some user data from an API. How can I access the data saved in my store inside of my components? I'm not able to get the data from the store generated in a specific matter by RTK Query. I have a simple…
Jim Peeters
  • 2,573
  • 9
  • 31
  • 53
6
votes
5 answers

How to stop Redux RTK query from retrying on error

I have some requests which may return 404s. When they do, RTK query will send retries, resulting in hundreds of failed requests. Why is it trying to refetch on error and what can I do?
HahnSolo
  • 125
  • 3
  • 10
6
votes
1 answer

How to get X-Total-Count header with RTK Query?

Don't know how to access the headers after the request. Documentation examples without using x-total-count const guitarApi = createApi({ reducerPath: 'GUITARS', baseQuery: fetchBaseQuery({ baseUrl: API_URL }), endpoints: (builder) => ({ …
v.zdorovcev
  • 71
  • 2
  • 6
6
votes
1 answer

File Upload with Loading progress bar in React (using RTK Query)

Looking to make a component that can take a CSV. (excel) file and upload it to the server. (with drag and drop functionality, as well as a responsive upload bar showing progress in uploading to the server along with any error handling) Any advice…
6
votes
1 answer

Configuring the store with RTK-Query middleware

I'm trying to add the RTK-Query middleware to a nested store structure, I'm getting a very long and non-descriptive typescript error when I add the api middleware... Here's my code: export const rootReducer = combineReducers({ foo: fooReducer, …
Daniel Aviv
  • 139
  • 1
  • 6
6
votes
4 answers

How to add headers to endpoints in RTK-Query Plugin?

Trying to follow the rather sparse tutorial on the official page doesn't get me far. I'm essentially trying to add a certain header based on the params of an api call, but am clueless how to configure the endpoints to do so.
Bishonen_PL
  • 1,400
  • 4
  • 18
  • 31
6
votes
3 answers

How to implement rtk's createApi query for debouncing

Can someone help me in implementing the debounce functionality using creatApi with query implementation from redux toolkit. Thanks in advance.
Priyesh Singhai
  • 244
  • 3
  • 6
5
votes
1 answer

RTK Query and createSlice extra reducers

I'm new to RTK query, I'm currently watching a tutorial wherein the RTK query data is stored in a redux slice using ExtraReducers. I'm trying to store RTK query data in a slice state, but unable to do so. import { createSlice } from…
Vaikruta
  • 141
  • 8
5
votes
1 answer

How to call RTK mutations after first finishes

I am using REDUX-TOOLKIT-QUERY, Now I have a situation, I have to call one mutation. once that mutation returns a response, and I have to use that response in the other three mutations as a request parameter. How can we implement this in a proper…
Andaman
  • 295
  • 3
  • 10
5
votes
1 answer

changing state with RTK Query

I'm learning about RTK Query and really confused. I'd be happy if someone could point me towards the right direction. My question is how one can manipulate the state of the application store the same way as it is done when using createAsyncThunk and…
Leonid
  • 137
  • 1
  • 7
5
votes
0 answers

Cannot persist cookies when using RTK Query

I'm creating a pet project with React with Redux on the front end and Node.js with express on the back end. It's the first time I use Redux and RTK Queries, and I'm confused about cookies not being saved. I tried both variants with RTK Query, and…
AntoineRNT
  • 151
  • 1
  • 6
5
votes
1 answer

msw not able to match the same request the second time with updated data in a single test

I have a simple list of homes generated with RTK query hooks where item can be marked favorite and data refetched automatically based on tags invalidation. While everything works when I run the project within the test msw is not able to match the…
user1751287
  • 491
  • 9
  • 26
1 2
3
63 64