Check the render method of `TopicDetail`

来源:4-7 话题详情页

慕侠3851047

2018-07-12

老师您好,我这边遇到这个问题卡住了,不知道那里出了问题,

使用固定的话题 可以渲染出 详情页,但是也无法获取 

topicStore: TopicStore{…}

# !/client/views/topic-detail/index.jsx
...
render() {
const {
classes,
} = this.props
// const id = this.getTopicId() // 通过react-router生成的match对象获取url的params参数
// const topic = this.props.topicStore.detailMap[id]
const topic = this.props.topicStore.topics[1]
if (!topic) { // topic 不存在加载 loading
...

http://img.mukewang.com/szimg/5b46ddab0001615313170767.jpg

但是 有正常的 api 请求,从 list 页面点击跳转到 detail 页面有正常的 api 请求

http://img.mukewang.com/szimg/5b46df3b0001a76b13230443.jpg

但是刷新页面就会报错

http://img.mukewang.com/szimg/5b46df9300016e8312950937.jpg

type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check the render method of `TopicDetail`.
    in TopicDetail (created by inject-TopicDetail)
    in inject-TopicDetail (created by WithStyles(inject-TopicDetail))
    in WithStyles(inject-TopicDetail) (created by Route)
    in Route (created by _default)
    in _default (created by App)
    in App (created by Main)
    in Main
    in MuiThemeProvider
    in Router (created by BrowserRouter)
    in BrowserRouter
    in Provider
    in AppContainer
The above error occurred in the <section> component:
    in section (created by TopicDetail)
    in div (created by Paper)
    in Paper (created by WithStyles(Paper))
    in WithStyles(Paper) (created by Container)
    in Container (created by WithStyles(Container))
    in WithStyles(Container) (created by TopicDetail)
    in TopicDetail (created by inject-TopicDetail)
    in inject-TopicDetail (created by WithStyles(inject-TopicDetail))
    in WithStyles(inject-TopicDetail) (created by Route)
    in Route (created by _default)
    in _default (created by App)
    in App (created by Main)
    in Main
    in MuiThemeProvider
    in Router (created by BrowserRouter)
    in BrowserRouter
    in Provider
    in AppContainer
React will try to recreate this component tree from scratch using the error boundary you provided, AppContainer.

运行服务端 npm run dev:server 跳转到 detail 页面也会报错

TypeError: stores[storeName].toJson is not a function
    at Object.keys.reduce (/Users/tianxiaoqiang/Life/git-osc/IDE/0702-yak-python-ide/server/utils/server-render.js:14:43)
    at Array.reduce (<anonymous>)
    at getStoreState (/Users/tianxiaoqiang/Life/git-osc/IDE/0702-yak-python-ide/server/utils/server-render.js:13:30)
    at bootstrapper.then (/Users/tianxiaoqiang/Life/git-osc/IDE/0702-yak-python-ide/server/utils/server-render.js:46:21)
    at <anonymous>


源代码链接 https://gitee.com/custer_git/0702-yak-python-ide/commit/329a5f8b46082c648508cb6fe6d2700f61c4df7e#52248e4f8fd8a5c214cccdf3c4433a2cc930ce3a_1_1

写回答

1回答

Jokcy

2018-07-13

stores[storeName].toJson is not a function,你是不是又一个store的toJson方法没有写

0
1
慕侠3851047
老师toJson知道哪里出了问题,但是,详情页点开就报错,不知道为什么?麻烦老师了
2018-07-13
共1条回复

React全栈+服务器渲染(ssr)打造社区Webapp

【毕设面试】只会写业务代码?out了,带你学会搭建属于自己的工程!

768 学习 · 414 问题

查看课程