UNPKG

react-native-qrcode-styled

Version:

A fully customizable QR Code generator for React Native based on react-native-svg and javascript-qrcode.

27 lines (22 loc) 640 B
import { useMemo } from 'react'; import type { BitMatrix } from '../types'; import { createQRCode, QRCodeMessage, QRCodeOptions } from '../adapters/qrcode'; import { consoleError } from '../helpers'; export default function useQRCodeData( data: QRCodeMessage, options: QRCodeOptions ): { bitMatrix: BitMatrix; qrCodeSize: number } { const QRCodeData = useMemo(() => { try { return createQRCode(data, options); } catch (error) { consoleError(error); return; } }, [data, options]); const { size: qrCodeSize = 0, bitMatrix = [] } = QRCodeData || {}; return { bitMatrix, qrCodeSize, }; }