I'm setting up a NextJS app on my localhost machine and have followed along the great tutorial on the website, however when plugging in my local API I am having problems.
I'm getting an error when changing my JS code. The error is
TypeError: Cannot read property 'id' of undefined
(anonymous function)
/Users/mattcohen/hello-
next/.next/server/static/development/pages/index.js:1611:17
Here is my statement for the api:
Index.getInitialProps = async function() {
const res = await fetch('http://localhost:8888/api/mods')
const data = await res.json()
console.log(`Show data fetched. Count: ${data.length}`)
return {
mods: data.mods.map(entry => entry.show)
}
}
export default Index
And here is my page layout code
import Layout from '../components/MyLayout.js'
import Link from 'next/link'
import fetch from 'isomorphic-unfetch'
const Index = (props) => (
<Layout>
<h1>Batman TV Shows</h1>
<ul>
{props.mods.map(mod => (
<li key={mod.id}>
<Link as={`/p/${show.id}`} href={`/post?id=${mod.id}`}>
<a>{mod.brand_name}</a>
</Link>
</li>
))}
</ul>
Any ideas?