This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import './CheckoutProduct.css' | |
import { useStateValue } from "./StateProvider"; | |
function CheckoutProduct({ id, image, title, price, rating, hideButton }) { | |
const [{ basket }, dispatch] = useStateValue(); | |
const removeFromBasket = () => { | |
// remove the item from the basket | |
dispatch({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const initialState = { | |
basket: [], | |
user: null | |
}; | |
// Selector | |
export const getBasketTotal = (basket) => | |
basket?.reduce((amount, item) => item.price + amount, 0); | |
const reducer = (state, action) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import "./Product.css"; | |
import { useStateValue } from "./StateProvider"; | |
function Product({ id, title, image, price, rating }) { | |
const [{ basket }, dispatch] = useStateValue(); | |
const addToBasket = () => { | |
// dispatch the item into the data layer | |
dispatch({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import "./Home.css"; | |
import Product from "./Product"; | |
function Home() { | |
return ( | |
<div className="home"> | |
<div className="home__container"> | |
<img | |
className="home__image" |