Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setState bug #1072

Open
showzyl opened this issue Jul 3, 2019 · 1 comment
Open

setState bug #1072

showzyl opened this issue Jul 3, 2019 · 1 comment

Comments

@showzyl
Copy link

showzyl commented Jul 3, 2019

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
@lizheming
Copy link
Contributor

https://code.h5jun.com/haxer/edit?html,js,console,output 直接用你的 DEMO 试了下并没有问题诶

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants