Created
January 4, 2022 12:51
-
-
Save Chojiu15/95ff4423a22f3e1b5f30a2439fc9ae4f to your computer and use it in GitHub Desktop.
Recipes.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import './App.css'; | |
import {useState, useEffect} from 'react' | |
import {client} from './client' | |
function App() { | |
const [recipes, setRecipes] = useState([]) | |
useEffect(() => { | |
fetchContentful() | |
}, []) | |
const fetchContentful = () => { | |
client.getEntries() | |
.then(response => setRecipes(response.items)) | |
} | |
console.log(recipes) | |
return ( | |
<div className="App"> | |
{recipes.map(recipe => { | |
return( | |
<> | |
<h1>{recipe.fields.title}</h1> | |
<img src={recipe.fields.image.fields.file.url} height="100px" width='100px'/> | |
{recipe.fields.ingredients.map(ingredient => { | |
return( | |
<ul> | |
<li>{ingredient}</li> | |
</ul> | |
) | |
})} | |
</> | |
) | |
})} | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment