Last active
May 31, 2022 03:33
-
-
Save leifarriens/001ae1da037bbbbc7df6c5e147d5440b to your computer and use it in GitHub Desktop.
NextJS infer prop types from getServerSideProps
This file contains 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 type { GetServerSidePropsContext, InferGetServerSidePropsType } from 'next'; | |
import Head from 'next/head'; | |
const Home = ({ host }: InferGetServerSidePropsType<typeof getServerSideProps>) => { | |
return ( | |
<> | |
<Head> | |
<title>Home Page</title> | |
</Head> | |
<main> | |
<div>{host}</div> | |
</main> | |
</> | |
); | |
}; | |
export const getServerSideProps = async ({ req }: GetServerSidePropsContext) => { | |
const host = req.headers.host; | |
return { | |
props: { | |
host, | |
}, | |
}; | |
}; | |
export default Home; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment