Som*_*ame 0 javascript ternary-operator reactjs
我想显示基于状态值的组件。我的
import React, {Component} from 'react';
import One from './One'
import Two from './Two'
import Three from './Three'
class MyTest extends Component{
constructor(props){
super(props);
this.state = {
slide: 1
}
}
handleClick=()=>{
const counter=this.state.slide;
this.setState({
slide:counter+1
})
}
render(){
return (
<div onClick={this.handleClick}>
{this.state.slide===1 ? <One /> :
{this.state.slide===2 ? <Two /> : <Three /> } }
</div>
)
}
}
export default MyTest;
Run Code Online (Sandbox Code Playgroud)
我得到了错误:{this.state.slide===2 Parsing error: Unexpected keyword 'this'
我在做什么错?
无需{ and }内部内部三元
{this.state.slide===1 ? <One /> :
this.state.slide===2 ? <Two /> : <Three /> }
Run Code Online (Sandbox Code Playgroud)