import { Button, Loading } from '@nextui-org/react' import dynamic from 'next/dynamic' import Image from 'next/image' import { Fragment, useState } from 'react' /** * You can use normal import if you are not within next / ssr environment * @info https://nextjs.org/docs/advanced-features/dynamic-import */ const ReactQrReader = dynamic(() => import('react-qr-reader-es6'), { ssr: false }) /** * Types */ interface IProps { onConnect: (uri: string) => Promise } /** * Component */ export default function QrReader({ onConnect }: IProps) { const [show, setShow] = useState(false) const [loading, setLoading] = useState(false) function onError() { setShow(false) } async function onScan(data: string | null) { if (data) { await onConnect(data) setShow(false) } } function onShowScanner() { setLoading(true) setShow(true) } return (
{show ? ( {loading && }
setLoading(false)} showViewFinder={false} onError={onError} onScan={onScan} style={{ width: '100%' }} />
) : (
qr code icon
)}
) }