diff --git a/src/pages/lottery.tsx b/src/pages/lottery.tsx index 25dda7df3..2e91677a5 100644 --- a/src/pages/lottery.tsx +++ b/src/pages/lottery.tsx @@ -13,6 +13,21 @@ type Props = { id: string } +type ServerProps = { + props: Props +} + +export async function unstable_getServerProps(): Promise { + const ids = await getFortunes().catch((): string[] => []) + const id = ids[Math.floor(Math.random() * ids.length)] + + if (!id) throw new TypeError("Fortune doesn't exist.") + + return { + props: { id } + } +} + const LotteryPage: NextPage = ({ id }) => { const router = useRouter() @@ -44,13 +59,4 @@ const LotteryPage: NextPage = ({ id }) => { ) } -LotteryPage.getInitialProps = async (): Promise => { - const ids = await getFortunes().catch((): string[] => []) - const id = ids[Math.floor(Math.random() * ids.length)] - - if (!id) throw new TypeError("Fortune doesn't exist.") - - return { id } -} - export default LotteryPage