docs: generate medusa-react reference (#6004)

* add new plugin for better organization

* added handling in theme for mutations and query types

* added tsdoc to hooks

* added tsdocs to utility functions

* added tsdoc to providers

* generated reference

* general fixes for generated reference

* generated api reference specs + general fixes

* add missing import react

* split utilities into different directories

* added overview page

* added link to customer authentication section

* fix lint errors

* added changeset

* fix readme

* fixed build error

* added expand fields + other sections to overview

* updated what's new section

* general refactoring

* remove unnecessary query field

* fix links

* added ignoreApi option
This commit is contained in:
Shahed Nasser
2024-01-05 17:03:38 +02:00
committed by GitHub
parent 6fc6a9de6a
commit 7d650771d1
2811 changed files with 231856 additions and 455063 deletions
@@ -475,10 +475,17 @@ To create a line item of a product and add it to a cart, you can use the followi
const createLineItem = useCreateLineItem(cart_id)
const handleAddItem = () => {
const handleAddItem = (
variantId: string,
quantity: amount
) => {
createLineItem.mutate({
variant_id,
variant_id: variantId,
quantity,
}, {
onSuccess: ({ cart }) => {
console.log(cart.items)
}
})
}
@@ -549,10 +556,17 @@ To update a line item's quantity in the cart, you can use the following code sni
const updateLineItem = useUpdateLineItem(cart_id)
const handleUpdateItem = () => {
const handleUpdateItem = (
lineItemId: string,
quantity: number
) => {
updateLineItem.mutate({
lineId,
quantity: 3,
lineId: lineItemId,
quantity,
}, {
onSuccess: ({ cart }) => {
console.log(cart.items)
}
})
}
@@ -614,9 +628,15 @@ To delete a line item from the cart, you can use the following code snippet:
const deleteLineItem = useDeleteLineItem(cart_id)
const handleDeleteItem = () => {
const handleDeleteItem = (
lineItemId: string
) => {
deleteLineItem.mutate({
lineId,
lineId: lineItemId,
}, {
onSuccess: ({ cart }) => {
console.log(cart.items)
}
})
}
@@ -253,22 +253,30 @@ Once the customer chooses one of the available shipping options, send a `POST` r
```tsx
import { useAddShippingMethodToCart } from "medusa-react"
// ...
const ShippingOptions = ({ cartId }: Props) => {
// ...
type Props = {
cartId: string
}
const Cart = ({ cartId }: Props) => {
const addShippingMethod = useAddShippingMethodToCart(cartId)
const handleAddShippingMethod = (option_id: string) => {
const handleAddShippingMethod = (
optionId: string
) => {
addShippingMethod.mutate({
option_id,
option_id: optionId,
}, {
onSuccess: ({ cart }) => {
console.log(cart.shipping_methods)
}
})
}
// ...
}
export default ShippingOptions
export default Cart
```
</TabItem>