I'm having trouble rendering a set of data that I'm fetching from an API, and would like to know why that is. If I comment out my map function, I'm able to console.log my data object and traverse it via the dev tools. However, once I implement the map function back into my code, I continually end up receiving a "cannot find property of reviews" TypeError. How is that? Considering I was able to console log the object earlier?
index.js
import Head from 'next/head'
import Image from 'next/image'
import styles from '../styles/Home.module.css'
import Header from '../components/Header'
import {useQuery, gql} from '@apollo/client'
const REVIEWS = gql`
query GetReviews {
reviews {
title,
body,
rating,
id
}
}
`
export default function Home() {
const {loading, error, data} = useQuery(REVIEWS)
console.log(data.reviews)
return (
<>
<Header/>
<div>{data.reviews.map(r => (
<div>{r.id}</div>
))}
</div>
</>
)
}
_app.js
import '../styles/globals.css'
import {
ApolloClient,
InMemoryCache,
ApolloProvider,
} from "@apollo/client";
function MyApp({ Component, pageProps }) {
const client = new ApolloClient({
uri: 'http://localhost:1337/graphql',
cache: new InMemoryCache()
})
return (
<ApolloProvider client={client}>
<Component {...pageProps} />
</ApolloProvider>
)
}
export default MyApp