QR Code Implementation in React.js in 5 mins.

Angad Srivastav
2 min readMay 23, 2021

--

QR Codes are very useful in storing information that can be shared very easily. QR Code allows a user to store information in form of an image that can be shared on any medium. Think of a link to your website as an image which eventually when scanned will lead to your webpage. In this tutorial, I will show you how you can easily implement a QR Code which will have some textual information embedded inside it which you can share.

For the purpose of this tutorial you will need to install the following NPM package:

QRcode.react (https://www.npmjs.com/package/qrcode.react)

First, we will need to start a react application. The quickest way to do so is by creating a react application with npx create-react-app. Once you run this command it will generate the boilerplate react app for you.

Next, we will import the package we require for QRcode implementation.

Once that is done we will finally place our QRcode package in our render logic. The QRCode package expects many props but the most essential prop for it to work is the value prop. The value prop will be the value that you want your users to obtain once they have scanned your QR code. This value can only be a string.

You can render the QR code as an SVG or as a canvas. You can also specify its size. For more props please do read its documentation. This code will generate the following output.

And this is how you can implement QRcode in your react.js applications. For code of the following project please visit my GitHub repository.

--

--

Angad Srivastav

Hi I am Angad and I'm a full-stack developer. I design and develop beautiful simple things, and I love what I do.