我在使用 react hooks 时遇到了这个错误。
从 'react' 导入 React, {useState, useEffect}; 从 '../client.js' 导入 sanityClient
export default function Post() {
const [postData, setPost] = useState(null);
7 |
8 | useEffect(() => {
> 9 | sanityClient.fetch(
| ^ 10 | `*[_type == "post"]{
11 | title,
12 | slug,
mainImage{
asset => {
_id,
url
},
alt
}
}`
)
.then((data) => setPost(data))
.catch(console.error);
}, []);
答案 0 :(得分:0)
我遇到了同样的问题,在检查我的代码后发现多个错误 喜欢:
从“@sanity/client”导入 sanityClient(这不是你的情况)
mainImage{asset => {_id, url }, should be ``mainImage{asset -> {_id, url }
用破折号而不是等号
所以我的建议是仔细检查你的拼写