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 File Explorer App using React-Native
Next article icon

Create an Employee Management using React-Native

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

Creating the Employee Management Application using React-Native is skill developing project. In this project, the application admin can manage the employees by adding them dynamically, updating the details, and deleting the employee as per the requirement. In this article, we will develop this Employee management application using React-Native by adding more features to it.

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

EMP

Prerequisites & Technologies Used:

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

Approach to creating Employee Management App using React-Native

  • This application/project is mainly a multi-screen application.
  • In this application, we have various functionalities like Searching for Employees in the list, sorting the employees, etc.
  • The application admin can add the employees to the application, whereas the validation is been checked for the Employee ID. Also, the admin can update and delete the details of the employee as per the need.
  • The application is styled with attractive styling, dynamic icons, and colors.

Steps to Create React Native Application:

Step 1: Create the project:

npx create-expo-app emp-app

Step 2: Navigate to the project

cd emp-app

Step 3: Install the packages as follows:

npm install expo/vector-icons react-native-paper react-native-screens react-native-elements
react-navigation/stack react-native-reanimated react-navigation/native react-native-vector-icons
react-native-gesture-handler react-native-safe-area-context react-native-vector-icons/MaterialIcons

Project Structure:

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-native-elements": "*",
"@react-navigation/stack": "*",
"react-native-reanimated": "~2.14.4",
"@react-navigation/native": "6.0.0*",
"react-native-vector-icons": "10.0.3",
"react-native-gesture-handler": "~2.9.0",
"react-native-safe-area-context": "4.5.0",
"react-native-vector-icons/MaterialIcons": "*"
}

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

