【发布时间】:2018-11-19 09:54:17
【问题描述】:
我知道这个问题已经被问过多次了, 但我仍然不知道如何修复我的代码。好像我不应该那样调用 setState 。但是我从material-ui网站上获取了示例代码,这应该是直截了当的吗?
class Dashboard extends React.Component {
constructor(props){
super(props);
this.state = {
activeStep: 0,
}
this.handleStep = this.handleStep.bind(this);
}
handleStep(step) {
this.setState({activeStep: step});
};
render(){
const { classes, match } = this.props;
const sprints = ['sprint 1', 'sprint 2', 'sprint 3'];
const { activeStep } = this.state;
return (
<div className= {classes.root}>
<div className = {classes.container} >
<Stepper nonLinear activeStep={activeStep} alternativeLabel>
{sprints.map((label,index)=>
{
return (
<Step key={label}>
<StepButton
onClick= {this.handleStep(index)}
>
{label}
</StepButton>
</Step>
)
})
}
</Stepper>
</div>
</div>
)
}
}
【问题讨论】:
标签: javascript reactjs material-ui