Basically I want to reset my quantity to 1 if equal to 0 or less. I understand I need more validation too but this is the first requirement. This this just keep resetting as soon as I start typing which is obvious
Product.component.js
import { useState, useEffect } from "react";
const Product = () => {
const [qty, setQty] = useState(1);
useEffect(() => { }, [qty]);
const handleChange = (currentQty) => {
if (currentQty > 0) {
console.log("ok");
//Do Somethong
} else {
setQty(1);
}
};
return (
<input type="text" value={qty} onChange={(e) => handleChange(e.target.value)} />
);
};
export default Product;