Skip to content

Commit

Permalink
add useEffect hook for fetching recipe data
Browse files Browse the repository at this point in the history
- Implemented useEffect to fetch recipes from the API
- Fetched recipe data from 'https://dummyjson.com/recipes'
- Updated state with fetched recipes and handled potential errors
  • Loading branch information
KoketsoMoilwe20 committed Oct 21, 2024
1 parent 32d0155 commit 21eac74
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/components/RecipeGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,16 @@ import RecipeCards from './RecipeCards';
const RecipeGrid = () => {
const [recipes, setRecipes] = useState([]);

useEffect(() => {
const fetchRecipes = async () => {
try {
const response = await fetch('https://dummyjson.com/recipes');
const data = await response.json();
setRecipes(data.recipes);
} catch (error) {
console.error('Error fetching recipes:', error);
}
};

fetchRecipes();
}, []);

0 comments on commit 21eac74

Please sign in to comment.