简体   繁体   中英

Custom modal is displaying despite condition not met in ReactJS?

On my log in page I want to show a modal with a picture when a failed login attempt is made.

in my render() I have this exert:

<ToggleDisplay show={this.state.failedLogin} tag="section">
    <Lightbox show={this.state.failedLogin} mainSrc={pic}  hideOnOverlayClicked 
    </Lightbox>
</ToggleDisplay>

The problem I'm having is the picture is shown when the page is loaded even though show=false by default. How do I have the picture display only when show=true?

How about doing like this:

{ this.state.failedLogin && (
 <ToggleDisplay tag="section">
   <Lightbox show={this.state.failedLogin} mainSrc={pic}  
     hideOnOverlayClicked 
   </Lightbox>
 </ToggleDisplay>
)}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM