S
S
statxems2021-04-06 18:06:22
React
statxems, 2021-04-06 18:06:22

How to remove image and return on reclick React?

You need to add a button and an image. When you click on the button, hide the image, when you click again, show it.
I can not figure out how to do it correctly, what would the button be pressed. img disappeared, clicked again appeared, help)

HideImage() {
    this.setState({
      hideImage: '22'
    });
 }

<p>
            <button onClick={this.HideImage}>Hide Iamge</button>
          </p>
          <p>
              <img src={logo} style={{width: "150px"}} />
          </p>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-04-06
@0xD34F

const [ showImage, setShowImage ] = useState(true);

<button onClick={() => setShowImage(!showImage)}>click me</button>
{showImage ? <img src="..." /> : null}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question