What is qrcode.react?
The qrcode.react npm package is a React component that uses the 'qrcode-generator' library to render QR codes as SVGs in React applications. It allows for easy creation and customization of QR codes directly within React components.
What are qrcode.react's main functionalities?
Generating a basic QR code
This feature allows you to generate a simple QR code by passing a string as the 'value' prop to the QRCode component.
{"import QRCode from 'qrcode.react';\n\nconst MyComponent = () => (\n <QRCode value='http://facebook.github.io/react/' />\n);"}
Customizing the QR code
This feature enables customization of the QR code by setting props such as 'size' for dimension, 'bgColor' for background color, 'fgColor' for foreground color, and 'level' for error correction level.
{"import QRCode from 'qrcode.react';\n\nconst MyComponent = () => (\n <QRCode\n value='http://facebook.github.io/react/'\n size={256}\n bgColor={'#ffffff'}\n fgColor={'#000000'}\n level={'H'}\n />\n);"}
Including a logo or image in the center of the QR code
This feature allows for the inclusion of a logo or image in the center of the QR code. The 'imageSettings' prop can be used to provide the image source and other related settings.
{"import QRCode from 'qrcode.react';\n\nconst MyComponent = () => (\n <QRCode\n value='http://facebook.github.io/react/'\n size={256}\n bgColor={'#ffffff'}\n fgColor={'#000000'}\n level={'H'}\n includeMargin={true}\n imageSettings={{\n src: 'path/to/logo.png',\n x: null,\n y: null,\n height: 24,\n width: 24,\n excavate: true,\n }}\n />\n);"}
Other packages similar to qrcode.react
qrcode
The 'qrcode' package is a more general QR code generator that can be used in both browser and server environments. It provides a wider range of options for generating QR codes, including output formats like PNG, UTF8, and others. Unlike qrcode.react, it is not specifically tailored for React and does not render as a React component.
react-qr-code
The 'react-qr-code' package is another React component for generating QR codes. It is similar to qrcode.react in that it is designed for React and renders QR codes as SVGs. However, it may have different customization options and dependencies.
react-native-qrcode-svg
The 'react-native-qrcode-svg' package is designed for React Native applications and allows for the generation of QR codes as SVG elements. It is similar to qrcode.react but is specifically built for the React Native environment rather than for web applications.
qrcode.react
A React component to generate QR codes.
Installation
npm install qrcode.react
Usage
var React = require('react');
var QRCode = require('qrcode.react');
React.render(
<QRCode value="http://facebook.github.io/react/" />,
mountNode
);
Available Props
prop | type | default value |
---|
value | string | |
size | number | 128 |
bgColor | string (CSS color) | "#FFFFFF" |
fgColor | string (CSS color) | "#000000" |