Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • NextJS
  • Material UI
  • React Bootstrap
  • React Suite
  • Ant Design
  • Reactstrap
  • BlueprintJS
  • React Desktop
  • React Native
  • React Rebass
  • React Spring
  • React Evergreen
  • ReactJS
  • ReactJS
  • JS Formatter
  • Web Technology
Open In App
Next Article:
Create a Camera App using React-Native
Next article icon

Create a Voting App using React-Native

Last Updated : 25 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Voting involves assessing multiple entities based on specific criteria. This article guides the creation of a basic voting app, where users can compare and evaluate options. The application allows users to make choices, making it a valuable tool for decision-making and gathering opinions. We will create a Voting app using React-Native.

Preview Image:

Voting-app-using-react-native
Preview Image | Create a Voting App using React Native


Prerequisites:

  • Introduction to React Native
  • Introduction React Native Components
  • React Native State
  • React Native Props
  • Expo CLI
  • Node.js and npm (Node Package Manager)

Steps to install & configure React Native:

Step 1: Create a react native application by using this command:

npx create-expo-app basicNotes-app

Step 2: After creating your project folder, i.e. basicNotes-app, use the following command to navigate to it:

cd basicNotes-app

Step 3: Open App.js file, open it and paste the source code into it.

Example: In this example, we create an app displaying images of programming languages with voting buttons. The useState hook is used to manage the vote count, enabling the castVote function to update votes for each image. The app is structured with a ScrollView and styled using the StyleSheet module. Each image is displayed in its own container with a corresponding vote count.

JavaScript
import React, { useState } from 'react'; import { StyleSheet, Text, View, Button, Image, ScrollView }      from 'react-native';  const image1 =  'https://media.geeksforgeeks.org/wp-content/cdn-uploads/20230305182658/HTML-tutorial.jpg'; const image2 =  'https://media.geeksforgeeks.org/wp-content/uploads/20230427130955/CSS-Tutorial.webp'; const image3 =  'https://media.geeksforgeeks.org/wp-content/cdn-uploads/20230305183140/Javascript.jpg'; const image4 =  'https://media.geeksforgeeks.org/wp-content/cdn-uploads/20230310153232/ReactJS-Tutorial.jpg';  const App = () => {     const [votes, setVotes] = useState({         image1: 0,         image2: 0,         image3: 0,         image4: 0,     });      const castVote = (imageKey) => {         setVotes((prevVotes) => ({             ...prevVotes,             [imageKey]: prevVotes[imageKey] + 1,         }));     };      return (         <ScrollView contentContainerStyle={styles.container}>             <Text style={styles.title}>GeeksforGeeks</Text>              <View style={styles.imageBtnContainer}>                 <View style={styles.imageContainer}>                     <Image source={{ uri: image1 }}                          style={styles.image} />                     <Button                         title="Vote for HTML"                         onPress={() => castVote('image1')}                         style={styles.button}                     />                     <View style={styles.voteContainer}>                         <Text style={styles.voteText}>Votes:                           {votes.image1}</Text>                     </View>                 </View>                  <View style={styles.imageContainer}>                     <Image source={{ uri: image2 }}                        style={styles.image} />                     <Button                         title="Vote for CSS"                         onPress={() => castVote('image2')}                         style={styles.button}                     />                     <View style={styles.voteContainer}>                         <Text style={styles.voteText}>Votes:                           {votes.image2}</Text>                     </View>                 </View>             </View>              <View style={styles.imageBtnContainer}>                 <View style={styles.imageContainer}>                     <Image source={{ uri: image3 }}                        style={styles.image} />                     <Button                         title="Vote for Javascript"                         onPress={() => castVote('image3')}                         style={styles.button}                     />                     <View style={styles.voteContainer}>                         <Text style={styles.voteText}>Votes:                          {votes.image3}</Text>                     </View>                 </View>                  <View style={styles.imageContainer}>                     <Image source={{ uri: image4 }}                             style={styles.image} />                     <Button                         title="Vote for React"                         onPress={() => castVote('image4')}                         style={styles.button}                     />                     <View style={styles.voteContainer}>                         <Text style={styles.voteText}>                             Votes: {votes.image4}                         </Text>                     </View>                 </View>             </View>         </ScrollView>     ); };  const styles = StyleSheet.create({     container: {         flex: 1,         alignItems: 'center',         backgroundColor: '#D2E0FB',     },     title: {         fontSize: 20,         fontWeight: 'bold',         marginVertical: 20,         color: 'green'     },     imageBtnContainer: {         flexDirection: 'row',         justifyContent: 'space-between',         marginBottom: 10,     },     imageContainer: {         alignItems: 'center',         marginRight: 10,     },     image: {         width: 150,         height: 150,         resizeMode: 'cover',         marginBottom: 10,     },      voteContainer: {         backgroundColor: '#8EACCD',         padding: 5,         borderRadius: 5,         marginTop: 10     },     voteText: {         fontSize: 16,         fontWeight: 'bold',         color: 'white',     }, });  export default App; 

