From a1b295a65daeaea68c66aac26b79bab3c9f83d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Isaksen?= Date: Mon, 28 Mar 2022 20:15:51 +0200 Subject: [PATCH] feat: add climate-page with SSR --- pages/climate/index.tsx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pages/climate/index.tsx b/pages/climate/index.tsx index 07d0d22..f78d1ce 100644 --- a/pages/climate/index.tsx +++ b/pages/climate/index.tsx @@ -1,21 +1,17 @@ import type { NextPage } from 'next'; import Link from 'next/link'; -import { useEffect, useState } from 'react'; import env from '../../env'; import { Location } from '../../types'; import { getLocations } from '../../services/api/climate/locations'; -interface Props {} +interface Props { + data: any; +} -const Climate: NextPage = () => { - const [locations, setLocations] = useState([]); +const Climate: NextPage = ({ data: locations}) => { const { READING_BASE_URI } = env; - useEffect(() => { - getLocations().then(locations => setLocations(locations)) - }, []) - return (
Climate Page12
@@ -35,4 +31,9 @@ const Climate: NextPage = () => { ) } +export async function getServerSideProps() { + const data = await getLocations(); + return { props: { data } } +} + export default Climate;