index.ts1037 chars38 linesIn this example, we define a WeatherPage component that uses state to keep track of the current weather using the useState hook. We use the useEffect hook to run an async function every 45 seconds to fetch the latest weather data from the Weather API using fetch, and then update the state with the new weather data.
We also define a getStaticProps function that fetches the initial weather data and returns it as props, so that the page can be rendered with the initial data immediately. We use NextPage and GetStaticProps types to make sure our page component has the expected props and static generation function signatures.
gistlibby LogSnag