Im pretty new to react (i have only worked with classes abit) and I want to add my input values to foodList
and write them out on the screen but my brain is locked and i cant figure out how...
Any tips would help, thanks!
import React, {useState, useEffect} from 'react';
const Form = () => {
const [recipe, setRecipe] = useState("");
const [ingrediens, setIngrediens] = useState("");
const [foodList, setFoodList] = useState([])
const handleChange = event => {
setIngrediens({[event.target.name]: event.target.value})
setRecipe({[event.target.name]: event.target.value})
}
const handleClick = event => { // Here is where i get problem
}
return (
<main>
<button onClick={handleClick}>add</button>
<div className="form">
<input type="text" placeholder="Enter your recipe" name="recipe" onChange={handleChange} ></input>
<input type="text" placeholder="Enter your ingrediens" name="ingrediens" onChange={handleChange} ></input>
</div>
<div className="results">
<ul>
{foodList.map(i => (
<li key={i}> {recipe} <p> {ingrediens} </p> </li>
))}
</ul>
</div>
</main>
)
}
export default Form;