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

How to use two API reducer with RTK query in configuration Store?

I tried to combine two RTK reducers, but every time I tried to use concat to include it in the middleware, there will be errors, here's my code store.ts import { configureStore,combineReducers } from "@reduxjs/toolkit"; import cartReducer from…
Kai021195
  • 653
  • 3
  • 13
  • 26
4
votes
1 answer

Is it possible to optimistically update all caches of a endpoint?

In the redux tutorial, we learned how to perform optimistic updates: part-8-rtk-query-advanced#implementing-optimistic-updates But in the API reference of updateQueryData, I found that an args must be passed in: const updateQueryData = ( …
Grapes
  • 221
  • 2
  • 10
4
votes
1 answer

Why does RTK query response handling not work?

I tried to use the RTK query on my login request, but I got some trouble when printing out the result. Here is my code. authRTK.ts import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react"; import { loginForm, UserResponse } from…
Kai021195
  • 653
  • 3
  • 13
  • 26
4
votes
1 answer

What's the proper way to use RTK Query when dealing with multiple base URLS?

I have migrated towards RTK and enjoying it immensely so far, but one thing I got stuck on is the following situation: We have (for keeping it simple's sake) two endpoints: www.domain-customer.com <- fetching customer data www.domain-order.com <-…
Moniac
  • 41
  • 1
  • 3
4
votes
1 answer

How to set equivalent of fetch's { credentials: "include" } in Redux Toolkit's createApi?

I have an express-react-typescript-redux-passport project where I am using createApi from redux toolkit to call a /getuser api on my backend. I'm using passport-google-oauth20 strategy to authenticate users, and the user is successfully…
NicoWheat
  • 2,157
  • 2
  • 26
  • 34
4
votes
1 answer

Redux Toolkit Query: Reduce state from "mutation" response

Let's say I have an RESTish API to manage "posts". GET /posts returns all posts PATCH /posts:id updates a post and responds with new record data I can implement this using RTK query via something like this: const TAG_TYPE = 'POST'; // Define a…
NSjonas
  • 10,693
  • 9
  • 66
  • 92
4
votes
3 answers

RTK Query | Invalidate cache of an API service from another API service

I have created multiple RTK Query API services split into multiple files. For this issue I have two services: "Contracts" and "Properties". The contracts service should be able to invalidate the Properties cache when a contract updates, but even…
4
votes
2 answers

Redux toolkit RTK query mutation not getting returning data

Hi I recently learned the new react toolkit with the rtk query tool, and I am trying to put in a login system together using the createApi from the rtk package. After giving it a test on the login button pressed, I see the network request going…
4
votes
3 answers

How to clear RTK Query cache in tests between requests when using MSW and Jest?

I'm using Redux Toolkit and RTK Query with MSW for mocking, but I seem to be getting back the same data when trying to return an error in tests. I suspect this is an issue with RTK Querys caching behavior, and have tried to disable it with these…
niemelsa
  • 125
  • 2
  • 5
4
votes
1 answer

Use RTK Query with Graphql

So far I understand I need to build my own baseQuery. I could write graphql queries and mutations like in example here https://rtk-query-docs.netlify.app/examples/react-with-graphql, will I get full type safety for queries and mutations if I add…
Nenad
  • 231
  • 3
  • 15
3
votes
0 answers

RTK query seems to be hitting targeting my index.html instead of baseUrl / dataset

Code below. The following error is console logged: {status: 'PARSING_ERROR', originalStatus: 200, data: '\n\n \n \n \n\n', error: `SyntaxError: Unexpected…
3
votes
2 answers

An unhandled error occurred processing a request for the endpoint while using createApi(nodejs)

I am using RTK Query for fetching and Caching the data in plain javascript(without react)in nodejs environment. enter image description here I am using the above code which is found in the official website of Redux toolkit. The only change is I…
3
votes
1 answer

Is it possible to define RTK Query queries without QueryArgs?

The definition for a query in RTK Query is query. All of this is fine for queries where I actually need to send parameters to the API. However, I have some endpoints which don't require anything to be sent (something like…
k_krrs
  • 139
  • 7
3
votes
1 answer

FETCH_ERROR "TypeError [ERR_INVALID_URL]: Invalid URL" for requests made in tests

This is the first time when I setup test environment with RTK Query and mock server (msw). Please tell me what I'm doing wrong. Environment Name Version msw 1.2.1 react 18 redux…
naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
3
votes
2 answers

Use RTK Query to poll API until expected data is received with a custom baseQuery

Hi I am new to RTK Query and Redux toolkit. I am working on a pet project where I am trying to poll a workflow status API until it gives me a workflow status as 'CLOSED' Now I am not sure how to poll this API within my component since I would have…
Manthan Jamdagni
  • 894
  • 2
  • 17
  • 31