I have done this a million time and never had this problem and i don't know what i am doing wrong.
I have a simple input field and have a hook useState
of amount
and setAmount
and I am using handleChange
function to update this but the handleChange
function is not triggering
const CustomAmount = () => {
const [amount, setAmount] = useState(1);
const handleChange = (e) => {
console.log(e); // This is not working either
setAmount(e.target.value);
};
return (
<div className="custom-amount-container">
<h4>Enter your desired amount</h4>
<input
type="number"
name="custom-amount"
data-test="custom-amount-input"
value={amount}
onChange={handleChange}
/>
</div>
);
};
I tried putting it inside the onChange
prop directly but still no luck and also normally if onChange
function doesn't work it doesn't change value but in this case value is being changed inside the input field
Also I am using this component inside sweetalert
modal
const customAmountModal = () => {
return swal(<CustomAmount />);
};