Skip to content

Instantly share code, notes, and snippets.

@raflyfahrezi
Last active May 25, 2021 22:42
Show Gist options
  • Save raflyfahrezi/f5a5afedb3484d82e269e6a5242a658f to your computer and use it in GitHub Desktop.
Save raflyfahrezi/f5a5afedb3484d82e269e6a5242a658f to your computer and use it in GitHub Desktop.
fetching data using getStaticProps
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