user12522448
user12522448

Reputation: 73

Howe hide and visible img in React?

Add button and image. When you click on the button, hide the image; when you click again, show.

 <img src="https://image.flaticon.com/icons/svg/2460/2460099.svg" />
  <button onClick={this.btn}>Count</button>

Upvotes: 0

Views: 254

Answers (1)

Gaurav Roy
Gaurav Roy

Reputation: 12215

you can maintain a state for the same, like

{this.state.isImageVisible?<img src="https://image.flaticon.com/icons/svg/2460/2460099.svg" />:<div></div>}   

      <button onClick={this.btn}>Count</button>

and on click of button ,

do this

btn =() => {

this.setState({isImageVisible:!this.state.isImageVisible});


}

Hope it helps

Upvotes: 2

Related Questions