Created
January 13, 2021 17:17
-
-
Save polluterofminds/74335d5932ec6712079586282ecf604f to your computer and use it in GitHub Desktop.
PostList component
This file contains 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
const PostList = () => { | |
const [allPosts, setPosts] = useState([]); | |
const [loading, setLoading] = useState(true); | |
useEffect(() => { | |
loadPosts(); | |
}, []); | |
const loadPosts = async () => { | |
try { | |
const posts = await loadAllPosts(); | |
setPosts(posts); | |
setLoading(false); | |
} catch (error) { | |
console.log(error); | |
setLoading(false); | |
} | |
} | |
const styles = { | |
postTopNav: { | |
display: "flex", | |
flexDirection: "row", | |
justifyContent: "space-between", | |
borderBottom: "1px solid #666" | |
}, | |
postContainer: { | |
maxWidth: "60%", | |
margin: "auto", | |
marginTop: 50 | |
} | |
} | |
return ( | |
<div style={styles.postContainer}> | |
{ | |
loading ? | |
<div> | |
<h3>Loading posts...</h3> | |
</div> : | |
<div> | |
<div style={styles.postTopNav}> | |
<div> | |
<p>New</p> | |
</div> | |
</div> | |
{allPosts.map((post) => { | |
return ( | |
<div> | |
<h3>{post.name}</h3> | |
<p>{post.date}</p> | |
<Link href={`/posts/${post.hash}`}>Read</Link> | |
</div> | |
) | |
})} | |
</div> | |
} | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment