import { useParams } from "react-router-dom"; import { useState, useEffect } from "react"; import { getRecipeById } from "../services/frontendApi.js"; import { type Recipe, type Ingredient } from "../types/Recipe" function RecipePage() { const [recipe, setRecipe] = useState({ details: {}, ingredients: [], steps: {} }); const [error, setError] = useState(null); const [loading, setLoading] = useState(true); const { id } = useParams(); useEffect(() => { const loadRecipe = async () => { try { const recipe = await getRecipeById(id); setRecipe(recipe); console.log(recipe) } catch (error) { console.log(error); setError("Failed to load recipes..."); } finally { setLoading(false); } }; loadRecipe(); }, [id]); console.log(recipe) return (
{error &&
{error}
} {loading ? (
Loading...
) : (

{recipe.details.name}

{recipe.details.cuisine}

Ingredients:

    {recipe.ingredients.map((ingredient: Ingredient, index) => (
  • {ingredient.quantity} {ingredient.unit} {ingredient.name}
  • ))}

Instructions:

    {recipe.steps && Object.keys(recipe.steps || {}).map((stepNumber) => (
  1. {stepNumber} {recipe.steps[parseInt(stepNumber)]}
  2. ))}
From the Kitchen of ★ ★ ★
)}
); } export default RecipePage;