[英]React.js on Rails error
I am following this tutorial on how to integrate react.js into rails and when I pre compile my assets I get an error with this code stating that (data) => this.setState({statuses: data});
我下面这个关于如何react.js融入轨教程,当我预编译我的资产,我得到一个错误与此代码指出,
(data) => this.setState({statuses: data});
causes SyntaxError: unknown: Unexpected token (14:44)
I tried many things to get it to work and when I delete the semi-colon at the end it works except that the interval no longer gets called the console will say alert twice when the page is refreshed and then never again. 导致
SyntaxError: unknown: Unexpected token (14:44)
我尝试了很多事情来使其起作用,并且当我最后删除分号时,它起作用了,只是不再调用该间隔,控制台将在两次提示时发出警报两次。页面会刷新,然后再也不会刷新。
var StatusesContainer = React.createClass ({
componentWillMount() {
this.fetchStatuses();
setInterval(this.fetchStatuses(), 1000);
},
fetchStatuses() {
console.log("alert");
$.getJSON(
this.props.statusesPath,
{
space_id: this.props.space_id
},
(data) => this.setState({statuses: data});
);
},
getInitialState() {
return ({ statuses: [] });
},
render() {
return (<RecentStatuses statuses={ this.state.statuses }/>);
}
});
$.getJSON(
this.props.statusesPath,
{
space_id: this.props.space_id
},
(data) => this.setState({statuses: data});
);
Here is the problem: (data) => this.setState({statuses: data});
这是问题所在:
(data) => this.setState({statuses: data});
, you should use ,
not ;
,您应该使用
,
而不是;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.