setState bug
showzyl opened this issue · comments
Lizi commented
componentDidMount 里 setState render 不执行。
class Page109 extends Component {
constructor(props) {
super(props);
this.state = {
show: false
}
}
componentDidMount() {
this.setState({
show: true
}, () => {
console.log(`componentDidMount here: `)
console.log(`this.state: `, this.state)
})
}
render() {
let img = utils.isSupportWebp() ? require('./assets/1.webp') : require('./assets/1.jpg')
console.log(`render state: `, this.state)
return (
<div className="page109">
<img className="imgs" src={img} alt=""/>
<div className="box">
<img src={require('./assets/2.jpg')}/>
{this.state.show ? <ul className="">
我是内容
</ul> : ""}
</div>
</div>
)
}
}
export default Page109
Austin Lee commented
https://code.h5jun.com/haxer/edit?html,js,console,output 直接用你的 DEMO 试了下并没有问题诶