@brand-map/redux-client
v0.0.10-alpha.34
Published
Brand-Map RTK Query client helpers.
Downloads
1,200
Readme
Redux Client
RTK Query endpoint injectors for the Brand-Map TypeScript SDK.
Configure
import { BrandMapClient } from "@brand-map/ts-client"
import { configureBrandMapReduxClient } from "@brand-map/redux-client"
export const brandMapClient = new BrandMapClient({
baseUrl: process.env.EXPO_PUBLIC_API,
})
configureBrandMapReduxClient(brandMapClient)Inject Endpoints
import { api } from "@/utils/rtkq/api"
import { createStoreProductHooks, injectStoreProductEndpoints } from "@brand-map/redux-client/store/product"
export const productApi = injectStoreProductEndpoints(api)
export const {
useListProductsQuery,
useGetProductQuery,
useListProductVariantsQuery,
} = createStoreProductHooks(productApi)Use Queries
const { data, isFetching, error } = useListProductsQuery({
query: {
fields: ["id", "title", "thumbnail"] as const,
populate: {
variants: {
fields: ["id", "sku"] as const,
},
},
},
})
data?.[0]?.id
data?.[0]?.title
data?.[0]?.variants?.[0]?.skuUse Mutations
const [createProduct, createProductState] = useCreateProductMutation()
const created = await createProduct({
body: { title: "New product" },
query: {
fields: ["id", "title"] as const,
},
}).unwrap()
created.id
created.titleWrapper hooks preserve field/populate/sort inference. Native RTK Query hooks are still available on the injected API using globally unique internal endpoint names.
