diff --git a/.changeset/calm-hotels-move.md b/.changeset/calm-hotels-move.md new file mode 100644 index 00000000..4f1b9245 --- /dev/null +++ b/.changeset/calm-hotels-move.md @@ -0,0 +1,9 @@ +--- +"@elasticpath/react-shopper-hooks": minor +--- + +- add product list example +- add product now takes optional params +- remove params for use delete cart query +- allow select query function +- make add product include params dynamic diff --git a/packages/react-shopper-hooks/example/App.tsx b/packages/react-shopper-hooks/example/App.tsx index e6ce02c8..e181cb80 100644 --- a/packages/react-shopper-hooks/example/App.tsx +++ b/packages/react-shopper-hooks/example/App.tsx @@ -4,30 +4,48 @@ import CartExample from "./CartExample" import { CartProvider } from "../src/cart" import { gateway as EPCCGateway } from "@moltin/sdk" import { StoreProvider } from "../src/store" +import { ElasticPathProvider } from "../src" +import { QueryClient } from "@tanstack/react-query" +import { ProductListExample } from "./ProductListExample" + +const client = EPCCGateway({ + name: "my_store", + client_id: import.meta.env.VITE_APP_EPCC_CLIENT_ID, + client_secret: import.meta.env.VITE_APP_EPCC_CLIENT_SECRET, + host: import.meta.env.VITE_APP_EPCC_HOST, +}) + +const queryClient = new QueryClient() function App() { - const client = EPCCGateway({ - name: "my_store", - client_id: import.meta.env.VITE_APP_EPCC_CLIENT_ID, - client_secret: import.meta.env.VITE_APP_EPCC_CLIENT_SECRET, - host: import.meta.env.VITE_APP_EPCC_HOST, - }) + const [activeItem, setActiveItem] = React.useState<"cart" | "products">( + "cart", + ) return (

React Shopper Hooks

+
+ + +
- client.Cart().cartId} + queryClientProviderProps={{ client: queryClient }} > - client.Cart().cartId}> - - - + + + {activeItem === "cart" && } + {activeItem === "products" && } + + +
) } +function TanstackWrapper() {} + export default App diff --git a/packages/react-shopper-hooks/example/CartExample.tsx b/packages/react-shopper-hooks/example/CartExample.tsx index b2a8e046..5b30d9cb 100644 --- a/packages/react-shopper-hooks/example/CartExample.tsx +++ b/packages/react-shopper-hooks/example/CartExample.tsx @@ -1,16 +1,19 @@ import React from "react" -import { useCart } from "../src/cart" +import { useCart, useCartAddBundleItem, useCartClear } from "../src/cart" export default function CartExample(): JSX.Element { - const { state, addBundleProductToCart, emptyCart } = useCart() + const { state } = useCart() + const { mutate: addBundleProductToCart } = useCartAddBundleItem() + const { mutate: emptyCart } = useCartClear() return ( <>