How can I insert an image into state (React) [closed]

Could be like this:

import React, { useState } from "react";
import img from "./img/img.jpg";

const ShowImage = () => {
  const [isVisible, setIsVisible] = useState(true);
  return (
    <div>
      <button onClick={() => setIsVisible(!isVisible)}>
        {isVisible ? "Hide" : "Show"}
      </button>
      {isVisible && <img src={img} alt="img" />}
    </div>
  );
};

export default ShowImage; 

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top