notrab / react-use-cart

React hook library for managing cart state
http://npm.im/react-use-cart
Apache License 2.0
367 stars 48 forks source link

Uncaught TypeError: addItem is not a function #89

Closed japick-joules closed 3 years ago

japick-joules commented 3 years ago

Next.js version 11.0.1 React version 17.0.2

Code ([handle].tsx):

import { useCart } from "react-use-cart"

export default function Product() {
  const { addItem } = useCart()

  ...

  <button onClick={() => addItem({p.id})}>Add to bag</button>
}

When clicking the Add to bag button Next throws the following error:

Unhandled Runtime Error
TypeError: addItem is not a function
japick-joules commented 3 years ago

Closing as fixed.

The app wasn't wrapped inside the CartProvider component.

All good now, thanks!