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

Support global cart metadata #58

Closed notrab closed 3 years ago

notrab commented 3 years ago

Similar to what happens with CartQL, it would be good to support a updateCart function that allows you to set global metadata on the cart.

This can be helpful for tracking any order notes, coupon codes, etc.

Example:

const { updateCart } = useCart()

updateCart({
  coupon: 'FREESHIPPING'
})

The only thing that would need decided is how to access this. I'd prefer to namespace this under metadata, so you'd be able to do:

function () {
  const { metadata } = useCart()

  return (
    <p>{metadata.coupon}</p>
  )
}
notrab commented 3 years ago

What should we call this function?

🚀 for updateCart 🎉 for updateCartMeta 👀 for updateCartMetadata

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 1.11.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: