VOOZH about

URL: https://www.geeksforgeeks.org/react-native/create-a-qr-code-generator-app-using-react-native/

⇱ Create a QR Code Generator App using React-Native - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Create a QR Code Generator App using React-Native

Last Updated : 23 Jul, 2025

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.

πŸ‘ Create-a--QR-Code-Generator

To give you a better idea of what we’re going to create, let’s watch a demo video.

Demo Video


Playground

Note: This Section is to interact with the app which you are going to build.


Prerequisites / Technologies Used

Step-by-Step Implementation

Step 1: Create a React Native Project

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.

πŸ‘ Image

It completes the project creation and displays a message: "Your Project is ready!" as shown in the image below.

πŸ‘ Image

Now go into your project folder, i.e., react-native-demo

cd app-name

Project Structure:

πŸ‘ Image

Step 2: Run  Application

Start the server by using the following command.

npx expo start

Then, the application will display a QR code.

  • For the Android users,
    • For the Android Emulator, press " a" as mentioned in the image below.
    • For the Physical Device, download the " Expo Go " app from the Play Store. Open the app, and you will see a button labeled " Scan QR Code. " Click that button and scan the QR code; it will automatically build the Android app on your device.
  • For iOS users, simply scan the QR code using the Camera app.
  • If you're using a web browser, it will provide a local host link that you can use as mentioned in the image below.
πŸ‘ Image

Step 3: Install libraries

Package.json

{
"dependencies": {
"react-native-paper": "^5.14.0",
"react-native-qrcode-svg": "^6.3.15"
}
}

Now, run the below command.

npm install

Step 4: Start Coding

- :

In this approach, the React Native code defines

  • Functional Component: a functional component named QRCodeGenerator. It uses React Hooks, including useState, to manage component state.
  • State Management: The component uses useState to manage state variables for the QR code value (qrValue) and its activation (isActive).
  • User Input Handling: It captures and updates user input in the TextInput field and toggles isActive when input is present.
  • QR Code Generation: A QR code is generated using the react-native-qrcode-svg package when the "Generate QR Code" button is pressed.
  • Styling: The app is styled with CSS-in-JS using StyleSheet.create for consistent design, including shadows, text, and button styles.
  • Component Structure: The app's UI is structured into a container with a title, description, input field, button, and conditional rendering of the QR code display based on user interaction.

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.

Complete Source Code

App.js:

Output


Comment

Explore