我正在尝试从无头 CMS (Sanity.io) 返回一些数据,但我的 React 不断遇到错误。我已经按照这个例子,但现在有错误TypeError: Cannot read property 'map' of undefined
我的代码
import * as React from "react";
import sanityClient from "@sanity/client";
import { Container, Row } from "reactstrap";
const client = sanityClient({
projectId: "<redacted>",
dataset: "<redacted>",
useCdn: true
});
let dataHenter;
const query = `*[_type == "land"]`;
export default class CountryList extends React.Component {
constructor(props) {
super(props);
this.state = {
country: []
};
}
static async getInitialProps() {
return {
country: await client.fetch(query)
};
}
render() {
const { country } = this.props;
return (
<Container>
<div className="country">
<ul className="list">
{country.map(country => (
<li key={country._id}>
<Row>
<a>
{country.image}
<h3>{country.name}</h3>
</a>
</Row>
</li>
))}
</ul>
</div>
</Container>
);
}
}
关于我做错了什么的任何想法?