Gatsby page components as class components

删除回忆录丶 提交于 2020-06-16 07:11:11

问题


I know I ask this on the eve of React Hooks being released but I was wondering - is it possible to create Page components as a Class component instead of a Function component?

When I convert the default Gatsby starter src/pages/index.js page to a Class component as such

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

export default IndexPage

I get this error (AppContainer)TypeError: Cannot set property 'props' of undefined

I couldn't find any documentation on this 😕


回答1:


You have a typo in your code, export default IndexPage instead of return.



来源:https://stackoverflow.com/questions/54539658/gatsby-page-components-as-class-components

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!