Created
February 13, 2020 04:44
-
-
Save vanhtuan0409/f68342aaf356a675079b5aca7e627e76 to your computer and use it in GitHub Desktop.
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 React, { useEffect } from "react"; | |
import Header from "../components/Header"; | |
import SiteMap from "../components/SiteMap"; | |
import Link from "next/link"; | |
const Index = ({ blogs }) => { | |
console.log("This is a component"); | |
useEffect(() => { | |
console.log("Index mounted"); | |
}); | |
return ( | |
<div> | |
<Header>Blogs</Header> | |
<ul> | |
{blogs.map(b => ( | |
<li key={b.id}> | |
<Link href="/blogs/[id]" as={`/blogs/${b.id}`}> | |
<a>{b.name}</a> | |
</Link> | |
</li> | |
))} | |
</ul> | |
<hr /> | |
<SiteMap /> | |
</div> | |
); | |
}; | |
Index.getInitialProps = () => { | |
console.log("Get initial props"); | |
return { | |
blogs: [ | |
{ id: 0, name: "Blog 1" }, | |
{ id: 1, name: "Blog 2" }, | |
{ id: 2, name: "Blog 3" }, | |
{ id: 3, name: "Blog 4" }, | |
{ id: 4, name: "Blog 5" } | |
] | |
}; | |
}; | |
export default Index; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment