My DaisyUI button is not firing onClick function

I was trying to make a button which add a product in my cart. But the button is sometimes firing the onClick or sometimes it doesn't I can't understand the exact reason Here's my code:
<button
className="btn btn-primary"
onClick={() => dispatch(cartSlice.actions.addToCart(product))}
>
Add to cart
</button>
<button
className="btn btn-primary"
onClick={() => dispatch(cartSlice.actions.addToCart(product))}
>
Add to cart
</button>
5 Replies
mahdi_murshed12
mahdi_murshed1217mo ago
Try putting a console.log inside the onClick and check the log is there after clicking.
ديان
ديانOP17mo ago
sometimes works or sometimes doesnt Same for the dispatch
mahdi_murshed12
mahdi_murshed1217mo ago
Can you show me the whole component?
ديان
ديانOP17mo ago
okay
ديان
ديانOP17mo ago
Pastebin
"use client";import { useDispatch, useSelector } from "react-redux"...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Want results from more Discord servers?
Add your server