Created
May 25, 2021 22:41
-
-
Save raflyfahrezi/c1593fcf1ee3c11bd5a2cd2024ee3f0f to your computer and use it in GitHub Desktop.
fetching data using getServerSideProps
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 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