![]() |
VOOZH | about |
In this article, we will walk you through the process of building a QR Code Generator app using React Native. A QR Code Generator App is a mobile application that allows users to create QR codes from text or URLs. It generates QR codes, which can store information such as website links, contact details, or other data, for easy sharing and scanning by others.
To give you a better idea of what weβre going to create, letβs watch a demo video.
Note: This Section is to interact with the app which you are going to build.
Now, create a project with the following command.
npx create-expo-app app-name --template
Note: Replace the app-name with your app name for example : react-native-demo-app
Next, you might be asked to choose a template. Select one based on your preference as shown in the image below. I am selecting the blank template because it will generate a minimal app that is as clean as an empty canvas in JavaScript.
It completes the project creation and displays a message: "Your Project is ready!" as shown in the image below.
Now go into your project folder, i.e., react-native-demo
cd app-nameStart the server by using the following command.
npx expo startThen, the application will display a QR code.
Package.json
{
"dependencies": {
"react-native-paper": "^5.14.0",
"react-native-qrcode-svg": "^6.3.15"
}
}
Now, run the below command.
npm installIn this approach, the React Native code defines
Let's dive into the code in detail.
Import required libraries at the top of the file.
Create a StyleSheet to style components like container, wrapper, title, etc.
This title and Subtitle explain what the app does. We use the text "QR Code Generator" as the title, "Paste a URL or enter text to create a QR code" as the subtitle, to show that the app is to generate QR Codes.
This TextInput is used to receive input from the user. We will show what the user types using a variable called "qrValue." When you type or change text in the TextInput, we will use the handleInputChange function to update the value. If the user clears the input in the TextInput, we will set the isActive state to false using the setIsActive function. This will help us decide whether to display the QR code or not.
This button is used to call the generateQRCode function when the user taps on it. It is made with the TouchableOpacity component, which makes the Text component interactive for the user.
This function checks if the qrvalue is false. If it is false, it doesn't do anything. If it's not false, it updates the isActive value by calling setIsActive with true as the argument.
We will display the QR Code only when the value of isActive is true using the QRCode component.
Now, wrap all design code with a View component, return it from the App component, and place all methods and useStates within the App component. Ensure to export the App.
App.js: