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
0
votes
1 answer

How can I update the data in my list if a subitem updates from a get request in RTK Query

So I have the general concept of RTK query down fairly well but I have a use case where I need some assistance. I have a list component and a details component that you can navigate to to view more details on that list item. So I have two endpoints…
epicmau5time
  • 316
  • 3
  • 7
0
votes
1 answer

How to use RTK Query with ErrorBoundary

Are there some examples of use with ErrorBoundary? This is what i can think of: const { isError: isGetAError, error: getAError } = useGetAQuery() if (isGetAError) { throw getAError } const { isError: isGetBError, error: getBError } =…
Mxcpanel
  • 95
  • 7
0
votes
1 answer

RTK query error / isError / isSuccess are not updating

I'm trying to use error / isError to validate if the request failed, but it is always undefined. This is my service (I set the URL to: 'non_exists_url') import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' import { …
Israel
  • 445
  • 2
  • 5
  • 15
0
votes
1 answer

Testing Redux Toolkit Query using jest issue with auth

Im currently trying to write jest test for my RTKQuery, but I get stuck on the authentication level for the test. Basically the api Im using is designed to have the token on query param instead of having it on the request header:…
user14459580
  • 206
  • 2
  • 12
0
votes
1 answer

Can RTK queries be used to incrementally update a single stored object across subsequent queries?

I am using a map from MapBox and after every onDragStopped, the bounds of the map are sent as {nw,ne,se,sw} coordinates to the server, where the geometry of those bounds is compared the the stored geometries of regions (counties, countries, ...). If…
paullc
  • 155
  • 2
  • 9
0
votes
0 answers

How to use `selectFromResult` with TS correctly

I want to select data from query result function useGetItemById(id: string) { return api.endpoints.getItemList(undefined, { selectFromResult: ({ data, ...rest }) => ({ ...rest, data: data?.find(item => item.id === id) }) …
0
votes
1 answer

Why RTK-Query always return originalStatus 200?

There is not backend on my localhost:3000 and I expect that all of my requests will return error 404. But RTK-Query always returns this: { data: "\n\n \n
Nikita Babeev
  • 43
  • 1
  • 9
0
votes
1 answer

How to ensure that the request has been sent before manually reading the cache?

Like this example: constructing-a-dynamic-base-url-using-redux-state, I need to get the data of a certain endpoint from the cache to build fetch arg, I can get the data by api.endpoints.getPost.select(postId)(getState()), But how do I ensure that…
Mxcpanel
  • 95
  • 7
0
votes
1 answer

Redux Toolkit useMutation hook data sharing between multiple component

I was building a react app where I am using redux-toolkit for state management where I am using useMutation hook to conditionally trigger post requests but I am not able to consume the data from this hook among multiple component. After searching a…
0
votes
2 answers

Customising RTK-query query / mutation body with redux store

I would like to make the query body using current redux store data in this createApi function changing the postBody variable. I mean I want to get a redux node here from the store and merge the data with postBody if that's possible. export const…
superdem
  • 15
  • 1
  • 4
0
votes
1 answer

Redux-Toolkit Query Authorization cases

Anybody used RTKQ for auth purposes? Successfully got signup and login working. But can’t figure out how to save the token that is fired back. Tried default useBaseQuery with prepareHeaders as in official docs and it simply returns 'can’t read…
0
votes
1 answer

React hooks & RTK pattern for a series of chained http requests

In my component, I need to fetch contestDetails, get a value from the response (draftgroupId), and then fetch the draftGroup. Normally I'd wrap them each in useEffect: const [draftGroupId, setDraftGroupId] = useState(); useEffect(() => { …
Jonathan Tuzman
  • 11,568
  • 18
  • 69
  • 129
0
votes
0 answers

RTK recall api when set new state

I have a api with rtk (redux-toolkit) with a state 'search' const [search, setSearch] = useState({nexToken: null}) const { data, isLoading, isError } = useGetPostQuery(search ?? skipToken) useEffect(() => { console.log('data', data) },…
fabio87
  • 65
  • 6
0
votes
1 answer

RTK query is looping over result but not providing the expected content

I'm currently doing the Redux Essentials tutorial and stuck in chapter 7: When switching from the classical thunk to the RTK query, the mapping will not work: content = posts.map(post => ) The error message…
Charly
  • 56
  • 4
0
votes
1 answer

Reduxtoolkit createApi how to mix and parse two endpoints results?

tldr; How to mix two or more createApi endpoints results ? So I'm using createApi from reduxToolkit and the problem I have quite simple but I'm kinda lost in this huge documentation of this beautiful tool. The idea is that I have a view that will…
François Richard
  • 6,817
  • 10
  • 43
  • 78