I am struggling to find a way to pass my key to the root div of my return statement
const [recipes, setRecipes] = useState([]);
const [search, setSearch] = useState("");
const [query, setQuery] = useState("chicken");
useEffect(() => {
getRecipes();
}, [query]);
const getRecipes = async () => {
const response = await fetch(`https://api.edamam.com/search?q=${query}&app_id=${App_ID}&app_key=${App_Key}`);
const data = await response.json();
setRecipes(data.hits);
console.log(data.hits);
}
const updateSearch = e => {
setSearch(e.target.value);
console.log(search);
};
const getSearch = e => {
e.preventDefault();
setQuery(search);
setSearch("")
};
return(
<div className="App">
<form onSubmit={getSearch} className="search-form">
<input
className="search-bar"
type="text" value={search}
onChange={updateSearch}
placeholder="Find a recipe" />
<button className="search-button" type="submit">
Search
</button>
</form>
<div className="recipes">
{recipes.map(recipe => (
<Recipe
title={recipe.recipe.label}
calories={Math.round(recipe.recipe.calories)}
image={recipe.recipe.image}
ingredients={recipe.recipe.ingredients}/>
))}
</div>
</div>
);
When I only pass the key to the Recipe component, I get the error "Each child in a list should have a unique "key" prop."
I assume this means that I need to pass the key to the div with className "App". How do I do that without passing the map function around the entire return statment?