lazy-load qrcode

This commit is contained in:
Martti Malmi 2023-08-31 21:00:51 +03:00
parent 97cbc39303
commit 0bcf1b8822
2 changed files with 11 additions and 10 deletions

View File

@ -1,8 +1,6 @@
import { createRef } from 'preact';
import { useEffect } from 'preact/hooks';
import QRCode from '../lib/qrcode.min';
export default function Qr(props) {
const ref = createRef();
//const [qr, setQr] = useState(null);
@ -11,13 +9,16 @@ export default function Qr(props) {
if (!ref.current) {
return;
}
new QRCode(ref.current, {
text: props.data,
width: props.width || 300,
height: props.width || 300,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: QRCode.CorrectLevel.H,
import('../lib/qrcode.min').then((module) => {
const QRCode = module.default;
new QRCode(ref.current, {
text: props.data,
width: props.width || 300,
height: props.width || 300,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: QRCode.CorrectLevel.H,
});
});
}, [props.data]);

View File

@ -14,7 +14,7 @@ type Tag = {
value: string;
};
export class MyDexie extends Dexie {
class MyDexie extends Dexie {
events!: Table<Event & { id: string }>;
tags!: Table<Tag>;