I am trying to update the input value. It's working fine, it's updating its value. However, there is a problem, when it's updated its value, it's converting to string from number. I have already tried with Number, parseInt, it does not work. it always converts to string.
import React from 'react';
import useForm from '../lib/useForm';
const CreateProduct = () => {
const { input, handleChange } = useForm({
name: 'mama',
price: 0,
});
return (
<form>
<label htmlFor="price">
Price
<input
type="number"
id="price"
name="price"
placeholder="Price"
value={parseInt(input.price)}
onChange={handleChange}
/>
</label>
</form>
);
};
export default CreateProduct;
and here in the custom function:
import * as React from 'react';
export default function useForm(initialValue = {}) {
const [input, setInput] = React.useState(initialValue);
function handleChange(event) {
const { name, value } = event.target;
setInput({
...input,
[name]: value,
});
}
return {
input,
handleChange,
};
}

