I am trying to fetch an image from this API by using getStaticProps but I can't seem to get it.
If I add a '?' to the code like this then in the log it says 'undefined'. Why can't I fetch it?
<div>
{hotelPics.map((hotelpic)=> (
<Image src={hotelpic.url} />
))}
</div>
This is the code:
import Image from 'next/image';
import React from 'react'
function Images({hotelPics }) {
console.log(hotelPics);
return (
<div>
{hotelPics.map((hotelpic)=> (
<Image src={hotelpic.url}/>
))}
</div>
)
}
export async function getStaticProps() {
const res= await fetch ('https://obmng.dbm.guestline.net/api/hotels?collection-id=OBMNG')
const hotelPics = await res.json()
return {
props: {
hotelPics,
},
}
}
export default Images