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 Bill Splitter App using React-Native
Next article icon

Create a Book Store using React-Native

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

React-Native is a flexible frameworks for building mobile applications. We will develop a Book Store application, which allows users to search for a specific book, and store the book in the application. If the user wants to remove the book from the stored list, they can easily remove it by navigating to the Remove option. In this article, we will build this Book Store application using React-Native with proper styling.

Preview of the final output: Let us look at what the final output will look like.

Screenshot-2023-12-13-at-09-04-51-Embed-min

Prerequisites & Technologies Used:

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

Approach to create Book Store App using React-Native

  • This application is a multi-page application.
  • Here, we have used the Google API to fetch the books from the internet as per the user's input.
  • When the books are fetched, the user can view the books and click on the Store Button. Once clicked, the book gets added to the Stored Book List.
  • From the Stored Book List, the user can manage the stored books by removing them as per their need.

Steps to Create React Native Application:

Step 1: Create the project:

npx create-expo-app book-store

Step 2: Navigate to the project

cd book-store

Step 3: Install the packages as follows:

npx expo install react-navigation/native react-navigation/stack expo/vector-icons react-native-gesture-handler react-native-safe-area-context react-native-paper react-native-screens

Project Structure

PS

The updated dependencies in package.json file will look like:

"dependencies": {     "@expo/vector-icons": "^13.0.0",     "react-native-paper": "4.9.2",     "react-native-screens": "~3.20.0",     "@react-navigation/stack": "*",     "@react-navigation/native": "6.0.0",     "react-native-gesture-handler": "~2.9.0",     "react-native-safe-area-context": "4.5.0" }

Example: In this example, we are following the above-explained approach.

