Fetch kész
This commit is contained in:
1 parent
237750bfef
commit
18bccaebe9
2 files changed
+13
-3
No files matched your search
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
function Coffee({ coffee }) {
|
function Coffee({ coffee }) {
|
||||||
return (
|
return (
|
||||||
<div className="card w-96 bg-blue-200 card-md shadow-sm">
|
<div className="card w-96 bg-blue-200 card-md shadow-sm m-2">
|
||||||
<div className="card-body">
|
<div className="card-body">
|
||||||
<h2 className="card-title">{coffee.name}</h2>
|
<h2 className="card-title">{coffee.name}</h2>
|
||||||
<p>Roast:{coffee.roast}</p>
|
<p>Roast:{coffee.roast}</p>
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ function Coffees() {
|
|||||||
const[coffees,setCoffees]=useState([]);
|
const[coffees,setCoffees]=useState([]);
|
||||||
|
|
||||||
const getCoffees=()=>{
|
const getCoffees=()=>{
|
||||||
|
fetch('http://localhost:3000/coffees')
|
||||||
|
.then(res=>res.json())
|
||||||
|
.then(adat=>setCoffees(adat))
|
||||||
|
.catch(err=>alert(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
@@ -13,7 +16,14 @@ function Coffees() {
|
|||||||
},[]);
|
},[]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>Coffees</div>
|
<div>
|
||||||
|
<h2 className="text-3xl text-center font-bold text-blue-800">Kávéink</h2>
|
||||||
|
<div className="flex flex-row flex-wrap items-center justify-center">
|
||||||
|
{
|
||||||
|
coffees.map((coffee)=>(<Coffee key={coffee.id} coffee={coffee} />))
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user