Skip to content

Instantly share code, notes, and snippets.

@raflyfahrezi
Created May 25, 2021 22:41
Show Gist options
  • Save raflyfahrezi/c1593fcf1ee3c11bd5a2cd2024ee3f0f to your computer and use it in GitHub Desktop.
Save raflyfahrezi/c1593fcf1ee3c11bd5a2cd2024ee3f0f to your computer and use it in GitHub Desktop.
fetching data using getServerSideProps
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 getServerSideProps = async () => {
const response = await axios.get('... some API path...')
return {
props: { data: response.data },
}
}
export default index
export { getServerSideProps }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment