From 8c30b7a017964950ace54a0eb4fa4abf7610ec93 Mon Sep 17 00:00:00 2001 From: Junior marques Date: Sun, 3 Oct 2021 20:41:14 -0300 Subject: [PATCH 1/2] change README component from class to functional component --- README.md | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 82a8f04..9ec5436 100644 --- a/README.md +++ b/README.md @@ -73,35 +73,27 @@ const Index = () => ( // components/MyFragment.js import React from 'react'; -export default class MyFragment extends React.Component { - render() { - return ( -
-

A fragment that can have its own TTL

- -
{this.props.greeting /* access to the props as usual */}
-
{this.props.dataFromAnAPI}
-
- ); - } +export default function MyFragment(props){ + return ( +
+

A fragment that can have its own TTL

+ +
{props.greeting /* access to the props as usual */}
+
{props.dataFromAnAPI}
+
+ ) +} + +export async function getStaticProps() { + const res = await fetch(/* any api */) + const data = await res.json() - static async getInitialProps({ props, req, res }) { - return new Promise(resolve => { - if (res) { - // Set a TTL for this fragment - res.set('Cache-Control', 's-maxage=60, max-age=30'); - } - - // Simulate a delay (call to a remote service such as a web API) - setTimeout( - () => - resolve({ - ...props, // Props coming from index.js, passed through the internal URL - dataFromAnAPI: 'Hello there' - }), - 2000 - ); - }); + return { + props: { + greeting: 'Hello there', + dataFromAnAPI: data + }, + revalidate: 60, } } ``` From aa3b0f7b5c4213ba366ea20f6c685101b5fbb200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Fri, 8 Oct 2021 00:32:01 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ec5436..c7afdc8 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ const Index = () => ( // components/MyFragment.js import React from 'react'; -export default function MyFragment(props){ +export default function MyFragment(props) { return (

A fragment that can have its own TTL