[go: up one dir, main page]

0% found this document useful (0 votes)
30 views44 pages

React - Js - From Fundamentals To Real-Time Applications

The document is a comprehensive guide on React.js, aimed at both beginners and intermediate developers, covering fundamental concepts and practical applications. It includes step-by-step projects such as building components, routing, state management, and CRUD operations, along with integration of tools like Bootstrap and Axios. Each chapter provides hands-on examples to enhance understanding and prepare for real-world development scenarios.

Uploaded by

adikilledar2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views44 pages

React - Js - From Fundamentals To Real-Time Applications

The document is a comprehensive guide on React.js, aimed at both beginners and intermediate developers, covering fundamental concepts and practical applications. It includes step-by-step projects such as building components, routing, state management, and CRUD operations, along with integration of tools like Bootstrap and Axios. Each chapter provides hands-on examples to enhance understanding and prepare for real-world development scenarios.

Uploaded by

adikilledar2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

React.

js Developer Guide: From Fundamentals to Real-Time Applications

Preface

In today’s fast-evolving web development landscape, React.js has established itself as


one of the most powerful and widely adopted JavaScript libraries. This book is designed
not only for absolute beginners but also for intermediate developers seeking to
consolidate their understanding of React through hands-on applications. Each topic is
coupled with a real-world application, ensuring a practical learning experience that
aligns with modern development and interview requirements.

Chapter 1: Introduction to React.js

React.js is a declarative, component-based JavaScript library for building user


interfaces. Developed and maintained by Facebook, it simplifies complex UI
development by allowing developers to break interfaces into reusable components.

Key Features

• Component-Based Architecture: Reusable, modular components.

• JSX Syntax: JavaScript with embedded XML-like tags.

• Virtual DOM: Optimized rendering using a virtual representation.

• Unidirectional Data Flow: Predictable state management.

• Hooks API: Enables state and lifecycle features in functional components.

Chapter 2: Setting Up Your First React Application

Project: First React Application

Steps:

1. Create a new app:

npx create-react-app firstapp

2. Navigate to the project:

cd firstapp

3. Open in VS Code:

code .

4. Start the application:

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


npm start

This will launch the default React template in the browser.

Chapter 3: Building Components in React

Project: Multi-Component Application

React encourages component-driven development. Each UI element can be


encapsulated into its own component.

Steps:

1. Create a folder components under src.

2. Create Home.js, Body.js, and Footer.js.

1. Home.js

3. function Home(){
4. return(
5. <div>
6. <h1>Home Component</h1>
7. </div>
8. )
9. }
10. export default Home;

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


2. Body.js

3. Footer.js

11. Import them in App.js and render:

import Home from './components/Home';

import Body from './components/Body';

import Footer from './components/Footer';

);

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


}

Chapter 4: Navigation using React Router

Project: Routing Application

Tools: react-router-dom

Steps:

1. Install router:

npm install react-router-dom

2. Create components: Home.js, Services.js, AboutUs.js, ContactUs.js.

3. In App.js:

<BrowserRouter>

<ul>

<li><Link to="/">Home</Link></li>

<li><Link to="/services">Services</Link></li>

<li><Link to="/aboutus">About Us</Link></li>

<li><Link to="/contactus">Contact Us</Link></li>

</ul>

<Routes>

<Route path="/" element={<Home />} />

<Route path="/services" element={<Services />} />

<Route path="/aboutus" element={<AboutUs />} />

<Route path="/contactus" element={<ContactUs />} />

</Routes>

</BrowserRouter>

Note: Same way as the above application, create the first components, and then add
routing

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


Chapter 5: Styling with Bootstrap & Two-Way Binding

Project: Student Form with Bootstrap

Steps:

1. Install Bootstrap:

npm install bootstrap

2. Import in index.js:

import 'bootstrap/dist/css/bootstrap.min.css';

3. Create Student.js using useState:

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


const [name, setName] = useState('Chandra');

<input value={name} onChange={(e) => setName(e.target.value)} />

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


