-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generic Type for GetStaticPaths (#11430)
* Generic Type for GetStaticPaths * Add generic typing for params to GSSP and GSP too * Added basic tests Co-authored-by: Luis Alvarez <luis@zeit.co>
- Loading branch information
Showing
3 changed files
with
60 additions
and
6 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { GetStaticPaths, GetStaticProps } from 'next' | ||
|
||
type Params = { | ||
slug: string | ||
} | ||
|
||
type Props = { | ||
data: string | ||
} | ||
|
||
export const getStaticPaths: GetStaticPaths<Params> = async () => { | ||
return { | ||
paths: [{ params: { slug: 'test' } }], | ||
fallback: false, | ||
} | ||
} | ||
|
||
export const getStaticProps: GetStaticProps<Props, Params> = async ({ | ||
params, | ||
}) => { | ||
return { | ||
props: { data: params!.slug }, | ||
revalidate: false, | ||
} | ||
} | ||
|
||
export default function Page({ data }: Props) { | ||
return <h1>{data}</h1> | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { GetServerSideProps } from 'next' | ||
|
||
type Params = { | ||
slug: string | ||
} | ||
|
||
type Props = { | ||
data: string | ||
} | ||
|
||
export const getServerSideProps: GetServerSideProps<Props, Params> = async ({ | ||
params, | ||
}) => { | ||
return { | ||
props: { data: params!.slug }, | ||
} | ||
} | ||
|
||
export default function Page({ data }: Props) { | ||
return <h1>{data}</h1> | ||
} |