JavaScript
// App.js  import React, { useState, useEffect, useContext, createContext } from 'react'; import { View, Text, FlatList, StyleSheet,  		TextInput, TouchableOpacity, Image, ScrollView, Alert } from 'react-native'; import { NavigationContainer } from '@react-navigation/native'; import { createStackNavigator } from '@react-navigation/stack'; import { MaterialCommunityIcons } from '@expo/vector-icons'; import styles from './styles'; const Stack = createStackNavigator(); const BookData = createContext(); const BookFetch = ({ children }) => { 	const [storedBooks, setStoredBooks] = useState([]); 	const addBook = (book) => { 		setStoredBooks((prevBooks) => [...prevBooks, { ...book, 			storedId: Math.random().toString(),  			addedDate: new Date().toLocaleDateString()  		}]); 	}; 	const removeBook = (id) => { 		setStoredBooks((prevBooks) => prevBooks.filter((book) => book.storedId !== id)); 	}; 	return ( 		<BookData.Provider value={{ storedBooks, addBook, removeBook }}> 			{children} 		</BookData.Provider> 	); }; const BookListScreen = ({ navigation }) => { 	const [books, setBooks] = useState([]); 	const [searchQuery, setSearchQuery] = useState('JavaScript'); 	const { addBook, removeBook, storedBooks } = useContext(BookData);  	const fetchBooks = async (query) => { 		try { 			const response = await fetch( `https://www.googleapis.com/books/v1/volumes?q=${query}&maxResults=10`); 			const data = await response.json(); 			setBooks(data.items || []); 		} catch (error) { 			console.error('Error fetching books:', error); 		} 	}; 	useEffect(() => { 		fetchBooks(searchQuery); 	}, [searchQuery]); 	const navigateToDetails = (book) => { 		navigation.navigate('BookDetails', { book }); 	}; 	const renderBookItem = ({ item }) => { 		const bookInfo = item.volumeInfo; 		const isBookStored = storedBooks.some((storedBook) => storedBook.id === item.id); 		const handleButtonPress = () => { 			if (isBookStored) { 				removeBook(item.id); 				Alert.alert('Book removed successfully!'); 			} else { 				addBook({ ...bookInfo, id: item.id }); 			} 		}; 		return ( 			<TouchableOpacity style={styles.bookItem}  							onPress={() => navigateToDetails(bookInfo)}> 				<Image style={styles.bookImage}  					source={{ uri: bookInfo.imageLinks?.thumbnail }} /> 				<View style={styles.bookDetails}> 					<Text style={styles.bookTitle}>{bookInfo.title}</Text> 					<Text style={styles.bookAuthor}>{bookInfo.authors?.join(', ')}</Text> 				</View> 				<TouchableOpacity  					style={isBookStored ? styles.removeButton : styles.storeButton}  					onPress={handleButtonPress}  					disabled={isBookStored}> 					<Text style={styles.buttonText}> 						{isBookStored ? 'Added' : 'Store'} 					</Text> 				</TouchableOpacity> 			</TouchableOpacity> 		); 	}; 	return ( 		<View style={styles.container}> 			<Text style={styles.header}>GeeksforGeeks Book Store</Text> 			<TextInput style={styles.searchInput}  					placeholder="Search books..." 					onChangeText={(text) => setSearchQuery(text)} value={searchQuery}/> 			<FlatList data={books}  					keyExtractor={(item) => item.id || item.etag}  					renderItem={renderBookItem} /> 			<TouchableOpacity style={styles.storedBooksButton}  							onPress={() => navigation.navigate('StoredBooks')}> 				<MaterialCommunityIcons name="bookshelf" size={24} color="#4CAF50" /> 				{storedBooks.length > 0 && ( 					<View style={styles.badge}> 						<Text style={styles.badgeText}>{storedBooks.length}</Text> 					</View> 				)} 			</TouchableOpacity> 		</View> 	); }; const BookDetailsScreen = ({ route }) => { 	const { book } = route.params;  	return ( 		<ScrollView style={styles.container}> 			<Text style={styles.header}>Book Details</Text> 			<Image style={styles.bookImageDetail}  				source={{ uri: book.imageLinks?.thumbnail }} /> 			<Text style={styles.bookTitle}>{book.title}</Text> 			<Text style={styles.bookAuthor}>{book.authors?.join(', ')}</Text> 		</ScrollView> 	); }; const StoredBooksScreen = () => { 	const { storedBooks, removeBook } = useContext(BookData); 	const handleRemoveBook = (storedId) => { 		removeBook(storedId); 		Alert.alert('Book removed successfully!'); 	}; 	const renderStoredBookItem = ({ item }) => ( 		<View style={styles.storedBookItem}> 			<Image style={styles.storedBookImage}  				source={{ uri: item.imageLinks?.thumbnail }} /> 			<View style={styles.storedBookDetails}> 				<Text style={styles.storedBookTitle}>{item.title}</Text> 				<Text style={styles.storedBookPreview}>{item.previewLink}</Text> 				<Text style={styles.storedBookAddedDate}>Added on: {item.addedDate}</Text> 			</View> 			<TouchableOpacity style={styles.removeButton}  							onPress={() => handleRemoveBook(item.storedId)}> 				<Text style={styles.buttonText}>Remove</Text> 			</TouchableOpacity> 		</View> 	); 	return ( 		<ScrollView style={styles.container}> 			<Text style={styles.header}>Stored Books</Text> 			{storedBooks.length > 0 ? ( 				<FlatList data={storedBooks}  						keyExtractor={(item) => item.storedId}  						renderItem={renderStoredBookItem} /> 			) : ( 				<Text>No stored books yet.</Text> 			)} 		</ScrollView> 	); }; const App = () => { 	return ( 		<NavigationContainer> 			<Stack.Navigator initialRouteName="BookList"> 				<Stack.Screen name="BookList" component={BookListScreen} /> 				<Stack.Screen name="BookDetails" component={BookDetailsScreen} /> 				<Stack.Screen name="StoredBooks" component={StoredBooksScreen} /> 			</Stack.Navigator> 		</NavigationContainer> 	); }; export default () => ( 	<BookFetch> 		<App /> 	</BookFetch> ); 
JavaScript
// styles.js  import { StyleSheet } from 'react-native';  const styles = StyleSheet.create({ 	container: { 		flex: 1, 		padding: 16, 		backgroundColor: '#f0f0f0', 	}, 	header: { 		fontSize: 24, 		fontWeight: 'bold', 		marginBottom: 16, 		color: '#4CAF50', 	}, 	bookItem: { 		flexDirection: 'row', 		backgroundColor: '#fff', 		padding: 16, 		marginVertical: 8, 		borderRadius: 8, 	}, 	bookImage: { 		width: 80, 		height: 120, 		marginRight: 16, 		borderRadius: 8, 	}, 	bookDetails: { 		flex: 1, 	}, 	bookImageDetail: { 		width: '100%', 		height: 200, 		borderRadius: 8, 		marginBottom: 16, 	}, 	bookTitle: { 		fontSize: 18, 		fontWeight: 'bold', 	}, 	bookAuthor: { 		marginTop: 8, 	}, 	storeButton: { 		backgroundColor: '#3498db', 		padding: 8, 		borderRadius: 8, 		marginLeft: 8, 		alignSelf: 'flex-start', 	}, 	removeButton: { 		backgroundColor: '#e74c3c', 		padding: 8, 		borderRadius: 8, 		marginLeft: 8, 		alignSelf: 'flex-start', 	}, 	buttonText: { 		color: '#fff', 		fontWeight: 'bold', 	}, 	searchInput: { 		height: 40, 		borderColor: 'gray', 		borderWidth: 1, 		marginBottom: 16, 		padding: 8, 		borderRadius: 8, 	}, 	storedBooksButton: { 		position: 'absolute', 		bottom: 16, 		right: 16, 		backgroundColor: '#faed39', 		padding: 16, 		borderRadius: 50, 		alignItems: 'center', 		justifyContent: 'center', 		zIndex: 1, 	}, 	badge: { 		position: 'absolute', 		top: -5, 		right: -5, 		backgroundColor: 'red', 		borderRadius: 10, 		width: 20, 		height: 20, 		alignItems: 'center', 		justifyContent: 'center', 	}, 	badgeText: { 		color: 'white', 		fontWeight: 'bold', 		fontSize: 12, 	}, 	storedBookItem: { 		flexDirection: 'row', 		alignItems: 'center', 		backgroundColor: '#fff', 		padding: 16, 		marginVertical: 8, 		borderRadius: 8, 	}, 	storedBookImage: { 		width: 80, 		height: 120, 		marginRight: 16, 		borderRadius: 8, 	}, 	storedBookDetails: { 		flex: 1, 	}, 	storedBookTitle: { 		fontSize: 18, 		fontWeight: 'bold', 	}, 	storedBookPreview: { 		marginTop: 8, 		color: '#555', 	}, 	storedBookAddedDate: { 		marginTop: 8, 		color: '#888', 	}, });  export default styles; 

