if-else

  1. class App extends React.Component {
  2. constructor(props) {
  3. super(props);
  4. this.state = {
  5. isShow:true
  6. }
  7. }
  8. render() {
  9. return (
  10. <div>
  11. {this.Message()}
  12. </div>
  13. )
  14. }
  15. Message(){
  16. if(this.state.isShow){
  17. return (<span>显示</span>)
  18. }else{
  19. return (<span>隐藏</span>)
  20. }
  21. }
  22. }
  23. export default App;

三元

  1. <p>{this.state.isShow?'good':'hello world'}</p>

for map

  1. <div>{this.state.arr.map(item=>{
  2. return (<p>{item}</p>)
  3. })}</div>
  4. </div>