import React, { Component } from 'react'
export default class
extends Component {
state={
show:true
}
f1=()=>{
this.setState({
show:!this.state.show
})
}
render() {
return (
<div>
<button onClick={this.f1}>隐藏/显示</button>
方法一
<h1 style={{display:this.state.show?'block':'none'}}>hello world</h1>
方法二
{this.state.show?(<div>hello world</div>):(<></>)}
</div>
)
}
}