[TQRCode] devcieInfo null
This commit is contained in:
@@ -1,9 +1,19 @@
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
import React, {
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import {
|
||||
useDispatch,
|
||||
useSelector,
|
||||
} from 'react-redux';
|
||||
|
||||
import { getDeviceAdditionInfo } from "../../actions/deviceActions";
|
||||
import { scaleH, scaleW } from "../../utils/helperMethods";
|
||||
import { getDeviceAdditionInfo } from '../../actions/deviceActions';
|
||||
import {
|
||||
scaleH,
|
||||
scaleW,
|
||||
} from '../../utils/helperMethods';
|
||||
|
||||
export default function TQRCode({
|
||||
ariaLabel,
|
||||
@@ -23,7 +33,7 @@ export default function TQRCode({
|
||||
}, [deviceInfo, dispatch]);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window === "object" && deviceInfo && entryMenu && nowMenu) {
|
||||
if (typeof window === "object" && entryMenu && nowMenu) {
|
||||
if (qrcodeRef.current) {
|
||||
while (qrcodeRef.current.firstChild) {
|
||||
qrcodeRef.current.removeChild(qrcodeRef.current.firstChild);
|
||||
@@ -34,21 +44,20 @@ export default function TQRCode({
|
||||
const encodedNowMenu = encodeURIComponent(nowMenu);
|
||||
const encodeEntryMenu = encodeURIComponent(entryMenu);
|
||||
|
||||
let idx;
|
||||
|
||||
if (deviceInfo === null) {
|
||||
idx = 0;
|
||||
}
|
||||
idx = deviceInfo.dvcIndex;
|
||||
|
||||
const qrcode = new window.QRCode(qrcodeRef.current, {
|
||||
text: `${text}&entryMenu=${encodeEntryMenu}&nowMenu=${encodedNowMenu}&idx=${deviceInfo.dvcIndex}`,
|
||||
text: `${text}&entryMenu=${encodeEntryMenu}&nowMenu=${encodedNowMenu}&idx=${idx}`,
|
||||
width: scaleW(width),
|
||||
height: scaleH(height),
|
||||
correctLevel: window.QRCode.CorrectLevel.L,
|
||||
});
|
||||
}
|
||||
// else if (typeof window === "object") {
|
||||
// const qrcode = new window.QRCode(qrcodeRef.current, {
|
||||
// text: `${text}`,
|
||||
// width: scaleW(width),
|
||||
// height: scaleH(height),
|
||||
// correctLevel: window.QRCode.CorrectLevel.L,
|
||||
// });
|
||||
// }
|
||||
}, [text, deviceInfo, entryMenu, nowMenu]);
|
||||
return <div aria-label={ariaLabel} ref={qrcodeRef} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user