Dummyjson posts
This commit is contained in:
1 parent
5f6df55a82
commit
aa9de8b37c
20 files changed
+3395
No files matched your search
@@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
function Header({szoveg}) {
|
||||
return (
|
||||
<h1 className="text-3xl text-center font-bold text-cyan-900 bg-cyan-300">{szoveg}</h1>
|
||||
)
|
||||
}
|
||||
|
||||
export default Header
|
||||
@@ -0,0 +1,29 @@
|
||||
|
||||
|
||||
function Post({ post }) {
|
||||
return (
|
||||
<div className="card bg-cyan-300 m-2 shadow-sm">
|
||||
|
||||
<div className="card-body">
|
||||
<h2 className="card-title">
|
||||
{post.title}
|
||||
|
||||
</h2>
|
||||
<div className="card-actions justify-start">
|
||||
{
|
||||
post.tags.map((tag,i)=>(<div key={i} className="badge badge-secondary">{tag}</div>))
|
||||
}
|
||||
|
||||
</div>
|
||||
<p>{post.body}</p>
|
||||
<div className="card-actions justify-end">
|
||||
<div className="badge badge-outline">👍{post.reactions.likes}</div>
|
||||
<div className="badge badge-outline">👎 {post.reactions.dislikes}</div>
|
||||
<div className="badge badge-outline">👁 {post.views}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Post
|
||||
@@ -0,0 +1,29 @@
|
||||
import { useState,useEffect } from "react"
|
||||
import Post from "./Post";
|
||||
|
||||
function Posts() {
|
||||
const[posts,setPosts]=useState([]);
|
||||
const letoltes=()=>{
|
||||
fetch('https://dummyjson.com/posts')
|
||||
.then(res=>res.json())
|
||||
.then(adatok=>setPosts(adatok.posts))
|
||||
.catch(err=>alert(err));
|
||||
|
||||
}
|
||||
|
||||
useEffect(()=>{
|
||||
letoltes();
|
||||
},[])
|
||||
return (
|
||||
<div>
|
||||
<div>
|
||||
|
||||
{
|
||||
posts.map((post)=>(<Post key={post.id} post={post} />))
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Posts
|
||||
Reference in new issue
Block a user