私は RTK に移行し、これまでのところ非常に楽しんでいますが、次のような状況で行き詰まりました。
(簡単にするために) 2 つのエンドポイントがあります。
- www.domain-customer.com <- 顧客データの取得
- www.domain-order.com <- ここで一部のユーザー データを変更できます
また、Web サイト自体は別のドメインでホストされています。
顧客エンドポイントからデータをフェッチする必要がありますが、特定のものを更新するには、注文エンドポイントに変更を加える必要があります。最初は、ベース URL ごとに createApi を定義する必要があると考えていましたが、無効にすることはできないと確信しています。新しいデータが再フェッチされるように、この以前のミューテーションで顧客のデータを無効にしたいと考えています。
これが私が思いついたものですが、これが前進する方法である場合は、いくつかの意見をお願いします.
export const customerApi = createApi({
reducerPath: "/../",
baseQuery: fetchBaseQuery({ baseUrl: "https://www.domain-customer.com/" }),
endpoints: (builder) => ({
// write provides tag stuff here
getCustomerExample: builder.query({ query: (name) => `customer/${name}` }),
// please ignore the details of the mutation, I haven't practiced much with it yet.
updateCustomer: builder.mutation({
queryFn: async (name) => {
const response = await fetch(
`https://www.domain-order.com/updateCustomer`,
{update mutation stuff here}
);
const data = await response.json();
return { data };
}
// write invalidate stuff here
})
})
});
これはそれについて行く方法ですか?それとも、すべてのミューテーションとクエリを保持する巨大な createAPI が存在する必要がありますか?