I know this is probably a question that is easily answered, but I cannot figure it out after a few hours. I am trying to map over this JSON but it keeps saying "props.shows.map" is not a function, however the same works for another bit of data. I am trying to get things like 'id' and 'name' from the data.
The mapping works with this link: https://api.tvmaze.com/search/shows?q=\%22Terrance%20House\%22
Here is the JSON that doesn't work/can't seem to get the information from: https://api.tvmaze.com/shows/34275/episodes
import Layout from '../components/MyLayout'
import fetch from 'isomorphic-unfetch'
import Link from 'next/link'
const ShowLink = ({ show }) => (
<li key={show.id}>
<Link as={`/episode/${show.id}`} href={`/episodes/id=${show.id}`}>
<a>{show.name}</a>
</Link>
<style jsx>{`
li {
list-style: none;
margin: 5px 0;
}
a {
text-decoration: none;
color: blue;
font-family: "Arial";
}
a:hover {
opacity: 0.6;
}
`}</style>
</li>
)
/*
<h1>{props.show.name}</h1>
<p>{props.show.summary.replace(/<[/]?p>/g, '')}</p>
<img src={props.show.image.medium}/>
*/
const Post = (props) => (
<Layout>
<h1>Terrace House Episodes</h1>
<ul>
{props.shows.map(({show}) => (
<ShowLink key={show} value={show} />
))}
</ul>
</Layout>
)
Post.getInitialProps = async function () {
//const { id } = context.query
//const res = await fetch(`https://api.tvmaze.com/shows/${id}`)
//const show = await res.json()
//const res = await fetch(`http://api.tvmaze.com/seasons/34275/episodes`);
const res = await fetch('https://api.tvmaze.com/shows/34275/episodes');
const data = await res.json()
return {
shows: data
}
}
export default Post
console.log(typeof props.shows)and let me know what it comes back as