首页 > 解决方案 > Gatsby 页面组件作为类组件

问题描述

我知道我在 React Hooks 发布前夕问过这个问题,但我想知道 - 是否可以将 Page 组件创建为 Class 组件而不是 Function 组件?

当我将默认的 Gatsbysrc/pages/index.js起始页转换为 Class 组件时

class IndexPage extends React.Component {
  render() {
    return (
      <div>I am a class component</div>
    )
  }
}

export default IndexPage

我收到这个错误(AppContainer)TypeError: Cannot set property 'props' of undefined

我找不到任何关于此的文档

标签: gatsby

解决方案


您的示例代码中有错字。

export default IndexPage

代替return


推荐阅读