react-ecommerce-hook
A basic shopping cart react hook, it uses localStorage to persist data
Note: This is using the new React Hooks API Proposal which is subject to change until React 16.8 final.
You'll need to install
react
andreact-dom
at^16.8.0-alpha.0
Install
yarn add react-ecommerce-hook
Examples
Product
import React from 'react';import useCart from 'react-ecommerce-hook'; const Product = id const addToCart removeFromCart increaseQuantity decreaseQuantity = ; return <div> <h1>Awesome Product</h1> /* if item is unique, its maximum quantity is 1 */ <button => Add To Cart Unique Product </button> <button => Add To Cart </button> <button => Remove From Cart </button> <button => Increase Quantity </button> <button => Decrease Quantity </button> </div> ;}
Cart
import React from 'react';import useCart from 'react-ecommerce-hook'; const Cart = const state: addedIds quantityById = ; return <div> addedIds </div> ;}
API