Chapter 6: Working with Arrays and CRUD Operations

Project: Arrays CRUD

This app demonstrates managing a list of students using array state and rendering via
.map().

• Add Student

• Display Table

• Buttons for future Update, View, Delete

Use useState() to maintain state.

Note: same way in this application, also install Bootstrap and add an import statement
to the index.js

Student.js

import React, { useState } from "react";

const Student = () => {

const [students, setStudents] = useState([]);

const [id, setId] = useState('');

const [name, setName] = useState('');

const [course, setCourse] = useState('');

const [viewedStudent, setViewedStudent] = useState(null); // view student

const [isUpdateMode, setIsUpdateMode] = useState(false);

const [editIndex, setEditIndex] = useState(null);

const saveStudent = (e) => {

e.preventDefault();

const newStudent = { id, name, course };

if (isUpdateMode) {

// Update mode logic

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


const updatedStudents = [...students];

updatedStudents[editIndex] = newStudent;

setStudents(updatedStudents);

setIsUpdateMode(false);

setEditIndex(null);

} else {

// Save mode logic

setStudents([...students, newStudent]);

// Clear form

setId('');

setName('');

setCourse('');

};

// Create editStudent Function

const editStudent = (index) => {

const studentToEdit = students[index];

setId(studentToEdit.id);

setName(studentToEdit.name);

setCourse(studentToEdit.course);

setIsUpdateMode(true);

setEditIndex(index);

};

const deleteStudent = (idToDelete) => {

const updatedStudents = students.filter(

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


(student) => student.id !== idToDelete

);

setStudents(updatedStudents);

};

const viewStudent = (student) => {

setViewedStudent(student);

};

return (

<div className="container">

<div className="card">

<div className="card-header">

<h1>{isUpdateMode ? "Update Student" : "Create Student"}</h1>

</div>

<div className="card-body">

<form onSubmit={saveStudent}>

<div className="mb-3">

<label className="form-label">Student Id</label>

<input

type="text"

className="form-control"

value={id}

onChange={(e) => setId(e.target.value)}

required

/>

</div>

<div className="mb-3">

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


<label className="form-label">Student Name</label>

<input

type="text"

className="form-control"

value={name}

onChange={(e) => setName(e.target.value)}

required

/>

</div>

<div className="mb-3">

<label className="form-label">Student Course</label>

<input

type="text"

className="form-control"

value={course}

onChange={(e) => setCourse(e.target.value)}

required

/>

</div>

<button className="btn btn-primary" type="submit">

{isUpdateMode ? "Update" : "Save"}

</button>

</form>

</div>

</div>

{viewedStudent && (

<div className="card mt-3">

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


<div className="card-header">

<h2>Viewed Student</h2>

</div>

<div className="card-body">

<p>

<strong>ID:</strong> {viewedStudent.id}

</p>

<p>

<strong>Name:</strong> {viewedStudent.name}

</p>

<p>

<strong>Course:</strong> {viewedStudent.course}

</p>

</div>

</div>

)}

<div className="card">

<div className="card-header">

<h1>Student List</h1>

</div>

<div className="card-body">

<table className="table table-striped">

<thead>

<tr>

<th>Id</th>

<th>Name</th>

<th>Course</th>

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


<th>Actions</th>

</tr>

</thead>

<tbody>

{students.map((student, index) => (

<tr key={index}>

<td>{student.id}</td>

<td>{student.name}</td>

<td>{student.course}</td>

<td>

<button

className="btn btn-primary"

style={{ marginRight: 10 }}

onClick={() => editStudent(index)}

>

Update

</button>

<button

className="btn btn-warning"

style={{ marginRight: 10 }}

onClick={() => viewStudent(student)}

>

View

</button>

<button

className="btn btn-danger"

onClick={() => deleteStudent(student.id)}

>

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


Delete

</button>

</td>

</tr>

))}

</tbody>

</table>

</div>

</div>

</div>

);

};

export default Student;

Check once : https://arraycurd.netlify.app/

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


Chapter 7: Props and State in React

Project: Employee Details

Understand how data flows from parent to child using props:

<Employee name="Chandra" course="React Js" />

In Employee.js, access via props.name and props.course.

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


Chapter 8: State Lifting

Project: Name Lifting Example

Lifting state to a common parent allows multiple child components to access shared
data.

• ParentComponent.js maintains state.

• NameInput.js and NameDisplay.js access the state via props.

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


Chapter 9: JSON Server and Axios Integration

Project: FullStack CRUD with Fake Backend

Steps:

1. Install json-server:

npm install json-server

2. Create db.json in src/db:

"products": [

{"id":1,"name":"abc","Qty":10,"Price":100.0}

3. Start server:

npx json-server db.json -p 5000

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


4. Use axios to call APIs from React.

ProductList.js
import axios from "axios";

import React, { useEffect, useState } from "react";

import { useNavigate } from "react-router-dom";

const ProductList = () => {

const navigate = useNavigate();

const [products, setProducts] = useState([]);

useEffect(() => {

axios.get("http://localhost:5000/products").then((res) => {

setProducts(res.data);

console.log(res.data);

});

}, []);

// Handle Delete Product

const handleDelete = (id) => {

if (window.confirm("Are you sure you want to delete this product?")) {

axios

.delete(`http://localhost:5000/products/${id}`)

.then(() => {

setProducts(products.filter((product) => product.id !== id));

})

.catch((err) => {

console.error("Error deleting product:", err);

});

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


};

return (

<div>

<div className="container">

<div className="card">

<div className="card-header">

<h1>Product List</h1>

</div>

<div className="card-body">

<table className="table table-striped">

<thead>

<tr>

<th>Id</th>

<th>Name</th>

<th>Qty</th>

<th>Price</th>

<th>Actions</th>

</tr>

</thead>

<tbody>

{products.map((product, index) => (

<tr key={index}>

<td>{product.id}</td>

<td>{product.name}</td>

<td>{product.qty}</td>

<td>{product.price}</td>

<td>

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


<button

className="btn btn-primary btn-sm me-2"

onClick={() => navigate(`/edit/${product.id}`)}

>

Edit

</button>

<button

className="btn btn-danger btn-sm"

onClick={() => handleDelete(product.id)}

>

Delete

</button>

</td>

</tr>

))}

</tbody>

</table>

</div>

</div>

</div>

</div>

);

};

export default ProductList;

CreateProduct.js
import axios from "axios";

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


import React, { useState } from "react";

const CreateProduct = () => {

const [id, setId] = useState();

const [name, setName] = useState();

const [qty, setQty] = useState();

const [price, setPrice] = useState();

const saveProduct = (e) => {

e.preventDefault();

alert("calling save product......");

axios

.post("http://localhost:5000/products", { id, name, qty, price })

.then((res) => {

console.log(res.data);

});

};

return (

<div className="container">

<div className="card">

<div className="card-header">

<h1>Create Product</h1>

</div>

<div className="card-body">

<div class="mb-3">

<label for="expId" class="form-label">

Product Id

</label>

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


<input

type="text"

class="form-control"

id="id"

value={id}

onChange={(e) => setId(e.target.value)}

/>

</div>

<div class="mb-3">

<label for="expName" class="form-label">

Product Name

</label>

<input

type="text"

class="form-control"

id="name"

value={name}

onChange={(e) => setName(e.target.value)}

/>

</div>

<div class="mb-3">

<label for="expQty" class="form-label">

Product Qty

</label>

<input

type="text"

class="form-control"

id="qty"

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


value={qty}

onChange={(e) => setQty(e.target.value)}

/>

</div>

<div class="mb-3">

<label for="expPrice" class="form-label">

Product Price

</label>

<input

type="text"

class="form-control"

id="price"

value={price}

onChange={(e) => setPrice(e.target.value)}

/>

</div>

<button className="btn btn-primary" onClick={saveProduct}>

Save

</button>

</div>

{id} {name} {qty} {price}

</div>

</div>

);

};

export default CreateProduct;

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


EditProduct.js
import axios from "axios";

import React, { useEffect, useState } from "react";

import { useParams, useNavigate } from "react-router-dom";

const EditProduct = () => {

const { id } = useParams();

const navigate = useNavigate();

const [product, setProduct] = useState({

name: "",

qty: "",

price: "",

});

const [loading, setLoading] = useState(true);

// Fetch product details by ID

useEffect(() => {

axios

.get(`http://localhost:5000/products/${id}`)

.then((res) => {

setProduct({

name: res.data.name || "",

qty: res.data.qty || "",

price: res.data.price || "",

});

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


setLoading(false);

})

.catch((err) => {

console.error("Error fetching product:", err);

setLoading(false);

});

}, [id]);

// Handle form input change

const handleChange = (e) => {

const { name, value } = e.target;

setProduct({ ...product, [name]: value });

};

// Update product

const handleUpdate = (e) => {

e.preventDefault();

const updatedProduct = {

...product,

qty: parseInt(product.qty, 10),

price: parseFloat(product.price),

};

axios

.put(`http://localhost:5000/products/${id}`, updatedProduct)

.then(() => {

alert("Product updated successfully!");

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


navigate("/");

})

.catch((err) => {

console.error("Error fetching product:", err);

alert("Product not found!");

navigate("/"); // optional: redirect to homepage

});

};

if (loading) return <div className="container mt-4">Loading...</div>;

return (

<div className="container mt-4">

<div className="card">

<div className="card-header">

<h2>Edit Product</h2>

</div>

<div className="card-body">

<form onSubmit={handleUpdate}>

<div className="mb-3">

<label className="form-label">Name</label>

<input

name="name"

className="form-control"

value={product.name || ""}

onChange={handleChange}

required

/>

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


</div>

<div className="mb-3">

<label className="form-label">Quantity</label>

<input

name="qty"

type="number"

className="form-control"

value={product.qty || ""}

onChange={handleChange}

required

/>

</div>

<div className="mb-3">

<label className="form-label">Price</label>

<input

name="price"

type="number"

className="form-control"

value={product.price || ""}

onChange={handleChange}

required

/>

</div>

<button type="submit" className="btn btn-success me-2">

Update

</button>

<button

type="button"

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


className="btn btn-secondary"

onClick={() => navigate("/")}

>

Cancel

</button>

</form>

</div>

</div>

</div>

);

};

export default EditProduct;

App.js
import { BrowserRouter, Link, Route, Routes } from "react-router-dom";

import "./App.css";

import CreateProduct from "./components/CreateProduct";

import ProductList from "./components/ProductList";

import Footer from "./components/Footer";

import EditProduct from "./components/EditProduct";

function App() {

return (

<div className="App">

<BrowserRouter>

<ul>

<li>

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


<Link to="/create">CreateProduct</Link>

</li>

<li>

<Link to="/list">ProductList</Link>

</li>

</ul>

<Routes>

<Route path="/" element={<ProductList />} />

<Route path="/create" element={<CreateProduct />} />

<Route path="/list" element={<ProductList />} />

<Route path="/edit/:id" element={<EditProduct />} />

</Routes>

</BrowserRouter>

<Footer/>

</div>

);

export default App;

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


Chapter 10: FontAwesome in React

Steps:

1. Install:

npm install @fortawesome/react-fontawesome @fortawesome/fontawesome-svg-core


@fortawesome/free-solid-svg-icons

2. Use in component:

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


<FontAwesomeIcon icon={faCoffee} />

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


Chapter 11: Data Tables

Project: User Table with Pagination

Library: react-data-table-component

Install:

npm install react-data-table-component

Render a sortable, paginated table using sample user data.

// src/MyDataTable.js

import React, { useState } from "react";

import DataTable from "react-data-table-component";

// Sample data

const data = [

{ id: 1, name: "John Doe", email: "john@example.com", role: "Admin" },

{ id: 2, name: "Jane Smith", email: "jane@example.com", role: "User" },

{ id: 3, name: "Bob Johnson", email: "bob@example.com", role: "Editor" },

];

// Column configuration

const columns = [

{ name: "ID", selector: row => row.id, sortable: true },

{ name: "Name", selector: row => row.name, sortable: true },

{ name: "Email", selector: row => row.email },

{ name: "Role", selector: row => row.role },

];

const MyDataTable = () => {

const [searchText, setSearchText] = useState("");

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


const filteredData = data.filter(item =>

item.name.toLowerCase().includes(searchText.toLowerCase()) ||

item.email.toLowerCase().includes(searchText.toLowerCase()) ||

item.role.toLowerCase().includes(searchText.toLowerCase())

);

return (

<div style={{ padding: "20px" }}>

<h2>User Data Table</h2>

<input

type="text"

placeholder="Search by name, email, or role"

value={searchText}

onChange={(e) => setSearchText(e.target.value)}

style={{

marginBottom: "10px",

padding: "8px",

width: "300px",

border: "1px solid #ccc",

borderRadius: "4px"

}}

/>

<DataTable

columns={columns}

data={filteredData}

pagination

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


highlightOnHover

selectableRows

striped

/>

</div>

);

};

export default MyDataTable;

import './App.css';

import MyDataTable from './components/MyDataTable';

function App() {

return (

<div className="App">

<MyDataTable/>

</div>

);

export default App;

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


Chapter 12: Firebase Authentication Integration

Project: Firebase Auth App

• Register/Login/Forgot Password

• Secure Dashboard

Steps:

1. Setup Firebase Project

2. Install dependencies:

npm install firebase react-router-dom bootstrap

3. Create a file src/firebase.js


// src/firebase.js
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";

const firebaseConfig = {
apiKey: "YOUR_API_KEY", // from Firebase settings
authDomain: "YOUR_AUTH_DOMAIN",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_STORAGE_BUCKET",
messagingSenderId: "YOUR_MSG_ID",
appId: "YOUR_APP_ID"
};

const app = initializeApp(firebaseConfig);


export const auth = getAuth(app);

4. Create components: Register.js, Login.js, ForgotPassword.js, Dashboard.js

Register.js
import React, { useState } from "react";

import { auth } from "./firebase";

import { createUserWithEmailAndPassword } from "firebase/auth";

import { Link, useNavigate } from "react-router-dom";

function Register() {

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


const [email, setEmail] = useState("");

const [password, setPassword] = useState("");

const navigate = useNavigate();

const register = async (e) => {

e.preventDefault();

try {

await createUserWithEmailAndPassword(auth, email, password);

alert("Registered successfully!");

navigate("/");

} catch (error) {

alert(error.message);

};

return (

<div>

<div className="container" style={{ marginTop: 50 }}>

<h1

className="blink-title"

style={{ color: "blue", textAlign: "center" }}

>

Login | Register | Forgotpassword | Firebase Application

</h1>

<div className="card">

<div className="card-header">

<h2>Register</h2>

</div>

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


<div className="card-body">

<form onSubmit={register}>

<input

type="email"

placeholder="Email"

onChange={(e) => setEmail(e.target.value)}

required

/>

<input

type="password"

placeholder="Password"

onChange={(e) => setPassword(e.target.value)}

required

/>

<button

type="submit"

className="btn btn-primary"

style={{ marginLeft: 10 }}

>

Register

</button>

</form>

<p>

Already have an account? <Link to="/">Login</Link>

</p>

</div>

</div>

</div>

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


</div>

);

export default Register;

Login.js
import React, { useState } from "react";

import { auth } from "./firebase";

import { signInWithEmailAndPassword } from "firebase/auth";

import { Link, useNavigate } from "react-router-dom";

function Login() {

const [email, setEmail] = useState("");

const [password, setPassword] = useState("");

const navigate = useNavigate();

const login = async (e) => {

e.preventDefault();

try {

await signInWithEmailAndPassword(auth, email, password);

navigate("/dashboard");

} catch (error) {

alert(error.message);

};

return (

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


<div>

<div className="container" style={{ marginTop: 50 }}>

<h1 className="blink-title" style={{ color: 'blue', textAlign: 'center' }}>

Login | Register | Forgotpassword | Firebase Application

</h1>

<div className="card">

<div className="card-header">

<h2>Login</h2>

</div>

<div className="card-body">

<form onSubmit={login}>

<input

type="email"

placeholder="Email"

className="form-control"

onChange={(e) => setEmail(e.target.value)}

required

/>

<input

type="password"

placeholder="Password"

className="form-control"

onChange={(e) => setPassword(e.target.value)}

required

/>

<button type="submit" className="btn btn-primary">

Login

</button>

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


<Link to="/forgot-password"> Forgot Password?</Link>

<p>

No account? <Link to="/register">Register</Link>

</p>

</form>

</div>

</div>

</div>

</div>

);

export default Login;

import React, { useState } from "react";

import { sendPasswordResetEmail } from "firebase/auth";

import { auth } from "./firebase";

import { Link } from "react-router-dom";

function ForgotPassword() {

const [email, setEmail] = useState("");

const resetPassword = async (e) => {

e.preventDefault();

try {

await sendPasswordResetEmail(auth, email);

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


alert("Reset link sent to your email!");

} catch (error) {

alert(error.message);

};

return (

<div>

<div className="container" style={{ marginTop: 50 }}>

<h1

className="blink-title"

style={{ color: "blue", textAlign: "center" }}

>

Login | Register | Forgotpassword | Firebase Application

</h1>

<div className="card">

<div className="card-header">

<h2>Forgot Password</h2>

</div>

<div className="card-body">

<form onSubmit={resetPassword}>

<input

type="email"

placeholder="Email"

onChange={(e) => setEmail(e.target.value)}

required

/>

<button

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


type="submit"

className="btn btn-primary"

style={{ marginLeft: 10 }}

>

{" "}

Send Reset Link

</button>

</form>

</div>

<p style={{ marginLeft: 10 }}>

<Link to="/">Back to Login</Link>

</p>

</div>

</div>

</div>

);

export default ForgotPassword;

import React from "react";

import { auth } from "./firebase";

import { signOut } from "firebase/auth";

import { useNavigate } from "react-router-dom";

function Dashboard() {

const navigate = useNavigate();

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


const logout = async () => {

await signOut(auth);

navigate("/");

};

return (

<div>

<div className="container" style={{marginTop:50}}>

<div className="card">

<div className="card-header">

<h2>Dashboard</h2>

</div>

<div className="card-body">

<p>Welcome, {auth.currentUser?.email}</p>

</div>

<button onClick={logout} className="btn btn-warning">Logout</button>

</div>

</div>

</div>

);

export default Dashboard;

5. Setup routing in App.js using <Routes>

6. import React from 'react';


7. import { BrowserRouter as Router, Routes, Route } from 'react-router-
dom';
8. import Register from './Register';
9. import Login from './Login';

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


10. import ForgotPassword from './ForgotPassword';
11. import Dashboard from './Dashboard';
12.
13. function App() {
14. return (
15. <Router>
16. <Routes>
17. <Route path='/' element={<Login />} />
18. <Route path='/register' element={<Register />} />
19. <Route path='/forgot-password' element={<ForgotPassword />} />
20. <Route path='/dashboard' element={<Dashboard />} />
21. </Routes>
22. </Router>
23. );
24. }
25.
26. export default App;
27.

Java Full Stack Trainer Chandra Sekhar +91- 9866037742


Final Thoughts

This book has equipped you with both the theoretical foundation and practical
experience necessary to confidently tackle front-end interviews and contribute
meaningfully to any React-based project. By building complete, topic-wise
applications, you now possess a job-ready portfolio.

Java Full Stack Trainer Chandra Sekhar +91- 9866037742

You might also like