gatsby - 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
我找不到任何关于此的文档
解决方案
您的示例代码中有错字。
export default IndexPage
代替return
推荐阅读
- c - 用户退出时如何关闭控制台窗口?
- c++ - 有什么东西可以阻止 std::optional::value_or() 有条件地为 noexcept 吗?
- python - 在我的基于数组的列表实现中为 append 方法编写单元测试
- python - PyQt 使用适当的抗锯齿调整 QMovie 的大小
- node.js - 无法从 fetch 中获取所有响应数据
- javascript - 试图在 Node 环境中使用 babel JavaScript 或 TypeScript 文件
- python - 如何扫描 json 文件中的某个字符串?使用 Python
- java - 尝试按日期删除时,查询不会产生结果集。
- c# - NetSuite Web API - 如何从联合搜索返回/填充销售订单的 customFieldList 数组?
- firebase - Firebase 计算列表的最佳实践