JavaScript
// App.js  import React, { useState, useEffect } from "react"; import { 	View, 	Text, 	TextInput, 	Button, 	FlatList, 	TouchableOpacity, 	Alert, } from "react-native"; import { NavigationContainer } from "@react-navigation/native"; import { createStackNavigator } from "@react-navigation/stack"; import { 	FAB, 	Card, 	Title, 	Paragraph, 	Provider as PaperProvider, 	Appbar, } from "react-native-paper"; import { SearchBar } from "react-native-elements"; import Icon from "react-native-vector-icons/MaterialIcons"; import Animated, { 	useAnimatedStyle, 	withSpring, 	useSharedValue, } from "react-native-reanimated"; import { styles } from "./styles";  const HomeScreen = ({ navigation }) => { 	const [employees, setEmployees] = useState([]); 	const [search, setSearch] = useState(""); 	const [filteredEmployees, setFilteredEmployees] = useState([]); 	const [sortOrder, setSortOrder] = useState("asc"); 	const fabScale = useSharedValue(1); 	useEffect(() => { 		const defaultEmployees = [ 			{ 				id: "1", 				empId: "EMP001", 				name: "Ramesh", 				position: "Software Engineer", 			}, 			{ 				id: "2", 				empId: "EMP002", 				name: "Suresh", 				position: "Product Manager", 			}, 			{ 				id: "3", 				empId: "EMP003", 				name: "Naresh", 				position: "UI/UX Designer", 			}, 		]; 		setEmployees(defaultEmployees); 	}, []); 	useEffect(() => { 		const filtered = employees.filter((employee) => 			employee.name.toLowerCase().includes(search.toLowerCase()) 		); 		setFilteredEmployees(filtered); 	}, [search, employees]); 	const handleSort = () => { 		const newOrder = sortOrder === "asc" ? "desc" : "asc"; 		setSortOrder(newOrder); 		const sortedEmployees = [...employees].sort((a, b) => { 			if (newOrder === "asc") { 				return a.name.localeCompare(b.name); 			} else { 				return b.name.localeCompare(a.name); 			} 		}); 		setEmployees(sortedEmployees); 	}; 	const deleteEmployee = (id) => { 		const updatedEmployees = employees.filter( 			(employee) => employee.id !== id 		); 		setEmployees(updatedEmployees); 	}; 	const editEmployee = (id, updatedEmployee) => { 		const updatedEmployees = employees.map((employee) => 			employee.id === id ? updatedEmployee : employee 		); 		setEmployees(updatedEmployees); 	}; 	const addEmployee = (newEmployee) => { 		if ( 			employees.some((employee) => employee.empId === newEmployee.empId) 		) { 			Alert.alert("Error", "Employee with the same ID already exists."); 		} else { 			setEmployees([...employees, newEmployee]); 			navigation.goBack(); 		} 	}; 	const fabStyle = useAnimatedStyle(() => { 		return { 			transform: [{ scale: withSpring(fabScale.value) }], 		}; 	}); 	return ( 		<View style={styles.container}> 			<View style={styles.titleContainer}> 				<Icon 					name="people" 					size={24} 					color="white" 					style={styles.titleIcon} 				/> 				<Text style={styles.title}>GeeksforGeeks Emp Management</Text> 			</View> 			<Appbar.Header style={styles.appbar}> 				<SearchBar 					placeholder="Search Employees..." 					onChangeText={setSearch} 					value={search} 					lightTheme 					containerStyle={styles.searchBarContainer} 					inputContainerStyle={styles.searchBarInputContainer} 				/> 				<Appbar.Action 					icon={() => ( 						<Icon name="filter-alt" size={24} color="white" /> 					)} 					onPress={handleSort} 				/> 			</Appbar.Header> 			{(filteredEmployees.length === 0 && search !== "") || 			(employees.length === 0 && filteredEmployees.length === 0) ? ( 				<View style={styles.noRecordsContainer}> 					<Text>No records found</Text> 				</View> 			) : ( 				<FlatList 					data={filteredEmployees} 					keyExtractor={(item) => item.id} 					renderItem={({ item }) => ( 						<Card style={styles.card}> 							<Card.Content> 								<Title>{item.name}</Title> 								<Paragraph>ID: {item.empId}</Paragraph> 								<Paragraph>Position: {item.position}</Paragraph> 							</Card.Content> 							<Card.Actions> 								<TouchableOpacity 									onPress={() => 										navigation.navigate("Edit", { 											employee: item, 											editEmployee: editEmployee, 										}) 									} 								> 									<Icon 										name="edit" 										size={24} 										color="#3498db" 										style={styles.actionIcon} 									/> 								</TouchableOpacity> 								<TouchableOpacity 									onPress={() => deleteEmployee(item.id)} 								> 									<Icon 										name="delete" 										size={24} 										color="#3498db" 										style={styles.actionIcon} 									/> 								</TouchableOpacity> 							</Card.Actions> 						</Card> 					)} 					style={styles.employeeList} 				/> 			)} 			<Animated.View style={[styles.fab, fabStyle]}> 				<FAB 					icon={() => <Icon name="add" size={24} color="white" />} 					onPress={() => { 						fabScale.value = 0.8; 						navigation.navigate("Add", { 							addEmployee: addEmployee, 						}); 					}} 					onStateChange={({ nativeEvent }) => { 						if (nativeEvent.state === 2) { 							fabScale.value = 1; 						} 					}} 				/> 			</Animated.View> 		</View> 	); }; const AddEmpScreen = ({ route, navigation }) => { 	const [name, setName] = useState(""); 	const [position, setPosition] = useState(""); 	const [empId, setEmpId] = useState(""); 	const addEmployee = () => { 		if (!empId || !name || !position) { 			Alert.alert("Error", "Please fill in all the fields."); 			return; 		} 		const existingEmployees = route.params?.employees || []; 		if (existingEmployees.some((employee) => employee.empId === empId)) { 			Alert.alert("Error", "Employee with the same ID already exists."); 		} else { 			route.params?.addEmployee({ 				id: Date.now().toString(), 				empId, 				name, 				position, 			}); 			navigation.goBack(); 		} 	}; 	return ( 		<View style={styles.container}> 			<TextInput 				placeholder="Enter Employee ID" 				value={empId} 				onChangeText={(text) => setEmpId(text)} 				style={styles.input} 			/> 			<TextInput 				placeholder="Enter Name" 				value={name} 				onChangeText={(text) => setName(text)} 				style={styles.input} 			/> 			<TextInput 				placeholder="Enter Position" 				value={position} 				onChangeText={(text) => setPosition(text)} 				style={styles.input} 			/> 			<Button title="Add Employee" onPress={addEmployee} /> 		</View> 	); }; const EditEmpScreen = ({ route, navigation }) => { 	const { employee, editEmployee } = route.params; 	const [empId, setEmpId] = useState(employee.empId); 	const [name, setName] = useState(employee.name); 	const [position, setPosition] = useState(employee.position); 	const saveChanges = () => { 		if (!empId || !name || !position) { 			Alert.alert("Error", "Please fill in all the fields."); 			return; 		} 		const existingEmployees = route.params?.employees || []; 		if ( 			existingEmployees.some( 				(emp) => emp.id !== employee.id && emp.empId === empId 			) 		) { 			Alert.alert("Error", "Employee with the same ID already exists."); 		} else { 			editEmployee(employee.id, { ...employee, empId, name, position }); 			navigation.goBack(); 		} 	}; 	return ( 		<View style={styles.container}> 			<TextInput 				placeholder="Enter Employee ID" 				value={empId} 				onChangeText={(text) => setEmpId(text)} 				style={styles.input} 			/> 			<TextInput 				placeholder="Enter Name" 				value={name} 				onChangeText={(text) => setName(text)} 				style={styles.input} 			/> 			<TextInput 				placeholder="Enter Position" 				value={position} 				onChangeText={(text) => setPosition(text)} 				style={styles.input} 			/> 			<Button title="Save Changes" onPress={saveChanges} /> 		</View> 	); }; const Stack = createStackNavigator(); const App = () => { 	return ( 		<PaperProvider> 			<NavigationContainer> 				<Stack.Navigator initialRouteName="Home"> 					<Stack.Screen name="Home" component={HomeScreen} /> 					<Stack.Screen name="Add" component={AddEmpScreen} /> 					<Stack.Screen name="Edit" component={EditEmpScreen} /> 				</Stack.Navigator> 			</NavigationContainer> 		</PaperProvider> 	); }; export default App; 
JavaScript
// styles.js  import { StyleSheet } from 'react-native';  export const styles = StyleSheet.create({ 	container: { 		flex: 1, 		backgroundColor: '#f0f0f0', 	}, 	titleContainer: { 		backgroundColor: 'white', 		flexDirection: 'row', 		alignItems: 'center', 		paddingVertical: 10, 		paddingLeft: 10, 		marginBottom: 5, 	}, 	titleIcon: { 		marginRight: 10, 		color: 'green', 	}, 	title: { 		color: 'green', 		fontSize: 20, 		fontWeight: 'bold', 	}, 	appbar: { 		backgroundColor: 'green', 	}, 	input: { 		height: 40, 		borderColor: 'gray', 		borderWidth: 1, 		marginBottom: 10, 		padding: 10, 		backgroundColor: 'white', 		borderRadius: 5, 	}, 	employeeList: { 		flex: 1, 		marginTop: 10, 		paddingHorizontal: 10, 	}, 	card: { 		marginBottom: 10, 		elevation: 4, 		borderRadius: 10, 	}, 	actionIcon: { 		marginHorizontal: 10, 	}, 	fab: { 		position: 'absolute', 		margin: 16, 		right: 0, 		bottom: 0, 		backgroundColor: '#3498db', 		borderRadius: 28, 	}, 	searchBarContainer: { 		backgroundColor: 'transparent', 		borderTopColor: 'transparent', 		borderBottomColor: 'transparent', 		flex: 1, 	}, 	searchBarInputContainer: { 		backgroundColor: '#ecf0f1', 	}, 	noRecordsContainer: { 		flex: 1, 		justifyContent: 'center', 		alignItems: 'center', 	}, }); 

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 File Explorer App using React-Native

