Skip to content

Commit 9339f0a

Browse files
committed
refactor: item quantity button
1 parent d26b36f commit 9339f0a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/components/shop/Counter.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import PropTypes from "prop-types";
22

33
function Counter({ className, setCount, count }) {
4+
const increment = () => setCount((prevCount) => prevCount + 1);
5+
const decrement = () =>
6+
setCount((prevCount) => (prevCount > 1 ? prevCount - 1 : prevCount));
7+
console.log(count)
48
return (
59
<div className={`flex rounded-lg ${className}`}>
610
<button
711
type="button"
812
data-action="decrement"
913
className="cursor-pointer outline-none w-20 border-y border-l border-l-[#EAECF0] border-y-[#EAECF0] rounded-l-md border-r"
10-
onClick={() => setCount(count > 1 ? count - 1 : 1)}
14+
onClick={decrement}
1115
>
1216
<span className=" text-base"></span>
1317
</button>
@@ -21,7 +25,7 @@ function Counter({ className, setCount, count }) {
2125
type="button"
2226
data-action="increment"
2327
className="cursor-pointer outline-none w-20 border-y border-r border-r-[#EAECF0] border-y-[#EAECF0] rounded-r-md border-l"
24-
onClick={() => setCount(count + 1)}
28+
onClick={increment}
2529
>
2630
<span className="text-base">+</span>
2731
</button>

0 commit comments

Comments
 (0)