Added use-cart-actions hook

This commit is contained in:
Luis Alvarez 2020-10-05 21:57:38 -05:00
parent 24f6ff792a
commit 21d5a8ea57
2 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,13 @@
import useAddItem from './use-add-item'
import useRemoveItem from './use-remove-item'
import useUpdateItem from './use-update-item'
// This hook is probably not going to be used, but it's here
// to show how a commerce should be structuring it
export default function useCartActions() {
const addItem = useAddItem()
const updateItem = useUpdateItem()
const removeItem = useRemoveItem()
return { addItem, updateItem, removeItem }
}

View File

@ -0,0 +1,16 @@
import type { Fetcher } from '..'
import useAddItem from './use-add-item'
import useRemoveItem from './use-remove-item'
import useUpdateItem from './use-update-item'
// This hook is probably not going to be used, but it's here
// to show how a commerce should be structuring it
export default function useCartActions<T, Input>(
fetcher: (fetch: Fetcher<T>, input: Input) => T | Promise<T>
) {
const addItem = useAddItem<T, Input>(fetcher)
const updateItem = useUpdateItem<T, Input>(fetcher)
const removeItem = useRemoveItem<T, Input>(fetcher)
return { addItem, updateItem, removeItem }
}