Reactjs 反应不连贯';不要在组件上工作,否则将卸载
我正在使用alt和React 0.13.1。在下面的我的组件中,Reactjs 反应不连贯';不要在组件上工作,否则将卸载,reactjs,flux,react-alt,Reactjs,Flux,React Alt,我正在使用alt和React 0.13.1。在下面的我的组件中,unlisten对componentWillUnmount不起作用 组件已卸载,但我可以看到轮询仍在进行。有没有什么我不明白的,关于如何去听?我没有绑定,因为React 0.13包含自动绑定。任何帮助都将不胜感激 “严格使用”; 从“React”导入React; 从“/SitesList”导入站点列表; 从“../stores/SiteStore”导入SiteStore; 从“../actions/SiteActions”导入Sit
unlisten
对componentWillUnmount
不起作用
组件已卸载,但我可以看到轮询仍在进行。有没有什么我不明白的,关于如何去听?我没有绑定,因为React 0.13包含自动绑定。任何帮助都将不胜感激
“严格使用”;
从“React”导入React;
从“/SitesList”导入站点列表;
从“../stores/SiteStore”导入SiteStore;
从“../actions/SiteActions”导入SiteActions;
//下一行是显示React to browser for所必需的
//React开发者工具:http://facebook.github.io/react/blog/2014/01/02/react-chrome-developer-tools.html
//要求(“暴露?反应!反应”);
var SitesBox=React.createClass({
displayName:“SiteBox”,
道具类型:{
url:React.PropTypes.string.isRequired,
pollInterval:React.PropTypes.number.isRequired
},
getStoreState(){
返回{
站点:SiteStore.getState()
};
},
getInitialState(){
返回这个.getStoreState();
},
componentDidMount(){
SiteStore.listen(this.onChange);
SiteActions.fetchSites(this.props.url,true);
setInterval(SiteActions.fetchSites,
这个.props.pollInterval,
this.props.url,
假);
},
组件将卸载(){
SiteStore.unlisten(this.onChange);
},
onChange(){
this.setState(this.getStoreState());
},
render(){
返回(
);
}
});
导出默认站点框;
回答我自己的问题。Unlisten不处理时间间隔。必须清除clearInterval(),如下所示。非常感谢alt创建者Josh Perez帮助解决此React(非alt)问题
“严格使用”;
从“React”导入React;
从“/SitesList”导入站点列表;
从“../stores/SiteStore”导入SiteStore;
从“../actions/SiteActions”导入SiteActions;
//下一行是显示React to browser for所必需的
//React开发者工具:http://facebook.github.io/react/blog/2014/01/02/react-chrome-developer-tools.html
//要求(“暴露?反应!反应”);
var SitesBox=React.createClass({
displayName:“SiteBox”,
sitesInterval:null,
道具类型:{
url:React.PropTypes.string.isRequired,
pollInterval:React.PropTypes.number.isRequired
},
getStoreState(){
返回{
站点:SiteStore.getState()
};
},
getInitialState(){
返回这个.getStoreState();
},
componentDidMount(){
SiteStore.listen(this.onChange);
SiteActions.fetchSites(this.props.url,true);
this.sitesInterval=setInterval(SiteActions.fetchSites,
这个.props.pollInterval,
this.props.url,
假);
},
组件将卸载(){
SiteStore.unlisten(this.onChange);
clearInterval(此.sitesInterval);
},
onChange(){
this.setState(this.getStoreState());
},
render(){
返回(
);
}
});
导出默认站点框;
'use strict';
import React from 'react';
import SitesList from './SitesList';
import SiteStore from '../stores/SiteStore';
import SiteActions from '../actions/SiteActions';
// Next line is necessary for exposing React to browser for
// the React Developer Tools: http://facebook.github.io/react/blog/2014/01/02/react-chrome-developer-tools.html
// require("expose?React!react");
var SitesBox = React.createClass({
displayName: 'SitesBox',
sitesInterval: null,
propTypes: {
url: React.PropTypes.string.isRequired,
pollInterval: React.PropTypes.number.isRequired
},
getStoreState() {
return {
sites: SiteStore.getState()
};
},
getInitialState() {
return this.getStoreState();
},
componentDidMount() {
SiteStore.listen(this.onChange);
SiteActions.fetchSites(this.props.url, true);
this.sitesInterval = setInterval(SiteActions.fetchSites,
this.props.pollInterval,
this.props.url,
false);
},
componentWillUnmount() {
SiteStore.unlisten(this.onChange);
clearInterval(this.sitesInterval);
},
onChange() {
this.setState(this.getStoreState());
},
render() {
return (
<div className="siteBox row">
<div className="col-md-12">
<div className="panel panel-inverse">
<div className="panel-body">
<SitesList sites={this.state.sites.sites} />
</div>
</div>
</div>
</div>
);
}
});
export default SitesBox;