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 (
      <button onClick={() => setIsVisible(!isVisible)}>
        {isVisible ? "Hide" : "Show"}
      {isVisible && <img src={img} alt="img" />}

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