Step to run the application:

Step 1: Navigate to the terminal or command prompt and type the required command there to run the React native application.

npx expo start

Step 2: Depending on your Operating System, type the following command in terminal

To run on Android:

npx react-native run-android

To run on IOS:

npx react-native run-ios

Output:


Next Article
Create a Bill Splitter App using React-Native

A

anjalibo6rb0
Improve
Article Tags :
  • Project
  • Web Technologies
  • ReactJS
  • Geeks Premier League
  • React-Native
  • Geeks Premier League 2023

Similar Reads

  • 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 Tic-Tac-Toe using React-Native
    In this article, we will learn how to build a Tic-Tac-Toe game using React-Native. React Native enables the application to run a single code base on multiple platforms like Android, IOS, etc. Developing the TicTacToe game application allows us to learn basic styling, app logic, user interaction, and
    4 min read
  • Create a Resume Builder using React-Native
    A resume is like a personal marketing document that shows off your skills, work history, and achievements to a potential employer. Resume builder apps help you to create this document more easily. In this article, we are going to implement a resume builder app using React Native. Preview of final ou
    5 min read
  • Create a Bill Splitter App using React-Native
    We are going to implement the Bill Splitter App using React Native. Bill Splitter App is a mobile application that helps us divide expenses and bills among a group of people. For example, when we are dining at a restaurant with friends, going on a trip, or sharing household expenses with roommates.
    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 ClassRoom App using React-Native
    ClassRoom App using React Native is a simple application designed to facilitate online learning and classroom management. These apps are commonly used in educational institutions, schools, colleges, and universities to enhance the teaching and learning experience. Preview of final output: Let us hav
    7 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 Job Board App using React-Native
    In this article, we are going to Create a Job Board App using React Native. The Job Board App is a simple application that is a collection of job openings in any field. It helps the students and the people who are searching for jobs in the market. It helps to find jobs and provides in-depth informat
    6 min read
  • Create a Tip Calculator using React-Native
    A Tip Calculator proves to be a convenient tool for effortlessly calculating tips and dividing bills among friends at restaurants. The app enables users to input the bill amount, select their desired tip perce­ntage, specify the numbe­r of people sharing the bill, and promptly obtain calculate­d val
    5 min read
  • Create a News Reader app using React-Native
    Creating the News Reader application using React-Native language is an exciting project. Using this project, the users can read the news in the application itself, by filtering them according to the categories as per their interest. In this article, we will develop the complete News Reader applicati
    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