2.1.1 • Published 1 year ago
carrito-de-compras v2.1.1
Carrito de compras by @jhangmez
Hook de React para administrar un carrito de compras, optimizado para aplicaciones Next.js App router. React hook for managing a shopping cart, optimized for Next.js App router applications.
Installation
npm install carrito-de-comprasUsage
- Wrap your app with the
CarritoProvider:
import { CarritoProvider } from 'carrito-de-compras'
function App() {
return (
<CarritoProvider>
{children} {/* Your app here */}
</CarritoProvider>
)
}- Use the
useCarritohook in your components:
import { useCarrito } from 'carrito-de-compras'
function MyComponent() {
const { addItem, removeItem, getItemCount, getTotalPrice } = useCarrito()
// Use the shopping cart features here
}API
addItem(id: number, quantity: number): Add an item to the cartremoveItem(id: number): Remove an item from the cartupdateQuantity(id: number, quantity: number): Update the quantity of an itemclearCart(): Clear all items from the cartgetItems(): Get all items in the cartgetItemCount(): Get the total number of items in the cartgetTotalPrice(getPriceById: (id: number) => number): Calculate the total price of the cart
Contribute
Contributions are welcome. Please open an issue or pull request for suggestions or improvements.
License
MIT