Closed a-creation closed 2 years ago
This isn't a bug with the library. You're using it inside React Native, and that QR code library depends on the DOM.
@jordansexton What is the best practice to generate this QR code within React Native?
I couldn't tell you specifically :)
But it's just a URL string that's being encoded, so any QR code library that works natively or without requiring the DOM should be good.
@a-creation A little late, but here is a good QR Code library for react-native.
Example:
import React from 'react';
import QRCode from 'react-native-qrcode-svg';
import { encodeURL } from '@solana/pay';
const MyComponent: React.FC = () => {
const url = 'https://...'; // Your url here
const encoded = encodeURL({ link: new URL(url) });
return (
<QRCode
value={encoded.toString()}
size={300}
/>
);
};
After following documentation specification for using the createQR(url), createQR errors: ReferenceError: Can't find variable: document.
const url = encodeURL({ recipient, amount, splToken, reference, label, message, memo }); const qrCode = createQR(url);