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
12
votes
2 answers

Redux-Toolkit query interceptor

I'm trying to build an interceptor for cases when the access token becomes invalid with RTK Query. I've built it by an example in the docs, so that is looks as follows: const baseQuery = fetchBaseQuery({ baseUrl: BASE_URL, prepareHeaders:…
Oleksandr Fomin
  • 2,005
  • 5
  • 25
  • 47
11
votes
4 answers

Middleware for RTK-Query API at reducerPath "api" has not been added to the store

I am creating a react native app and I am getting this warning. Middleware for RTK-Query API at reducerPath "api" has not been added to the store. Features like automatic cache collection, automatic refetching etc. will not be available. I see my…
Jonathan Vargas
  • 256
  • 1
  • 4
  • 8
11
votes
2 answers

How to send a file with RTK Query from Redux Toolkit?

I am trying to use RTK Query mutations to upload a file to the API. Here is my mutation code: addBanner: builder.mutation({ query(body) { return { url: `/api/banners`, method: 'POST', …
Yevgeniy Timchenko
  • 360
  • 1
  • 3
  • 11
10
votes
1 answer

How to use await for get request in RTKQuery?

I've tried initiate - but this result was retrieved from previous result. mutate - but I think this is irregular. Is there any way to use await for a normal get request? relevant questions: Approaches for using RTK-Query hooks inside…
sandbox24
  • 121
  • 2
  • 5
10
votes
4 answers

Prevent Caching on a specific RTK Query Endpoint

I am using rtq query and i have an endpoint that takes azure-ad oid from the global store and makes a query to the backend to check if the user exists on the backend to check if the user exists. If the user exists then I redirect the user to the…
Dijiflex
  • 523
  • 1
  • 8
  • 26
10
votes
3 answers

How to put RTK query into store/slice?

I just started using RTK query, but facing a problem My app has all the setting in one big JSON, so I create an RTK query to fetch the setting. In the tutorial, the examples are about using the useQuery hook in the component and immediately display…
vito huang
  • 4,228
  • 7
  • 26
  • 24
9
votes
1 answer

RTK query `use*Query` is using cached isLoading and data even for different args

I'm new to RTK query and I'm having issues with it sharing data across queries with different args. // api.js const { useGetStuffQuery } = api.injectEndpoints({ endpoints: (builder) => ({ getStuff: builder.query({ query: (stuffId) => ({…
enrij
  • 93
  • 1
  • 3
8
votes
1 answer

React RTK query Mutation can return value?

Is is possible to get the response of endpoint in React RTK Query Mutation . I have a one mutation which insert into DB and I need to get the ID which inserted. in my api : addRecord: build.mutation({ query(data) { return { …
Reza Rahgozar
  • 99
  • 1
  • 7
8
votes
1 answer

Refetching upon a button click in RTK Query does not trigger component update

Hello all and thanks in advance. Just to begin with, I am aware that weather data is not a suitable use case for RTK Query as it is always changing, I am using RTK Query in this case just for practicing purposes. I want to refetch weather data upon…
jpxcar
  • 107
  • 1
  • 2
  • 7
8
votes
1 answer

RTK Query: How to query an array of IDs and return an array of retrieved data?

I am working with "Redux Toolkit Query" and run into the situation where I have an array of place ids and want to return an array of retrieved places. However, with my current setup, I am only able to query a single place, but not the entire…
dan_boy
  • 1,735
  • 4
  • 19
  • 50
8
votes
1 answer

Should I use RTK Query per base URL or Resource?

I am working in a big project with a lots of base URL and resources that we can undestand as a lot of diferent integrated services. Pluging RTK on my application following the resource line (Isolated), that i have a createApi() per resource. I'm…
Lucas Cordeiro
  • 213
  • 3
  • 8
7
votes
1 answer

RTK Query sustain `isLoading` for auto-refetching after cache invalidation

Having a hard time finding a good answer/ solution for this problem. I have a POSTS list component that allows to delete individual POST rows. I'm using a run of the mill queryMutation for deletion purposes: IMPLEMENTATION deletePostById:…
flaky
  • 6,816
  • 4
  • 29
  • 46
7
votes
1 answer

Invalid hook call while testing with jest - react native

I've got problem with testing screen. I'm trying to test with jest snapshot but first of all I wan't to pass simple test with RTK Query request API. In next example I try to get error something like Test didn't pass due to not equal results but I'm…
7
votes
1 answer

Should I put RTK Query results into the store?

Trying to understand RTK Query and how to use it optimally in a React app. I have a Search component in one part of my application. When a search is executed, I want the results to appear in another area, far away in the component tree. All the…
doggie
  • 79
  • 1
  • 6
7
votes
3 answers

RTK Query query not refetching after mutation

On my api I have two mutations and strangely, one of them does trigger the refetch but the other doesn't and I have no clue why. Both mutations make their networks calls and changes are reflected in the server. Here's my api definition. import {…
Juan De la Cruz
  • 436
  • 6
  • 17
1
2
3
63 64