import { getRecipeIngredients } from "../services/frontendApi.js"; import { useState, useEffect } from "react"; import { type Ingredient } from "../types/Recipe.ts" function RecipeIngredients() { const [recipeIngredients, setRecipeIngredients] = useState([]); const [error, setError] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { const loadRecipeIngredients = async () => { try { const recipeIngredients = await getRecipeIngredients(); setRecipeIngredients(recipeIngredients); console.log(recipeIngredients) } catch (err) { console.log(err); setError("Failed to load recipe ingredients..."); console.log(error) } finally { setLoading(false); } }; loadRecipeIngredients(); }, []); console.log(recipeIngredients) return ( // should this be a string[]? only if we are only returning raw. otherwise i will need to type and return the ingredient object. This template shoudl work for steps though, so maybe setting that up is a good first step
{loading ? (
Loading...
) : (
{recipeIngredients.map(ing => (
  • {ing.raw}
  • ))}
    )}
    ) } export default RecipeIngredients