react-basket
A shopping basket components library for React based on material-ui components.
Key features
- Shopping Cart Component
- Realtime shopping cart support
- Connect to shopping cart data anywhere in app
Demo
You can access the demo page from demo site.
If you have any sort of doubt, idea or just want to talk about the project, feel free to join our chat on Gitter :)
Installation
npm install react-basket
Usage
1. Implement a DataProvider
; implements DataProvider // You can call callback functions if you socket.io/pusher or something like it. products = id: "1" name: 'Computer' price: 172244 quantity: 1 id: "2" name: 'Phone' price: 52214 quantity: 1 ; items = id: "1" name: 'Computer' price: 172244 quantity: 1 id: "2" name: 'Phone' price: 52214 quantity: 2 ; getInitialData = : Promise<BasketItem> return <BasketItem> { }; : Promise<BasketItem> return <BasketItem> { }; : Promise<BasketItem> return <BasketItem> { }; onItemDeleted = id: string: Promise<BasketItem> return <BasketItem> { };
I used Typescript, but you can use pure javascript.
2. Adding Basket Provider to app
You should add BasketProvider component in root of your application with a data provider implementation.
Component { const classes = thisprops; return <BasketProvider dataProvider=> <div> your all components will be here </div> </>BasketProvider> ; }
3. Use Basket component
It connects to BasketProvider and take data from it.
; <Basket />
4. Connect to basket data anywhere
;;; const MyComponent = <IconButton color="inherit"> <Badge badgeContent=propsbasketDataitemslength color="secondary"> <ShoppingCart /> </Badge> </IconButton> MyComponent;
Licence
This project is licensed under the terms of the MIT license.