我是 Redux 和 RTK 查询的新手,我不明白当另一个端点的响应成功时如何从另一个端点获取数据。
我创建了一个这样的 API:
import { Config } from '@/Config'
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
const baseQuery = fetchBaseQuery({ baseUrl: Config.API_URL })
const baseQueryWithInterceptor = async (args, api, extraOptions) => {
let result = await baseQuery(args, api, extraOptions)
if (result.error && result.error.status === 401) {
// Deal with unauthorised
}
return result
}
export const api = createApi({
baseQuery: baseQueryWithInterceptor,
endpoints: () => ({}),
})
Run Code Online (Sandbox Code Playgroud)
我为每种资源都有一个模块,例如:
// /modules/matches
import { api } from '../../api'
import …Run Code Online (Sandbox Code Playgroud) refetch为什么当我在下面的代码中使用方法时,值在获取期间isLoading不会返回?true
const [matchFilterSelected, setMatchFilterSelected] = useState('explorer')
// Query declaration
const {
data: matches,
refetch,
error: matchesError,
isLoading: matchesIsLoading,
} = useFetchMatchesQuery(matchFilterSelected)
// Callback function from onPress event
const filterSelectedChanged = (matchesType) => {
if (matchesType && matchesType !== matchFilterSelected) {
setMatchFilterSelected(matchesType)
refetch()
}
}
Run Code Online (Sandbox Code Playgroud)