the code is as follows:
//
longBtnClick=()=>{
this.setState((prev)=>({
ifNextScenes:true,
step:prev.step+1 //step0
}),()=>{
setTimeout(()=>{
this.setState({
ifNextScenes:false
})
},300);
})
}
//render
<img className="mainImg" src={
this.state.onSwitch?this.props.data[parseInt(this.state.step)].text //this.state.step1
:
this.props.dataT[parseInt(this.state.step)]
} />
problem: everything is fine when loading by default for the first time, but when clicked, it prompts the following error:
Uncaught TypeError: Cannot read property"1" of undefined
Why did you report an error of 1? it"s just a subscript, not a variable? Array to confirm that there is a subscript.