【问题标题】:React Hook is called in function which is neither a React function component or a custom React Hook function [duplicate]在既不是 React 函数组件也不是自定义 React Hook 函数的函数中调用 React Hook [重复]
【发布时间】:2020-08-26 13:41:10
【问题描述】:

我的blog.js 组件:

import {useStaticQuery, graphql} from "gatsby"


const blog = () => {
    const {site} = useStaticQuery(
        graphql`
      query {
        site {
          siteMetadata {
            title
          }
        }
      }
    `
    )
    return site.siteMetadata
}

export default blog

盖茨比文档:https://www.gatsbyjs.org/docs/use-static-query/

我已尝试解决此问题!

有什么解决办法吗??

谢谢

【问题讨论】:

    标签: reactjs gatsby


    【解决方案1】:

    将组件名称大写:

    import {useStaticQuery, graphql} from "gatsby"
    
    
    const Blog = () => {
      const {site} = useStaticQuery(
        graphql`
          query {
            site {
              siteMetadata {
                title
              }
            }
          }
        `
      )
      return site.siteMetadata
    }
    
    export default Blog
    

    User-Defined Components Must Be Capitalized

    我们建议使用大写字母命名组件。如果您确实有一个以小写字母开头的组件,请在 JSX 中使用之前将其分配给大写变量。

    【讨论】:

    • 不工作!!当我使用 StaticQuery 时,它正在工作。 gatsbyjs.org/docs/static-query
    • 您能否提供更多信息,说明究竟是什么不工作?
    猜你喜欢
    • 2021-11-27
    • 1970-01-01
    • 2023-02-19
    • 1970-01-01
    • 2019-10-21
    • 2022-08-07
    • 2020-03-18
    • 2019-09-14
    • 2020-11-02
    相关资源
    最近更新 更多