QRCode 중복으로 쌓이는 현상 수정
This commit is contained in:
@@ -1,22 +1,23 @@
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
|
||||
//!!raw-loader!../../utils/qrcode.min.js
|
||||
import QRCodeMin from "!!raw-loader!../../utils/qrcode.min.js";
|
||||
import QRCodeMin from "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(() => {
|
||||
let script = document.createElement("script");
|
||||
script.innerText = QRCodeMin;
|
||||
|
||||
document.body.appendChild(script);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
console.log("#text", text);
|
||||
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user