2019-07-25 17:18:38 +02:00
|
|
|
import fetch from 'isomorphic-unfetch'
|
|
|
|
import Link from 'next/link'
|
|
|
|
|
|
|
|
const Index = ({ users }) => (
|
|
|
|
<ul>
|
|
|
|
{users.map(user => (
|
|
|
|
<li key={user.id}>
|
2019-11-11 04:24:53 +01:00
|
|
|
<Link href="/user/[id]" as={`/user/${user.id}`}>
|
2019-07-25 17:18:38 +02:00
|
|
|
<a>{`User ${user.id}`}</a>
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
)
|
|
|
|
|
|
|
|
Index.getInitialProps = async () => {
|
|
|
|
const response = await fetch('http://localhost:3000/api/users')
|
|
|
|
const users = await response.json()
|
|
|
|
|
|
|
|
return { users }
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Index
|