I'm doing a recipe project and I want the user to add a recipe.
I'll add data via input but I cannot make any changes on "video URL" and "ingCount" inputs. I do not understand why this is so. Other inputs work fine and they work smoothly..
I just can't enter values into ingCount and videoLink.
*** Their names on the API are also correct.
const [addRecipe, setAddRecipe] = useState({
id: "",
title: "",
description: "",
image: "",
category: "",
time: 0,
ingCount: 0,
servings: 0,
videoLink: "",
ingredients: "",
makeDetails: ""
})
const handleChange = (e) => {
setAddRecipe({
id: Math.random() * 100,
...addRecipe,
[e.target.name]: e.target.value
})
}
const handleSubmit = (e) => {
e.preventDefault()
setRecipes([...recipes, addRecipe])
axios
.post(
"https://5fccb170603c0c0016487102.mockapi.io/api/recipes",
addRecipe
)
.then((res) => {
console.log(res)
})
.catch((err) => {
console.log(err)
})
setAddRecipe(addRecipe)
console.log(handleSubmit)
}
<form onSubmit={handleSubmit}>
<div>
<input
type="text"
name="title"
value={addRecipe.title}
onChange={handleChange}
placeholder="baslik giriniz"
/>
</div>
<div>
<input
type="text"
name="description"
value={addRecipe.description}
onChange={handleChange}
placeholder="tarif aciklamasi"
/>
</div>
<div>
<input
type="text"
name="category"
value={addRecipe.category}
onChange={handleChange}
placeholder="kategori"
/>
</div>
<div>
<input
type="number"
name="time"
value={addRecipe.time}
onChange={handleChange}
placeholder="süre"
/>
</div>
<div>
<input
type="number"
name="malzeme"
value={addRecipe.ingCount}
onChange={handleChange}
placeholder="malzeme sayısı"
/>
</div>
<div>
<input
type="number"
name="servings"
value={addRecipe.servings}
onChange={handleChange}
placeholder="kişilik"
/>
</div>
<div>
<input
type="text"
name="ingredients"
value={addRecipe.ingredients}
onChange={handleChange}
placeholder="malzemeler"
/>
</div>
<div>
<input
type="text"
name="makeDetails"
value={addRecipe.makeDetails}
onChange={handleChange}
placeholder="yapilisi"
/>
</div>
<div>
<input
type="text"
name="image"
value={addRecipe.image}
onChange={handleChange}
placeholder="resim"
/>
</div>
<div>
<input
type="text"
name="video"
value={addRecipe.videoLink}
onChange={handleChange}
placeholder="video"
/>
</div>
<button className="todoform__btn" type="submit">
Tarifi ekle!
</button>
</form>
