我有一些要求可能回去404个。 当他们这样做时,RTK会发出试射,导致数以百计的失败要求。 为什么它试图对错误和我能做些什么进行指责?
如果你最后点错,RTK Query s use Query
将在两种情况下发出请求:
- you change the argument (that would always result in a new request)
- you mount a component using this
useQuery
.
因此,如果看不见你的法典,我就认为,你的构成部分会重新出现,从而在不断发展之后又提出另一个要求。
您可使用<条码>最大限度条码>,限制自动进行的复审次数。 页: 1
import { createApi, fetchBaseQuery, retry } from
@reduxjs/toolkit/query/react
// maxRetries: 5 is the default, and can be omitted. Shown for
documentation purposes.
const staggeredBaseQuery = retry(fetchBaseQuery({ baseUrl: / }), {
maxRetries: 5,
})
export const api = createApi({
baseQuery: staggeredBaseQuery,
endpoints: (build) => ({
getPosts: build.query({
query: () => ({ url: posts }),
}),
getPost: build.query({
query: (id) => ({ url: `post/${id}` }),
extraOptions: { maxRetries: 5 }, // You can override the retry behavior on each endpoint
}),
}),
})
export const { useGetPostsQuery, useGetPostQuery } = api
https://redux-toolkit.js.org/rtk-query/usage/customizing-queries#customizing-queries-with-queryfn” rel=“nofollow noreferer”/docs则,用于处理习惯错误,我们可以使用
1. 使用不同错误处理行为的一次性查询
因此,如果出于任何原因,你想提出错误要求,你可以做到:
getPokemon: build.query<Pokemon, string>({
async queryFn(name, api, extraOptions, baseQuery) {
const result = await baseQuery({
url: `https://pokeapi.co/api/v2/pokemon/${name}`,
method: GET
});
if (result.error?.status === 404) {
// don t refetch on 404
return { data: result.data as Pokemon };
}
if (result.error) {
// but refetch on another error
return { error: result.error };
}
return { data: result.data as Pokemon };
}
}),
你们需要定制你们的创造 复印机功能。 您可以停止永久地重新尝试,确定unstable__sideEffectsInRender 财产为假造
import {
buildCreateApi,
coreModule,
reactHooksModule,
} from @reduxjs/toolkit/dist/query/react ;
const createApi = buildCreateApi(
coreModule(),
reactHooksModule({ unstable__sideEffectsInRender: false })
);
export default createApi;
const{isError} = 使用质量;
if (isError) show error message else render the components.
在部件提供之前,通过使用Query检查遗嘱归还财产。 如果APICOR公司失败,那么Error就成为事实,那么部件就会落空,从而防止针对失败的情景提出多重的APIC申请。
2024年4月的答复: 您可以按行业条件调整:
import { Mutex } from async-mutex
import {
BaseQueryApi,
BaseQueryFn,
FetchArgs,
fetchBaseQuery,
FetchBaseQueryError,
retry,
} from @reduxjs/toolkit/query
import { RootState } from @common/store
import {
BaseQueryArg,
BaseQueryExtraOptions,
} from @reduxjs/toolkit/dist/query/baseQueryTypes
import { RetryOptions } from @reduxjs/toolkit/dist/query/retry
// HERE
const customRetryCondition = (
error: FetchBaseQueryError,
args: BaseQueryArg<BaseQueryFn>,
{
attempt,
extraOptions: { maxRetries } = {},
}: {
attempt: number
baseQueryApi: BaseQueryApi
extraOptions: BaseQueryExtraOptions<BaseQueryFn> & RetryOptions
},
) => {
// retry on default condition
const defaultCondition = attempt <= (maxRetries || 0)
if (defaultCondition) {
return true
}
// retry on network s errors
if (error.status === FETCH_ERROR || error.status === TIMEOUT_ERROR ) {
return true
}
// other case (application logic error), don t retry
return false
}
const baseQuery = retry(
fetchBaseQuery({
prepareHeaders: (headers, { getState }) => {
const {
userAuth: {
token: { accessToken },
},
} = getState() as RootState
const token = accessToken
if (token) {
headers.set( authorization , `Bearer ${token}`)
}
return headers
},
baseUrl,
}),
{
maxRetries: 5,
// HERE
retryCondition: customRetryCondition as unknown as undefined, // avoiding typescript error
},
)
This is my first question, and english is not my first language, sorry if my question is hard to understand I was trying to make simple CRUD app with mysql database and react as the frontend, and i ...
I have two react apps, parent app and child app. and child app have an hash router. I have build the child app using npm run build, It creates build folder. That build folder moved into inside the ...
这是我的第一个问题,请与我一起回答。 I m从事一项SPA React项目,该项目跟踪农场及其相关床位,并可使用一些帮助。 我愿就......提供一些数据。
I want to print the selected value, and below is my option list: const vesselName = [ { value: 0 , label: ALBIDDA , }, { value: 1 , label: ALRUMEILA , }, { value: 2 ,...
I have this custom filter for date , filter button is working as expected but reset button is not working, can anyone help me,what s wrong here? Below is my code which contain handlesearch,handlereset ...
I am using react. I want to add a line break <br> between strings No results and Please try another search term. . I have tried No results.<br>Please try another search term. but ...
I am trying to make a POC with Rails5, action Cable, React and Rails and React DnD. The purpose is to make an app like trello but for an recruitment process. My front is in ReactJS. I have 3 ...
- winforms
- combobox
- fogbugz
- java
- date
- internationalization
- asp.net
- iis
- url-rewriting
- urlrewriter
- c#
- enums
- ocaml
- haxe
- algorithm
- string
- viewstate
- .net
- c++
- c
- symbol-table
- mysql
- database
- postgresql
- licensing
- migration
- vb.net
- vb6
- declaration
- vb6-migration
- python
- psycopg2
- backup
- vmware
- virtualization
- gnu-screen
- authentication
- desktop
- excel
- xll
- cultureinfo
- regioninfo
- oracle
- client
- session
- download
- html
- virtual
- constructor
- scenarios
- perl
- full-text-search
- javascript
- ajax
- testing
- oop
- inheritance
- vim
- encapsulation
- information-hiding