【问题标题】:Cannot read property '__reactstandin__key' of undefined gatsby graphql无法读取未定义 gatsby graphql 的属性“__reactstandin__key”
【发布时间】:2019-12-21 18:37:03
【问题描述】:

我是 gatsby 和 graphql 的新手。 尝试使用 graphql 获取图像,控制台正在返回图像日期, 但接下来我得到错误:

TypeError: Cannot read property '__reactstandin__key' of undefined

这是我获取 iamge 的代码:

export const fluidImage = graphql`
  fragment fluidImage on File {
    childImageSharp {
      fluid(maxWidth: 1000) {
        ...GatsbyImageSharpFluid
      }
    }
  }
`

export const pageQuery = graphql`
  query {
    myPhoto: file(relativePath: { eq: "me.png" }) {
      ...fluidImage
    }
  }
`

在渲染中

{console.log(this.props.data.myPhoto.childImageSharp.fluid)}
<Img fluid={this.props.data.myPhoto.childImageSharp.fluid} />

我得到带有 base64 数据的日志。 什么可能导致此错误?

【问题讨论】:

    标签: reactjs graphql gatsby


    【解决方案1】:

    我遇到了这个错误,因为我使用的是命名导出而不是默认导出。

    使用:

    import Img from "gatsby-image"
    

    不要使用:

    import {Img} from "gatsby-image"
    

    【讨论】:

      猜你喜欢
      • 2020-01-01
      • 2019-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-07
      • 2019-05-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多