G

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

Similar Reads

  • Create File Explorer App using React-Native
    Creating a File Explorer app using React Native provides a seamless way to explore and interact with the device's file system on both iOS and Android platforms. In this tutorial, we'll guide you through the process of building a simple yet functional File Explorer app. Output Preview: Prerequisites:
    3 min read
  • Create an Image Crop Tool using React-Native
    In this tutorial, we are going to build an Image crop tool using React-Native. The Image Crop tool is a very important tool for cropping the Images. It will allow the users to pick an image from storage, crop it, and later save it locally. Preview Image:Prerequisites Introduction to React NativeReac
    4 min read
  • Create Memes Generator App using React-Native
    The Me­me Generator App is a mobile­ application that allows users to effortlessly create memes. With its use­r-friendly interface, use­rs can choose from a wide collection of popular me­me templates and add their own customized text to the top and bottom. In this article, we will see how we can bui
    4 min read
  • Create a Task Manager App using React-Native
    In this article, we'll walk you through the process of building a basic Task Manager app using React Native. The application enables users to effortlessly create, edit, complete/incomplete, and delete­ tasks, providing an uncomplicated yet impactful introduction to Re­act Native's mobile app develop
    7 min read
  • Create a Password Manager using React-Native
    This article will demonstrate how to create a Password Manager Application using React-Native. To assist users in securely storing and managing their passwords, we will develop a Password Manager mobile­ application using React Native for this project. The application will provide functionalities su
    6 min read
  • Create a Memory Pair Game using React-Native
    In this article, we will build the interactive Memory Pair Game using the React Native language. We are displaying the 12 boxes to the user, in the user has to click on each box, and when the user clicks on the box the random icon will be shown. Users have to guess or find its match by clicking on t
    5 min read
  • Create an Image Resize and Editor using React-Native
    Image manipulation in mobile apps is an important functionality, from cropping and resizing to adding filters or overlays. In this tutorial, you will learn the process of building a simple Image Resize and Editor application using React-Native. This project aims to provide a foundation to integrate
    3 min read
  • Create Jokes Generator App using React-Native
    In this article, we are going to build a jokes generator app using react native. React Native enables you to master the­ designing an elegant and dynamic use­r interface while e­ffortlessly retrieving joke­s from external APIs. Let's take a look at how our completed project will look Prerequisites /
    3 min read
  • Create a Map with Google Map Api using React-Native
    In this project, we'll explore how to integrate Google Maps into a React Native application. We'll create a dynamic map that allows users to view their current location and interact with markers on the map. This project aims to provide a practical guide for developers looking to incorporate maps int
    3 min read
  • Create an E-commerce App using React-Native
    An E-commerce app using react native is an application designed to facilitate online buying and selling of goods and services. These apps aim to provide a digital platform for businesses to showcase their products or services and for consumers to browse, compare, and purchase items without the need
    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