I am using this right now, need to add a condition in such a way that whenever the getCartCount is 0 it should show image as bag_empty instead of bag and when the cart count is more than 0 it should show bag
JavaScript
x
11
11
1
<Badge count={getCartCount()}>
2
<img
3
className="bag__img"
4
src={bag}
5
alt=""
6
onClick={user ? handleOpenBag : handleDynamicLink}
7
onMouseOver={() => setbag(hoverbag)}
8
onMouseOut={() => setbag(cart)}
9
/>
10
</Badge>
11
Advertisement
Answer
You could use a ternary operator like below, assuming that you have your empty bag image in your public folder.
JavaScript
1
11
11
1
<Badge count={getCartCount()}>
2
<img
3
className="bag__img"
4
src={getCartCount()>0 ? bag : "/emty-bag-goes-here.png"}
5
alt=""
6
onClick={user ? handleOpenBag : handleDynamicLink}
7
onMouseOver={() => setbag(hoverbag)}
8
onMouseOut={() => setbag(cart)}
9
/>
10
</Badge>
11