# cart-it

> A custom hook for managing a shopping cart using only the localStorage feature of web browsers.

Latest version **1.0.2** (published 2023-07-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install cart-it
pnpm add cart-it
yarn add cart-it
bun add cart-it
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2023-07-07 |
| First published | 2023-07-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Zack Dx |
| Maintainers | zack16 |
| Keywords | react, hooks, shopping, cart |

## Links

- npm: https://www.npmjs.com/package/cart-it
- Repository: https://github.com/Zack-Dx/use-cart
- Homepage: https://github.com/Zack-Dx/use-cart#readme
- Issues: https://github.com/Zack-Dx/use-cart/issues
- npm.io page: https://npm.io/package/cart-it

## Dependencies (1)

- [react](https://npm.io/package/react.md) ^16.0.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2023-07-07
- 1.0.1 — 2023-07-06
- 1.0.0 — 2023-07-06

## README

# Cart-it

Cart-it is a custom React hook for managing a shopping cart using only the localStorage feature of web browsers.

## Installation

To install Cart-it, use the following command:

```javascript
npm install cart-it

```

## Functions

addToCart(item: any):
Adds an item to the cart.
(item: The item to add to the cart.)

removeFromCart(item: any):
Removes an item from the cart.
(item: The item to remove from the cart.)

# Usage

Import the useCart hook in your React component and start using it to manage your cart state.

```javascript
import React from 'react';
import useCart from 'cart-it';

function MyComponent() {
  const [cart, addToCart, removeFromCart] = useCart();

  // Use the cart, addToCart, and removeFromCart functions as needed

  return (
    // JSX code for your component
  );
}

```

# Example

```javascript
import React from "react";
import useCart from "cart-it";

function MyComponent() {
  const [cart, addToCart, removeFromCart] = useCart();

  const handleAddToCart = () => {
    const item = { id: 1, name: "Product 1", price: 10 };
    addToCart(item);
  };

  const handleRemoveFromCart = () => {
    const item = { id: 1, name: "Product 1", price: 10 };
    removeFromCart(item);
  };

  return (
    <div>
      <button onClick={handleAddToCart}>Add to Cart</button>
      <button onClick={handleRemoveFromCart}>Remove from Cart</button>
      <ul>
        {cart.map((item) => (
          <li key={item.id}>{item.name}</li>
        ))}
      </ul>
    </div>
  );
}
```

## License

Cart-it is open source software licensed under the MIT license.

---
_Source: https://npm.io/package/cart-it · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
