javascripttypescriptreact-nativecommand-line-interfaceqr-code

How to scan a qr code in React Native cli?


Is there anyone who has a tutorial or code how to read a qr code in React Native cli that actually works in the current React Native version? I tried so many tutorials and docs and nothing works. It would be nice if it works in tsx.


Solution

  • Use the react-native-qrcode-scanner package in React Native to scan QR codes. Here is an illustration of how you may employ it:

    import QRCodeScanner from 'react-native-qrcode-scanner';
    
    const MyQRCodeScanner = () => {
      const onSuccess = (e) => {
        console.log(e.data);
        // e.data contains the QR code data
      };
    
      return (
        <QRCodeScanner onRead={onSuccess} />
      );
    };