-
-
Save shameemreza/71689ce6193206bd1e8b2b6415696b06 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 Link from "next/link"; | |
function UserList({ users }) { | |
return ( | |
<ul> | |
{users.map((user) => ( | |
<li key={user.id}> | |
<Link href={`/users/${user.id}`}> | |
<a>{user.name}</a> | |
</Link> | |
</li> | |
))} | |
</ul> | |
); | |
} | |
export async function getServerSideProps() { | |
// Fetch list of users | |
const res = await fetch("https://api.example.com/users"); | |
const users = await res.json(); | |
return { | |
props: { | |
users, | |
}, | |
}; | |
} | |
export default UserList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment