Skip to content

Instantly share code, notes, and snippets.

@vanhtuan0409
Created February 13, 2020 04:44
Show Gist options
  • Save vanhtuan0409/f68342aaf356a675079b5aca7e627e76 to your computer and use it in GitHub Desktop.
Save vanhtuan0409/f68342aaf356a675079b5aca7e627e76 to your computer and use it in GitHub Desktop.
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