I've just started learning how to use React, and I encountered the following problem: I need to render this data I fetched using graphql, when I console.log the data it shows up just fine. But when I try to map the array to get what I need it seems to be returning undefined.
How can I render the name and email of each subscriber using map?
import React, { useState } from "react";
import { gql, useQuery } from "@apollo/client";
const GET_SUBSCRIBERS_QUERY = gql`
query {
subscribers(stage: DRAFT) {
name
email
id
}
}
`;
const App = () => {
const { data } = useQuery(GET_SUBSCRIBERS_QUERY);
return (
<>
<h1>@fsouza/table-data</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
{data.subscribers.map((subscriber) => (
<tr key={subscriber.id}>
<td>{subscriber.name}</td>
<td>{subscriber.email}</td>
</tr>
))}
</tbody>
</table>
</>
);
};
export default App;
data?.subscribers.map(, data is undefined on the first render