It is worth the problem that react changes the number in state.

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.

Mar.17,2021

the variable before the subscript is ubdefined, that is, this.props.data is undefined


error means that your data attribute does not exist


this.props.data data does not get


the reason for this error is that one of your this.props.data or this.props.dataT is undefined,. You can print these two values and see

.
Menu