【发布时间】:2016-01-01 05:05:38
【问题描述】:
我正在 Alex Bank 的 "Building a Polling App with Socket IO 工作 和 React.js" (Lynda.com),但我正在尝试将其升级到 反应路由器 1.0.0-RC1.
问题:
当演讲者登录并创建演示文稿时,会显示成功的问题列表。但是,当演讲者单击要向与会者发出的相应问题时,我收到错误:"Cannot read property 'props' of null",它标识了 Question.js 组件中的错误:
ask(question) {
console.log('this question: ' + JSON.stringify(question));
this.props.emit('ask', question); <--- Console points to this
}
但我不认为这本身就是问题所在。我相信实际的问题是这个发射没有到达应用程序中的 socket.on。
APP.js:
componentWillMount() {
this.socket = io('http://localhost:3000');
this.socket.on('ask', this.ask.bind(this));
....
}
ask(question) {
sessionStorage.answer = '';
this.setState({ currentQuestion: question });
}
我相信它与react-router相关,但父路由确实有组件{APP},并且Speaker是子路由并且Speaker组件确实导入了Question组件,所以我假设Question组件连接到APP的。
在亚历克斯的项目中它正在工作,但他使用:
"react": "^0.13.3",
"react-router": "^0.13.3",
有人可以提供一些关于这方面的见解吗?
非常感谢!
【问题讨论】:
标签: socket.io reactjs react-router