我正在学习使用 YouTube 教程创建盖茨比博客网站。我已按照教程中所示的确切步骤进行操作。存在与 graphql 查询格式相关的错误。已解决。
我已经搜索了错误。但所有答案都与react app有关。没有与盖茨比相关的答案。所以我无法找到解决问题的正确方法。
Read more该页面在本地服务器端口 8000 加载。单击按钮查看单个帖子时出现错误。该错误似乎是 React 的。
元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件),但得到:未定义。您可能忘记从定义它的文件中导出组件,或者您可能混淆了默认导入和命名导入。检查 的渲染方法singlePost。
这是codesandbox链接:https://codesandbox.io/s/gatsby-starter-hello-world-m685p
singlePost.js
import React from "react"
import { graphql } from "gatsby"
import { MDXRenderer } from "gatsby-plugin-mdx"
import { H1 } from "../elements"
import { Container, Post, FeatureImage, Seo } from "../components"
const singlePost = ({ data }) => {
const featureImage = data.mdx.frontmatter.featureImage.childImageSharp.fixed
const seoImage = data.mdx.frontmatter.featureImage.publicURL
return (
<Container>
<Seo
title={data.mdx.frontmatter.title}
image={seoImage}
description={data.mdx.frontmatter.excerpt}
/>
<FeatureImage fixed={featureImage} />
<Post> …Run Code Online (Sandbox Code Playgroud)