You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

29 lines
712 B

  1. import React from 'react'
  2. import Link from 'next/link'
  3. import { useToasts } from 'react-toast-notifications'
  4. import { useDispatch } from 'react-redux'
  5. const AddToCartBtn = ({ id }) => {
  6. // console.log(id)
  7. const { addToast } = useToasts()
  8. const dispatch = useDispatch()
  9. const addToCart = () => {
  10. dispatch({
  11. type: 'ADD_TO_CART',
  12. id
  13. })
  14. addToast('Cart Added Successfully', { appearance: 'success' })
  15. }
  16. return (
  17. <Link href="#">
  18. <a onClick={e => {
  19. e.preventDefault();
  20. addToCart()
  21. }} className="add-to-cart-btn">Add to Cart</a>
  22. </Link>
  23. )
  24. }
  25. export default AddToCartBtn