react-qr-code is a JavaScript library providing a `<QRCode />` component for generating and rendering QR codes within both React and React Native applications. As of version 2.0.18, the library is actively maintained with frequent patch releases, ensuring compatibility and addressing minor bugs. It differentiates itself by offering a consistent API for both web and mobile platforms, leveraging `react-native-svg` for its React Native implementation. The component strictly adheres to the official QR code specification, supporting various error correction levels and substantial data capacities, making it a reliable choice for easily integrating QR code generation into the React ecosystem.
npm install react-qr-codeVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to render a basic, responsive QR code component in a React application. It includes a user input field to dynamically update the QR code's content and applies essential styling to ensure a proper 'quiet zone' for scannability.
Run `npm install react-native-svg` (or `yarn add react-native-svg`) and then `cd ios && pod install` for iOS projects.
Always wrap the `<QRCode />` component in a container with sufficient light-colored padding, for example: `<div style={{ background: 'white', padding: '16px' }}><QRCode value='...' /></div>`.Use `import QRCode from 'react-qr-code';` for ES modules or `const QRCode = require('react-qr-code');` for CommonJS environments.Ensure your React environment and type definitions are compatible with React 19. If issues arise, consider upgrading React or adjusting custom rendering logic to match `ReactNode` return types.
Install `react-native-svg` via `npm install react-native-svg` (or `yarn add react-native-svg`) and then navigate to your `ios` directory and run `pod install`.
Change your import statement from `import { QRCode } from 'react-qr-code';` to `import QRCode from 'react-qr-code';`.Add a white or light-colored background with adequate padding around the `<QRCode />` component (e.g., `<div style={{ background: 'white', padding: '16px' }}><QRCode ... /></div>`). Also, ensure `fgColor` and `bgColor` props provide strong contrast.