10 - "What Should I Eat?" Random Recipe Generator
Description
Algorithm
Classes
Code
import React, { useState, useEffect } from 'react';
function RecipeGenerator() {
const [recipe, setRecipe] = useState(null);
const handleGenerateRecipe = () => {
fetch('<receipe-url>')
.then(response => response.json())
.then(data => setRecipe(data));
};
return (
<div>
<button onClick={handleGenerateRecipe}>What should I eat?</button>
{recipe && (
<div>
<h2>{recipe.name}</h2>
<p>Ingredients:</p>
<ul>
{recipe.ingredients.map(ingredient => (
<li key={ingredient}>{ingredient}</li>
))}
<p>Instructions:</p>
<ol>
{recipe.instructions.map(instruction => (
<li key={instruction}>{instruction}</li>
))}
</ol>
</div>
)}
</div>
);
}
export default RecipeGenerator;
Explanation
Possible Future Enhancements
Last updated