Javascript 警告.js:45警告:设置状态(…):只能更新已安装或正在安装的组件
我不熟悉Javascript 警告.js:45警告:设置状态(…):只能更新已安装或正在安装的组件,javascript,jquery,html,reactjs,redux,Javascript,Jquery,Html,Reactjs,Redux,我不熟悉js我正在尝试使用this.setState({ 但我得到一个警告。 你们能告诉我为什么我会收到下面的警告吗 warning.js:45 warning:setState(…):只能更新已安装或正在安装的组件。这通常意味着您在未安装的组件上调用了setState()。这是禁止操作的。请检查PerformanceChartNav组件的代码 提供以下代码:- import React from 'react'; import {connect} from 'react-redux'; imp
js
我正在尝试使用this.setState({
但我得到一个警告。
你们能告诉我为什么我会收到下面的警告吗
warning.js:45 warning:setState(…):只能更新已安装或正在安装的组件。这通常意味着您在未安装的组件上调用了setState()。这是禁止操作的。请检查PerformanceChartNav组件的代码
提供以下代码:-
import React from 'react';
import {connect} from 'react-redux';
import moment from 'moment';
import height from './jump-player-tab-content';
import weight from './jump-player-pane-content';
import AccountSetupTab from './running-setup';
import BalancePortfolio from './balance-portfolio';
class FirstTimeTab extends React.Component {
constructor(props) {
super(props);
this.state = {
runningSetup: 'jump-player-active',
investmentPurchase: 'sports-invest-ico',
balancePortfolio: 'sports-balance-ico',
performance: 'sports-perf-ico',
selectedTab: 0
};
}
componentWillMount() {
let {sportsPhone, runningSnapshot, runningPositions, runningPerformance} = this.props;
let managedProductActivationDate = this.props.sportsPhone.managedProductActivationDate;
let past1Day = moment().subtract(1, 'days').format('YYYY-MM-DD');
let isActive= managedProductActivationDate < past1Day;
if(sportsPhone !== '' && !isActive) {
this.setState({
selectedTab: 0,
runningSetup: "sports-setup-ico jump-player-active ft-active-tab"
});
}else if(isActive) {
this.setState({
selectedTab: 1,
runningSetup: "sports-setup-ico ft-prev-day",
investmentPurchase: "sports-invest-ico jump-player-active ft-active-tab"
});
}else if(runningSnapshot !== undefined && runningPositions.positions.length > 0 ) {
this.setState({
selectedTab: 2,
runningSetup: "ft-prev-day",
investmentPurchase: "ft-prev-day",
balancePortfolio: "sports-balance-ico jump-player-active ft-active-tab"
});
}else if(runningPerformance !== undefined ) {
this.setState({
selectedTab: 3,
runningSetup: "dft-prev-day",
investmentPurchase: "ft-prev-day",
balancePortfolio: "ft-prev-day",
performance: "sports-perf-ico jump-player-active ft-active-tab"
});
}
}
callback(selectedTab){
if (this.state.selectedTab !== selectedTab) {
switch(this.state.selected) {
case 0:
let temp = this.state.runningSetup.substring(32, 45);
this.setState({runningSetup: temp});
break;
case 1:
let temp1 = this.state.runningSetup.substring(33, 46);
this.setState({runningSetup: temp});
break;
case 2:
let tem2 = this.state.runningSetup.substring(34, 47);
this.setState({runningSetup: temp});
break;
case 3:
let temp3 = this.state.runningSetup.substring(31, 41);
this.setState({runningSetup: temp});
break;
}
switch(selected) {
/*case 0:
let temp = this.state.runningSetup+' ft-active-tab';
this.setState({runningSetup: temp});
break;*/
case 0:
let temp4 = this.state.runningSetup.substring(0, 32);
this.setState({runningSetup: temp});
break;
case 1:
let temp5 = this.state.runningSetup.substring(0, 33);
this.setState({runningSetup: temp});
break;
case 2:
let temp6 = this.state.runningSetup.substring(0, 34);
this.setState({runningSetup: temp});
break;
case 3:
let temp7 = this.state.runningSetup.substring(0, 31);
this.setState({runningSetup: temp});
break;
}
}
}
render () {
// service changes need to be done
let isActiveSecond= managedProductActivationDate < past1Day;
// let {sportsPhone, runningSnapshot, runningPositions, runningPerformance} = this.props;
let managedProductActivationDate = this.props.sportsPhone.managedProductActivationDate;
let past1Day = moment().subtract(1, 'days').format('YYYY-MM-DD');
// let isActive= managedProductActivationDate < past1Day;
//let selectedTab = 0;
return (
<height selected={ this.state.selectedTab}>
<weight label="Account Setup" subtitle="Days 1 and 2" liClass={ this.state.runningSetup}>
<div>
<AccountSetupTab sportsPhone={this.props.sportsPhone} isActiveSecond={this.props.isActive} />
</div>
</weight>
<weight label="Investments Purchase" subtitle="Approx. Day 3" liClass={this.state.investmentPurchase}>
<div className="sports-tab-content">
<p className="sports-large-text ft-day1 ft-day2">
Once we verify your deposit and your running has been funded, we’ll start purchasing ETFs for your portfolio.
</p>
</div>
</weight>
<weight label="Balance and Portfolio" subtitle="Approx. Day 4" liClass={this.state.balancePortfolio}>
<div >
<BalancePortfolio portfolio={this.props.portfolio} />
</div>
</weight>
<weight label="Performance" subtitle="Approx. Day 5" liClass={this.state.performance}>
<div className="sports-tab-content">
<p className="sports-large-text ft-day1 ft-day2 ft-day3 ft-day4">
You’ll be able to monitor your portfolio as it responds to daily market changes.
</p>
</div>
</weight>
</height>
);
}
}
FirstTimeTab.propTypes = {
sportsPhone: React.PropTypes.object.isRequired,
runningSnapshot: React.PropTypes.object.isRequired,
runningPositions: React.PropTypes.object.isRequired,
runningPerformance: React.PropTypes.object.isRequired,
portfolio: React.PropTypes.object.isRequired,
managedProductActivationDate: React.PropTypes.object.isRequired
};
function select(state) {
return {
sportsPhone: state.sportsPhone,
runningSnapshot: React.PropTypes.object.isRequired,
runningPositions: React.PropTypes.object.isRequired,
runningPerformance: React.PropTypes.object.isRequired,
portfolio: state.portfolio,
past1Day: React.PropTypes.number,
isActive: React.PropTypes.object.isRequired
};
}
export default connect(select)(FirstTimeTab);
从“React”导入React;
从'react redux'导入{connect};
从“力矩”中导入力矩;
从“/jump player选项卡内容”导入高度;
从“/jump player窗格内容”导入权重;
从“/运行安装程序”导入AccountSetupTab;
从“./余额组合”导入余额组合;
类FirstTimeTab扩展了React.Component{
建造师(道具){
超级(道具);
此.state={
runningSetup:“跳转玩家激活”,
投资购买:“体育投资ico”,
平衡组合:“运动平衡ico”,
表演:“体育表演ico”,
所选选项卡:0
};
}
组件willmount(){
让{sportsPhone,runningSnapshot,runningPositions,runningPerformance}=this.props;
让managedProductActivationDate=this.props.SportPhone.managedProductActivationDate;
让pass1day=moment().减去(1,'days')。格式('YYYY-MM-DD');
让isActive=managedProductActivationDate<过去1天;
如果(SportPhone!=''&&!isActive){
这是我的国家({
已选择选项卡:0,
跑步设置:“运动设置ico跳跃玩家活动ft活动选项卡”
});
}else if(isActive){
这是我的国家({
所选选项卡:1,
运行设置:“运动设置ico ft上一天”,
投资购买:“体育投资ico跳跃玩家活动ft活动选项卡”
});
}else if(runningSnapshot!==未定义&&runningPositions.positions.length>0){
这是我的国家({
选择选项卡:2,
运行设置:“ft上一天”,
投资购买:“金融时报前一天”,
平衡组合:“运动平衡ico跳跃玩家活动ft活动选项卡”
});
}else if(运行性能!==未定义){
这是我的国家({
选择选项卡:3,
运行设置:“dft上一天”,
投资购买:“金融时报前一天”,
余额组合:“金融时报上一天”,
性能:“运动性能ico跳跃玩家激活ft激活选项卡”
});
}
}
回调(已选择的选项卡){
如果(this.state.selectedTab!==selectedTab){
开关(this.state.selected){
案例0:
设temp=this.state.runningSetup.substring(32,45);
this.setState({runningSetup:temp});
打破
案例1:
设temp1=this.state.runningSetup.substring(33,46);
this.setState({runningSetup:temp});
打破
案例2:
设tem2=this.state.runningSetup.substring(34,47);
this.setState({runningSetup:temp});
打破
案例3:
设temp3=this.state.runningSetup.substring(31,41);
this.setState({runningSetup:temp});
打破
}
开关(选定){
/*案例0:
设temp=this.state.runningSetup+'ft active tab';
this.setState({runningSetup:temp});
中断*/
案例0:
设temp4=this.state.runningSetup.substring(0,32);
this.setState({runningSetup:temp});
打破
案例1:
设temp5=this.state.runningSetup.substring(0,33);
this.setState({runningSetup:temp});
打破
案例2:
设temp6=this.state.runningSetup.substring(0,34);
this.setState({runningSetup:temp});
打破
案例3:
设temp7=this.state.runningSetup.substring(0,31);
this.setState({runningSetup:temp});
打破
}
}
}
渲染(){
//需要进行服务更改
让isActiveSecond=managedProductActivationDate<过去1天;
//让{sportsPhone,runningSnapshot,runningPositions,runningPerformance}=this.props;
让managedProductActivationDate=this.props.SportPhone.managedProductActivationDate;
让pass1day=moment().减去(1,'days')。格式('YYYY-MM-DD');
//让isActive=managedProductActivationDate<过去1天;
//设selectedTab=0;
返回(
一旦我们确认您的存款和您的跑步资金已经到位,我们将开始为您的投资组合购买ETF。
您将能够监控您的投资组合,因为它对每日市场变化作出响应。
);
}
}
FirstTimeTab.propTypes={
sportsPhone:React.PropTypes.object.isRequired,
茹
componentWillMount
componentDidMount