Package Exports
- carrito-de-compras
- carrito-de-compras/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (carrito-de-compras) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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-react';
function MiComponente() {
const { addItem, removeItem, getItemCount, getTotalPrice } = useCarrito();
// Use the shopping cart features here
}
## API
- `addItem(id: number, quantity: number)`: Add an item to the cart
- `removeItem(id: number)`: Remove an item from the cart
- `updateQuantity(id: number, quantity: number)`: Update the quantity of an item
- `clearCart()`: Clear all items from the cart
- `getItems()`: Get all items in the cart
- `getItemCount()`: Get the total number of items in the cart
- `getTotalPrice(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
---
## Carrito de compras by [@jhangmez](https://github.com/jhangmez)
<div style="display: flex; align-items: center; height: fit-content;">
<img src="https://avatars.githubusercontent.com/u/60937214?v=4" width="40" style="margin-right: 10px;"/>
<span>Hecho con ❤️ por Jhan Gómez P.</span>
</div>