30 lines
808 B
JavaScript
30 lines
808 B
JavaScript
import React, { useEffect, useRef, useState } from "react";
|
|
|
|
//!!raw-loader!../../utils/qrcode.min.js
|
|
import QRCodeMin from "!!raw-loader!../../utils/qrcode.min.js";
|
|
|
|
let script = document.createElement("script");
|
|
script.innerText = QRCodeMin;
|
|
document.body.appendChild(script);
|
|
|
|
export default function TQRCode({ text, width = "128", height = "128" }) {
|
|
const qrcodeRef = useRef(null);
|
|
|
|
useEffect(() => {
|
|
if (typeof window === "object") {
|
|
if (qrcodeRef.current) {
|
|
while (qrcodeRef.current.firstChild) {
|
|
qrcodeRef.current.removeChild(qrcodeRef.current.firstChild);
|
|
}
|
|
}
|
|
|
|
const qrcode = new window.QRCode(qrcodeRef.current, {
|
|
text: text,
|
|
width: width,
|
|
height: height,
|
|
});
|
|
}
|
|
}, [text]);
|
|
return <div ref={qrcodeRef} />;
|
|
}
|