Last active
May 25, 2021 22:42
-
-
Save raflyfahrezi/f5a5afedb3484d82e269e6a5242a658f to your computer and use it in GitHub Desktop.
fetching data using getStaticProps
This file contains hidden or 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
import React from 'react' | |
import axios from 'axios' | |
const index = ({ data }) => { | |
return ( | |
<div> | |
{data.map((item, index) => { | |
return ( | |
<div key={index}>{item.name}</div> | |
) | |
})} | |
</div> | |
) | |
} | |
const getStaticProps = async () => { | |
const response = await axios.get('... some API path...') | |
return { | |
props: { data: response.data }, | |
revalidate: 1, | |
} | |
} | |
export default index | |
export { getStaticProps } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment