像这个例子:constructing-a-dynamic-base-url-using-redux-state,我需要从缓存中获取某个端点的数据来构建fetch arg,我可以通过 获取数据api.endpoints.getPost.select(postId)(getState())
,但是我如何确保getPost 请求已发送?
const api = createApi({
baseQuery: fetchBaseQuery(),
endpoints: (builder) => ({
getPost: builder.query({
query: (id) => `/posts/${id}`,
}),
getBook: builder.query({
async queryFn(postId, { dispatch, getState }) {
// could I use this?
await dispatch(api.endpoints.getPost.initiate(postId))
const { data: post } = api.endpoints.getPost.select(postId)(getState())
// ...
// use post.xxx to fetch books...
myFetch(`/books/${post.xxx}`)
},
}),
}),
})