【发布时间】:2021-11-04 12:06:50
【问题描述】:
我使用带有queryFn 而不是query 的端点来执行许多请求。有没有办法调用已经定义的端点而不是使用 fetchWithBQ ?
这是一个例子。
export const api = createApi({
reducerPath: "api",
baseQuery: fetchBaseQuery({
baseUrl: "url",
}),
endpoints: (builder) => {
return {
device: builder.query<Device, string>({
query: (id) => `devices/${id}`, // repeat 1
}),
deployments: builder.query<Deployment[], string>({
queryFn: async (arg, _api, _extraOptions, fetchWithBQ) => {
// I would preferred to call the device endpoint directly.
// It will prevent to repeat the url and get cached data.
const result = await fetchWithBQ(`devices/${arg}`); // repeat 2
return ...
},
}),
};
},
});
【问题讨论】:
标签: reactjs redux react-redux redux-toolkit rtk-query