Download next.js/examples/api-routes-apollo-server/pages/[username].tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 864 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/examples/api-routes-apollo-server/pages/%5Busername%5D.tsx
- Command line
-
hf download 'hf://datasets/Devendra174/react-code-dataset/next.js/examples/api-routes-apollo-server/pages/[username].tsx'
-
curl -L -o '[username].tsx' https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/examples/api-routes-apollo-server/pages/%5Busername%5D.tsx
864 Bytes
| import queryGraphql from "../shared/query-graphql"; | |
| export default function UserProfile({ user }) { | |
| if (!user) { | |
| return <h1>User Not Found</h1>; | |
| } | |
| return ( | |
| <h1> | |
| {user.username} is {user.name} | |
| </h1> | |
| ); | |
| } | |
| export async function getStaticProps(context) { | |
| const { params } = context; | |
| const { username } = params; | |
| const { user = null } = await queryGraphql( | |
| ` | |
| query($username: String) { | |
| user(username: $username) { | |
| name | |
| username | |
| } | |
| } | |
| `, | |
| { username }, | |
| ); | |
| return { props: { user } }; | |
| } | |
| export async function getStaticPaths() { | |
| const { users } = (await queryGraphql(` | |
| query { | |
| users { | |
| username | |
| } | |
| } | |
| `)) as { users: { username: string }[] }; | |
| return { | |
| paths: users.map(({ username }) => ({ | |
| params: { username }, | |
| })), | |
| fallback: true, | |
| }; | |
| } | |