A simple QR code scanner component for React.
npm install react-qrcode-scanner-mi``bash`
npm install --save react-qrcode-scanner-mi
`jsx
import React, { useState } from 'react';
import { QrScanner } from 'react-qrcode-scanner-mi'; // Correct named import
function App() {
const [scannedData, setScannedData] = useState(null); // Store the scanned QR code value
// This function will be triggered when a QR code is scanned
const handleScan = (data) => {
if (data) {
setScannedData(data); // Set the scanned QR code value to state
}
};
// This function will be triggered if there's an error while scanning
const handleError = (err) => {
console.error("Error scanning QR Code: ", err);
};
return (
{/ Pass the handleScan function to the onScan prop /}
onError={handleError}
/>
{/ Display the scanned data /}
{scannedData && (
{scannedData}
export default App;
``
MIT © miteshdevg