Step 4: Go to the Terminal and type the following command to run the react native application.

npx expo start

To run on Android:

npx react-native run-android

To run on IOS:

npx react-native run-ios

Output:


Next Article
Create a Camera App using React-Native

G

geekwriter2024
Improve
Article Tags :
  • Project
  • Web Technologies
  • ReactJS
  • Geeks Premier League
  • React-Native
  • Web Development Projects
  • Web Tech - Advanced
  • Geeks Premier League 2023

Similar Reads

  • Create a Voice Notes App using React-Native
    We are going to build a Voice Notes app that will allow us to save our voice as a recording in our application. It is similar to a notes app but we will have our voice as notes. We can play the voice recordings, record them, and delete them. It leverages React-Native's cross-platform capabilities to
    5 min read
  • Create a Blog App using React-Native
    This article shows how to create a basic blog app using react native. This app contains functionalities such as adding a blog and a delete button to remove the blogs using react native. The user can enter content with a title and then click on 'Add New Post' to create a new blog post Preview of fina
    4 min read
  • Create a Video Player App using React-Native
    React-Native is an open-source JavaScript framework used to broaden cross-platform packages i.e., you may write code in React-Native and publish it as an Android or IOS app. In this article, we will build a Video Player app with the usage of React-Native. The app will run on both Android and IOS. Pr
    4 min read
  • Create a Camera App using React-Native
    A camera app using react native is a mobile application that is designed to capture photos or videos using the built-in camera functionality of a mobile device. In this article, you will learn how you can create a camera app with simple steps. Output Preview: Let us have a look at how the final appl
    3 min read
  • Create a Chatbot App using React-Native
    Creating a chatbot app using React Native will be an exciting project. In this article, we are going to implement a Chatbot App using React Native. Chatbot App is a mobile application that answers the user's questions on the basis of their previous learning or content provided by developers. It help
    4 min read
  • Create a Compass App using React-Native
    In this project, we'll create a Compass App using React Native. The app will display real-time compass heading information, along with additional details such as cardinal direction. The user interface will include a rotating compass image to provide a visual representation of the device's orientatio
    3 min read
  • Create a Video Streaming App using React-Native
    React-Native is an open-source JavaScript framework used to broaden cross-platform packages i.e., you may write code in React-Native and publish it as an Android or IOS app. In this article, we will build a Video Streaming app using React-Native. The app will run on both Android and IOS. Preview of
    4 min read
  • Create a Location Sharing App using React-Native
    In this article, we are going to build a step-by-step Location Sharing App using React-Native. A Location Sharing App developed with React-Native allows users to share their real-time location with others. It leverages React-Native's cross-platform capabilities to create a mobile application that fa
    4 min read
  • Create Timeline App using React-Native
    A Timeline App is a software application designed to display events in chronological order. The primary purpose of this timeline app is to present a visual representation of a sequence of events. In this article, we are going to implement a TimeLine App using React Native. It allows users to easily
    4 min read
  • Create a Portfolio App using React-Native
    In this article, we are going to Create a portfolio app using React Native. The portfolio app is a simple application that is a collection of a person's qualifications, achievements, work samples, and other relevant materials. It is used to demonstrate one's abilities and suitability for a particula
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences