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 the getPost request has been sent?
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}`)
},
}),
}),
})