我将Gatsby与Netlify CMS一起使用,在Netlify CMS中预览模板时遇到了问题。
有一个索引页组件可以正常工作。它从markdown和frontmatter获取数据,并与Netlify CMS窗口小部件,还有一个特色的posts组件,它通过useStaticQuery
钩子获取数据。
但一旦我在Netlify管理员中转到索引页面预览模板,我就会得到:
Error: The result of this StaticQuery could not be fetched.
This is likely a bug in Gatsby and if refreshing the page does not fix it, please open an issue in https://github.com/gatsbyjs/gatsby/issues
useStaticQuery
./.cache/gatsby-browser-entry.js:1
> 1 | import React from "react"
2 | import PropTypes from "prop-types"
3 | import Link, {
4 | withPrefix,
View compiled
_default
./src/components/common/FeaturedPosts.js:1
> 1 | import React from 'react'
2 | import v4 from 'uuid'
3 | import { useStaticQuery, graphql } from "gatsby"
4 |
View compiled
▶ 28 stack frames were collapsed.
我的目标是从来自Netlify CMS和特色博客列表组件的降价和前台数据中渲染主页,该组件通过Netlify Admin中的useStaticQuery
挂钩从/posts
目录中获取数据。
复制回购可以在这里找到
gatsby-plugin-netlify-cms
中是这样做的。
如果您确实需要访问为静态查询提取的数据,但无法保持与导入原始JSON文件完全相同的代码,请查看此问题。https://stackoverflow.com/a/58944342/157601