Receiving an error: “function components cannot be given refs” when trying to add a download option for a generated QR code

I am receiving an error in react when trying to add a download option for a generated QR code. The error states “Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?”. Note that I am new to react and not sure where to implement this “forwardRef” option. Here is my code:

import React, { useState, useRef } from "react";
import {
  Container,
  Row,
  Col,
  Button,
  ToggleButtonGroup,
  ToggleButton,
  InputGroup,
  FormControl,
} from "react-bootstrap";
import QRCode from "qrcode.react";

const LinkQRPage = () => {
  const [link, setLink] = useState(""); // State for input link
  const [qrOptions, setQROptions] = useState({
    size: 256,
    bgColor: "#FFFFFF",
    fgColor: "#000000",
    level: "H",
    includeMargin: false,
    imageOptions: {
      type: "url",
      src: "",
      file: null,
      width: 40,
      height: 40,
    },
  });

  const qrCanvasRef = useRef(null); // Ref to hold QR code canvas element

  // Function to handle form submission
  const handleSubmit = (e) => {
    e.preventDefault();
    console.log(
      "Generating QR code with link:",
      link,
      "and options:",
      qrOptions
    );
  };

  // Function to handle input change for link
  const handleLinkChange = (e) => {
    setLink(e.target.value);
  };

  // Function to handle input change for styling options
  const handleOptionChange = (name, value) => {
    setQROptions((prevState) => ({
      ...prevState,
      [name]: value,
    }));
  };

  // Function to handle file upload for image
  const handleFileUpload = (e) => {
    const file = e.target.files[0];
    if (file) {
      const reader = new FileReader();
      reader.readAsDataURL(file);
      reader.onloadend = () => {
        setQROptions((prevState) => ({
          ...prevState,
          imageOptions: {
            ...prevState.imageOptions,
            type: "file",
            src: reader.result,
            file: file,
          },
        }));
      };
    }
  };

  // Function to handle QR code size change
  const handleQRSizeChange = (e) => {
    const newSize = parseInt(e.target.value, 10);
    setQROptions((prevState) => ({
      ...prevState,
      size: newSize,
    }));
  };

  // Function to handle downloading the QR code
  const handleDownload = () => {
    if (qrCanvasRef.current !== null) {
      const canvas = qrCanvasRef.current._canvas; // Accessing the canvas element
      const imageDataUrl = canvas.toDataURL("image/png");
      const downloadLink = document.createElement("a");
      downloadLink.href = imageDataUrl;
      downloadLink.download = "QRCode.png";
      document.body.appendChild(downloadLink);
      downloadLink.click();
      document.body.removeChild(downloadLink);
    }
  };

  return (
    <Container className="mt-5 mb-5">
      <Row>
        <Col md={8} className="left-side-qr">
          <h1>LinkQR</h1>
          <form onSubmit={handleSubmit}>
            <div className="mb-3">
              <label htmlFor="linkInput" className="form-label">
                Link
              </label>
              <input
                type="text"
                className="form-control"
                id="linkInput"
                placeholder="Enter your link"
                value={link}
                onChange={handleLinkChange}
              />
            </div>
            <div className="mb-3">
              <label htmlFor="sizeInput" className="form-label">
                QR Code Size
              </label>
              <input
                type="number"
                className="form-control"
                id="sizeInput"
                name="size"
                value={qrOptions.size}
                onChange={handleQRSizeChange}
                min="64"
                max="256"
              />
            </div>
            <div className="mb-3">
              <label htmlFor="bgColorInput" className="form-label">
                Background Color
              </label>
              <input
                type="color"
                className="form-control"
                id="bgColorInput"
                name="bgColor"
                value={qrOptions.bgColor}
                onChange={(e) =>
                  handleOptionChange(e.target.name, e.target.value)
                }
              />
            </div>
            <div className="mb-3">
              <label htmlFor="fgColorInput" className="form-label">
                Foreground Color
              </label>
              <input
                type="color"
                className="form-control"
                id="fgColorInput"
                name="fgColor"
                value={qrOptions.fgColor}
                onChange={(e) =>
                  handleOptionChange(e.target.name, e.target.value)
                }
              />
            </div>
            <div className="mb-3">
              <label className="form-label">Image Type</label>
              <ToggleButtonGroup
                type="radio"
                name="imageType"
                value={qrOptions.imageOptions.type}
                onChange={(value) => handleOptionChange("imageType", value)}
              >
                <ToggleButton id="url-toggle" value="url">
                  URL
                </ToggleButton>
                <ToggleButton id="file-toggle" value="file">
                  Upload
                </ToggleButton>
              </ToggleButtonGroup>
            </div>
            {qrOptions.imageOptions.type === "url" && (
              <div className="mb-3">
                <label htmlFor="imageSrcInput" className="form-label">
                  Image Source (URL)
                </label>
                <input
                  type="text"
                  className="form-control"
                  id="imageSrcInput"
                  name="imageSrc"
                  placeholder="Enter image URL"
                  value={qrOptions.imageOptions.src}
                  onChange={(e) =>
                    handleOptionChange("imageSrc", e.target.value)
                  }
                />
              </div>
            )}
            {qrOptions.imageOptions.type === "file" && (
              <div className="mb-3">
                <label htmlFor="imageFileInput" className="form-label">
                  Upload Image
                </label>
                <input
                  type="file"
                  className="form-control"
                  id="imageFileInput"
                  name="imageFile"
                  onChange={handleFileUpload}
                />
              </div>
            )}
            <div className="mb-3">
              <label htmlFor="imageWidthInput" className="form-label">
                Image Width (Optional)
              </label>
              <InputGroup>
                <FormControl
                  type="number"
                  id="imageWidthInput"
                  name="imageWidth"
                  placeholder="Width"
                  value={qrOptions.imageOptions.width}
                  onChange={(e) =>
                    handleOptionChange("imageWidth", e.target.value)
                  }
                  aria-label="Image width"
                />
                <InputGroup.Text>px</InputGroup.Text>
              </InputGroup>
            </div>
            <div className="mb-3">
              <label htmlFor="imageHeightInput" className="form-label">
                Image Height (Optional)
              </label>
              <InputGroup>
                <FormControl
                  type="number"
                  id="imageHeightInput"
                  name="imageHeight"
                  placeholder="Height"
                  value={qrOptions.imageOptions.height}
                  onChange={(e) =>
                    handleOptionChange("imageHeight", e.target.value)
                  }
                  aria-label="Image height"
                />
                <InputGroup.Text>px</InputGroup.Text>
              </InputGroup>
            </div>
            <Button variant="primary" type="submit">
              Generate QR Code
            </Button>
          </form>
        </Col>

        <Col
          md={4}
          className="right-side-qr d-flex align-items-center justify-content-center"
        >
          <div style={{ width: "100%", textAlign: "center" }}>
            <h1>Preview</h1>
            <div style={{ width: "80%", margin: "0 auto" }}>
              <QRCode
                ref={qrCanvasRef} // Ref to access QR code canvas element
                size={256} // Fixed size for the preview
                value={link}
                bgColor={qrOptions.bgColor}
                fgColor={qrOptions.fgColor}
                includeMargin={qrOptions.includeMargin}
                imageSettings={{
                  src: qrOptions.imageOptions.src,
                  x: null,
                  y: null,
                  height: qrOptions.imageOptions.height,
                  width: qrOptions.imageOptions.width,
                  excavate: true,
                }}
              />
            </div>
            <div className="mt-3">
              <Button variant="success" onClick={handleDownload}>
                Download QR Code
              </Button>
            </div>
          </div>
        </Col>
      </Row>
    </Container>
  );
};

export default LinkQRPage;

I tried multiple suggestions, but unsure where to implement it. Just looking for advice or pointers in the right direction.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật