adrianhajdin / ecommerce_sanity_stripe

Modern Full Stack ECommerce Application with Stripe
https://jsmastery.pro
2.21k stars 674 forks source link

const { decQty, incQty, qty, onAdd, setShowCart } = useStateContext(); these variables are undefined in the slug.js file. On printing useStateContext() on console it shows the default value() #97

Open muskan-Bansal opened 1 year ago

HameedAsmath commented 1 year ago

No description provided.

make sure that you implemented th context correctly and dont forget to enclose all the components in _app.js with your context

muskan-Bansal commented 1 year ago

it works if wrap it in _app.js file in a way that stateContext binds only component and not from the layout

But now the problem is functions we passed in the context api like incQty doesnt change the state of qty on click

Could you please tell me what exactly is going wrong

HameedAsmath commented 1 year ago

So you are saying that context works well but it doesn't change the state. May I know how are you checking that state is not updated ? Are you using console.log(qty)?