ALL SLIPS CODE : React practical, slip-wise

Each slip has: question, folder structure, then every file with its path and code.

CONTENTS

  Slip  1 : Login form events
  Slip  2 : Fetch users with useEffect
  Slip  3 : ON OFF UI background
  Slip  4 : Home, About, Contact routes with validation
  Slip  5 : Login validation and 404
  Slip  6 : Protected route with mock authentication
  Slip  7 : TODO list
  Slip  8 : ON OFF button text and background
  Slip  9 : Counter with initial prop
  Slip 10 : Number validation and digit sum
  Slip 11 : String operations
  Slip 12 : Notes management with Redux Toolkit
  Slip 13 : Redux counter with console output
  Slip 14 : Calculator
  Slip 15 : Counter using actions and reducer
  Slip 16 : Traditional DOM vs Virtual DOM
  Slip 17 : Sign In and Sign Out
  Slip 18 : Profile with name, bio and image
  Slip 19 : Ten favorite movies
  Slip 20 : Login and dynamic route parameters
  Slip 21 : Even/Odd and palindrome

################################################################################
# SLIP 1 : Login form events
################################################################################

QUESTION

2) Create a react application which contains user login form with styling with event handlers
   for OnInput() and OnSubmit() and onChange() events. Display the entered values in the
   console.
                                                                              (12 Marks)

FOLDER STRUCTURE

slip1/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   `-- main.jsx
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip1/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(<App />);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip1/src/App.jsx
--------------------------------------------------------------------------------
import React, { useState } from 'react';

export default function App() {
  const [username, setUsername] = useState('');
  const [password, setPassword] = useState('');
  const [message, setMessage] = useState('');

  function handleSubmit(e) {
    e.preventDefault();
    console.log('onSubmit:', { username, password });
    setMessage('Form submitted. Check the console.');
  }

  return <main>
    <h1>User Login</h1>
    <form onSubmit={handleSubmit}>
      <label>Username<input value={username} required
        onInput={e => console.log('onInput:', e.currentTarget.value)}
        onChange={e => setUsername(e.target.value)} /></label>
      <label>Password<input type="password" value={password} required
        onChange={e => { setPassword(e.target.value); console.log('onChange: password changed'); }} /></label>
      <button type="submit">Login</button>
    </form>
    <p role="status">{message}</p>
    <small>Practice only: use dummy credentials, not a real password.</small>
  </main>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip1/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip1/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 01 - Login Form Events</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip1/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-01",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

################################################################################
# SLIP 2 : Fetch users with useEffect
################################################################################

QUESTION

2) Create a react functional component using useEffect () that fetches and displays data from
   an API (e.g. users list) on console.                                      (12 Marks)

FOLDER STRUCTURE

slip2/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   `-- main.jsx
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip2/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(<App />);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip2/src/App.jsx
--------------------------------------------------------------------------------
import React, { useEffect, useState } from 'react';

export default function App() {
  const [users, setUsers] = useState([]);
  const [status, setStatus] = useState('Loading users...');

  useEffect(() => {
    fetch('https://jsonplaceholder.typicode.com/users')
      .then(response => {
        if (!response.ok) throw new Error('HTTP ' + response.status);
        return response.json();
      })
      .then(data => {
        console.log('Users:', data);
        setUsers(data);
        setStatus('Users loaded. Open the console.');
      })
      .catch(error => {
        console.error(error);
        setStatus('Could not fetch users. Check internet connection.');
      });
  }, []);

  return <main><h1>Users List</h1><p role="status">{status}</p>
    <ul>{users.map(user => <li key={user.id}>{user.name} - {user.email}</li>)}</ul>
  </main>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip2/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip2/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 02 - Fetch Users with useEffect</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip2/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-02",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

################################################################################
# SLIP 3 : ON OFF UI background
################################################################################

QUESTION

2) Write a program to create a react application, create a button that toggles between
   ON and OFF states when clicked. Change background color of UI when button state
   chang                                                                       (12 Marks)

FOLDER STRUCTURE

slip3/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   `-- main.jsx
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip3/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(<App />);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip3/src/App.jsx
--------------------------------------------------------------------------------
import React, { useState } from 'react';

export default function App() {
  const [on, setOn] = useState(false);
  return <div className="full-page" style={{ backgroundColor: on ? '#d1fae5' : '#fee2e2' }}>
    <main><h1>Toggle UI Background</h1>
      <button onClick={() => setOn(!on)}>{on ? 'ON' : 'OFF'}</button>
      <p>Current state: {on ? 'ON' : 'OFF'}</p>
    </main>
  </div>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip3/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip3/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 03 - ON OFF UI Background</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip3/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-03",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

################################################################################
# SLIP 4 : Home, About, Contact routes with validation
################################################################################

QUESTION

2) Create a multi-page React application using react-router-dom with Home, About and
   Contact pages. For each Route display appropriate UI with validation.     (12 Marks)

FOLDER STRUCTURE

slip4/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   `-- main.jsx
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

EXTRA LIBRARIES

npm install react-router-dom@6

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip4/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(<App />);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip4/src/App.jsx
--------------------------------------------------------------------------------
import React, { useState } from 'react';
import { BrowserRouter, Routes, Route, Link } from 'react-router-dom';

function Home() { return <section><h2>Home</h2><p>Welcome to our website.</p></section>; }
function About() { return <section><h2>About</h2><p>This is a React Router demo.</p></section>; }
function Contact() {
  const [name, setName] = useState('');
  const [email, setEmail] = useState('');
  const [message, setMessage] = useState('');
  function submit(e) {
    e.preventDefault();
    if (!name.trim() || !/^\S+@\S+\.\S+$/.test(email.trim())) {
      setMessage('Enter a valid name and email.');
    } else setMessage('Contact form submitted successfully.');
  }
  return <section><h2>Contact</h2><form onSubmit={submit} noValidate>
    <label>Name<input value={name} onChange={e => setName(e.target.value)} /></label>
    <label>Email<input type="email" value={email} onChange={e => setEmail(e.target.value)} /></label>
    <button>Submit</button></form><p role="status">{message}</p></section>;
}
export default function App() {
  return <BrowserRouter><main><h1>Multi-page React App</h1>
    <nav><Link to="/">Home</Link><Link to="/about">About</Link><Link to="/contact">Contact</Link></nav>
    <Routes><Route path="/" element={<Home />} /><Route path="/about" element={<About />} />
      <Route path="/contact" element={<Contact />} /><Route path="*" element={<h2>404 Error, Page Not Found</h2>} /></Routes>
  </main></BrowserRouter>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip4/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip4/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 04 - Home About Contact Routes</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip4/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-04",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1",
    "react-router-dom": "^6.30.6"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

################################################################################
# SLIP 5 : Login validation and 404
################################################################################

QUESTION

2) Design login form which accepts username and password                     (12 Marks)
     a.      On submit button click it should validate username and password and console
     log if its valid
     b. Validity check should be simple like username: Admin; password: Pass123
     c. If any other credentials it should say Unauthorized Access
     d. If the router name is wrong then the display message is “404 Error, Page Not Found”.

FOLDER STRUCTURE

slip5/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   `-- main.jsx
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

EXTRA LIBRARIES

npm install react-router-dom@6

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip5/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(<App />);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip5/src/App.jsx
--------------------------------------------------------------------------------
import React, { useState } from 'react';
import { BrowserRouter, Routes, Route, Link } from 'react-router-dom';

function Login() {
  const [username, setUsername] = useState('');
  const [password, setPassword] = useState('');
  const [message, setMessage] = useState('');
  function submit(e) {
    e.preventDefault();
    if (username === 'Admin' && password === 'Pass123') {
      console.log('Valid login:', username);
      setMessage('Login Successful');
    } else setMessage('Unauthorized Access');
  }
  return <section><h2>Login</h2><form onSubmit={submit}>
    <label>Username<input value={username} onChange={e => setUsername(e.target.value)} /></label>
    <label>Password<input type="password" value={password} onChange={e => setPassword(e.target.value)} /></label>
    <button>Login</button></form><p role="status">{message}</p></section>;
}
export default function App() {
  return <BrowserRouter><main><h1>Login System</h1><nav><Link to="/">Home</Link><Link to="/login">Login</Link></nav>
    <Routes><Route path="/" element={<Login />} /><Route path="/login" element={<Login />} />
      <Route path="*" element={<h2>404 Error, Page Not Found</h2>} /></Routes>
  </main></BrowserRouter>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip5/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip5/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 05 - Login Validation and 404</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip5/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-05",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1",
    "react-router-dom": "^6.30.6"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

################################################################################
# SLIP 6 : Protected route with mock authentication
################################################################################

QUESTION

2) Create a react application which contains a protected route that only shows a page if the
   user is authenticated (mock authentication). Display proper message once user
   authenticates.                                                              (12 Marks)

FOLDER STRUCTURE

slip6/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   `-- main.jsx
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

EXTRA LIBRARIES

npm install react-router-dom@6

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip6/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(<App />);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip6/src/App.jsx
--------------------------------------------------------------------------------
import React, { useState } from 'react';
import { BrowserRouter, Routes, Route, Link } from 'react-router-dom';

function ProtectedRoute({ authenticated, children }) {
  return authenticated ? children : <p>Please sign in first. Access denied.</p>;
}
export default function App() {
  const [authenticated, setAuthenticated] = useState(false);
  return <BrowserRouter><main><h1>Protected Route Demo</h1>
    <nav><Link to="/">Home</Link><Link to="/dashboard">Dashboard</Link></nav>
    <button onClick={() => setAuthenticated(true)}>Sign In</button>{' '}
    <button onClick={() => setAuthenticated(false)}>Sign Out</button>
    <p role="status">{authenticated ? 'Authentication Successful' : 'Not authenticated'}</p>
    <Routes><Route path="/" element={<p>Welcome. Sign in to view Dashboard.</p>} />
      <Route path="/dashboard" element={<ProtectedRoute authenticated={authenticated}>
        <h2>Welcome to Protected Dashboard</h2></ProtectedRoute>} />
      <Route path="*" element={<h2>404 Error, Page Not Found</h2>} /></Routes>
  </main></BrowserRouter>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip6/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip6/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 06 - Protected Route Mock Authentication</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip6/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-06",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1",
    "react-router-dom": "^6.30.6"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

################################################################################
# SLIP 7 : TODO list
################################################################################

QUESTION

2) Create a basic react TODO List application:                            (12 Marks)
      a. Build a component for adding, displaying, and deleting tasks.
      b. Use state to manage the list of tasks.
      c. Add a form for users to input new tasks.
      d. Display the list of tasks and provide a button to remove them.

FOLDER STRUCTURE

slip7/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   `-- main.jsx
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip7/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(<App />);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip7/src/App.jsx
--------------------------------------------------------------------------------
import React, { useState } from 'react';

export default function App() {
  const [task, setTask] = useState('');
  const [tasks, setTasks] = useState([]);
  function addTask(e) {
    e.preventDefault();
    if (!task.trim()) return;
    setTasks([...tasks, task.trim()]);
    setTask('');
  }
  function deleteTask(index) {
    setTasks(tasks.filter((_, i) => i !== index));
  }
  return <main><h1>TODO List</h1><form onSubmit={addTask}>
    <label>New Task<input value={task} onChange={e => setTask(e.target.value)} /></label>
    <button>Add Task</button></form>
    <ul>{tasks.map((item, index) => <li key={index}>{item} {' '}
      <button type="button" onClick={() => deleteTask(index)}>Delete</button></li>)}</ul>
  </main>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip7/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip7/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 07 - TODO List</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip7/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-07",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

################################################################################
# SLIP 8 : ON OFF button text and background
################################################################################

QUESTION

2) Create a react application which contains a toggle button. When a button is clicked by the
   user, button text should toggle between ON and OFF and background color of text should
   also get changed, visually reflecting the state.                          (12 Marks)

FOLDER STRUCTURE

slip8/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   `-- main.jsx
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip8/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(<App />);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip8/src/App.jsx
--------------------------------------------------------------------------------
import React, { useState } from 'react';

export default function App() {
  const [on, setOn] = useState(false);
  return <main><h1>Toggle Button</h1>
    <button style={{ backgroundColor: on ? 'green' : 'red', color: 'white' }}
      onClick={() => setOn(!on)}>{on ? 'ON' : 'OFF'}</button>
  </main>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip8/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip8/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 08 - ON OFF Button Text Background</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip8/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-08",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

################################################################################
# SLIP 9 : Counter with initial prop
################################################################################

QUESTION

2)    Create a simple react component called Counter that displays a number and
      has 2 buttons "Increment" and "Decrement." The number should start at 0 and
      change when the buttons are clicked.                               (12 Marks)
        a. Use state to manage the number.
        b. Pass the initial number as a prop to the Counter component.

FOLDER STRUCTURE

slip9/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   `-- main.jsx
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip9/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(<App />);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip9/src/App.jsx
--------------------------------------------------------------------------------
import React, { useState } from 'react';

function Counter({ initialNumber }) {
  const [count, setCount] = useState(initialNumber);
  return <section><h2>Count: {count}</h2>
    <button onClick={() => setCount(count + 1)}>Increment</button>{' '}
    <button onClick={() => setCount(count - 1)}>Decrement</button>
  </section>;
}
export default function App() {
  return <main><h1>Counter App</h1><Counter initialNumber={0} /></main>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip9/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip9/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 09 - Counter with Initial Prop</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip9/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-09",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

################################################################################
# SLIP 10 : Number validation and digit sum
################################################################################

QUESTION

2) Create a react application to check whether a number is valid or not and also calculate the
   sum of the digit of the number entered by the user and display it on UI. Also display
   appropriate messages on the UI if the entered value is invalid or blank. (12 Marks)

FOLDER STRUCTURE

slip10/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   `-- main.jsx
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip10/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(<App />);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip10/src/App.jsx
--------------------------------------------------------------------------------
import React, { useState } from 'react';

export default function App() {
  const [number, setNumber] = useState('');
  const [result, setResult] = useState('');
  function calculate(e) {
    e.preventDefault();
    const value = number.trim();
    if (value === '') { setResult('Please enter a number.'); return; }
    if (!/^[+-]?\d+$/.test(value)) { setResult('Invalid number. Enter an integer.'); return; }
    const digits = value.replace(/^[+-]/, '');
    let sum = 0;
    for (const digit of digits) sum += Number(digit);
    setResult('Valid Number. Sum of digits: ' + sum);
  }
  return <main><h1>Sum of Digits</h1><form onSubmit={calculate}>
    <label>Enter a number<input value={number} onChange={e => setNumber(e.target.value)} /></label>
    <button>Calculate</button></form><p role="status">{result}</p></main>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip10/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip10/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 10 - Number Validation and Digit Sum</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip10/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-10",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

################################################################################
# SLIP 11 : String operations
################################################################################

QUESTION

2) Create React Application which will take string as input from user and perform string
   operations given below:
       a. Uppercase
       b. Lowercase
       c. Length of String
       d. Reverse of String.                                                (12 Marks)

FOLDER STRUCTURE

slip11/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   `-- main.jsx
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip11/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(<App />);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip11/src/App.jsx
--------------------------------------------------------------------------------
import React, { useState } from 'react';

export default function App() {
  const [text, setText] = useState('');
  return <main><h1>String Operations</h1>
    <label>Enter a string<input value={text} onChange={e => setText(e.target.value)} /></label>
    <p>Uppercase: {text.toUpperCase()}</p><p>Lowercase: {text.toLowerCase()}</p>
    <p>Length of String: {text.length}</p><p>Reverse: {Array.from(text).reverse().join('')}</p>
  </main>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip11/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip11/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 11 - String Operations</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip11/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-11",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

################################################################################
# SLIP 12 : Notes management with Redux Toolkit
################################################################################

QUESTION

2) Create a react application which will build a notes management app using Redux
   Toolkit with createSlice() to manage state.
                                                                             (12 Marks)

FOLDER STRUCTURE

slip12/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   |-- main.jsx
|   `-- store.js
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

EXTRA LIBRARIES

npm install @reduxjs/toolkit react-redux

--------------------------------------------------------------------------------
FILE : store.js
PATH : slip12/src/store.js
--------------------------------------------------------------------------------
import { configureStore, createSlice } from '@reduxjs/toolkit';

let nextId = 1;
const notesSlice = createSlice({
  name: 'notes',
  initialState: [],
  reducers: {
    addNote(state, action) {
      state.push(action.payload);
    },
    deleteNote(state, action) {
      return state.filter(note => note.id !== action.payload);
    },
    editNote(state, action) {
      const note = state.find(n => n.id === action.payload.id);
      if (note) note.text = action.payload.text;
    }
  }
});
export const addNote = text => notesSlice.actions.addNote({ id: nextId++, text });
export const { deleteNote, editNote } = notesSlice.actions;
export const store = configureStore({ reducer: { notes: notesSlice.reducer } });

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip12/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';
import { Provider } from 'react-redux';
import { store } from './store.js';

createRoot(document.getElementById('root')).render(<Provider store={store}><App /></Provider>);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip12/src/App.jsx
--------------------------------------------------------------------------------
import React, { useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { addNote, deleteNote, editNote } from './store.js';

export default function App() {
  const [text, setText] = useState('');
  const [editing, setEditing] = useState(null);
  const notes = useSelector(state => state.notes);
  const dispatch = useDispatch();
  function save(e) {
    e.preventDefault();
    if (!text.trim()) return;
    if (editing === null) dispatch(addNote(text.trim()));
    else dispatch(editNote({ id: editing, text: text.trim() }));
    setText(''); setEditing(null);
  }
  return <main><h1>Notes Management</h1><form onSubmit={save}>
    <label>Note<textarea value={text} onChange={e => setText(e.target.value)} /></label>
    <button>{editing === null ? 'Add Note' : 'Save Note'}</button></form>
    <ul>{notes.map(note => <li key={note.id}>{note.text}{' '}
      <button onClick={() => { setEditing(note.id); setText(note.text); }}>Edit</button>{' '}
      <button onClick={() => { dispatch(deleteNote(note.id)); if (editing === note.id) { setEditing(null); setText(''); } }}>Delete</button>
    </li>)}</ul>
  </main>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip12/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip12/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 12 - Notes Management Redux Toolkit</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip12/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-12",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1",
    "@reduxjs/toolkit": "^2.8.2",
    "react-redux": "^9.2.0"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

################################################################################
# SLIP 13 : Redux counter with console output
################################################################################

QUESTION

2) Create a Redux store of counter buttons to display the current count and provide two
   buttons to increment and decrement the count. Display count on console. (12 Marks)

FOLDER STRUCTURE

slip13/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   |-- main.jsx
|   `-- store.js
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

EXTRA LIBRARIES

npm install @reduxjs/toolkit react-redux

--------------------------------------------------------------------------------
FILE : store.js
PATH : slip13/src/store.js
--------------------------------------------------------------------------------
import { configureStore, createSlice } from '@reduxjs/toolkit';
const counterSlice = createSlice({
  name: 'counter', initialState: 0,
  reducers: {
    increment: state => state + 1,
    decrement: state => state - 1
  }
});
export const { increment, decrement } = counterSlice.actions;
export const store = configureStore({ reducer: { counter: counterSlice.reducer } });

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip13/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';
import { Provider } from 'react-redux';
import { store } from './store.js';

createRoot(document.getElementById('root')).render(<Provider store={store}><App /></Provider>);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip13/src/App.jsx
--------------------------------------------------------------------------------
import React, { useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { increment, decrement } from './store.js';

export default function App() {
  const count = useSelector(state => state.counter);
  const dispatch = useDispatch();
  useEffect(() => { console.log('Current Count:', count); }, [count]);
  return <main><h1>Redux Counter</h1><h2>Count: {count}</h2>
    <button onClick={() => dispatch(increment())}>Increment</button>{' '}
    <button onClick={() => dispatch(decrement())}>Decrement</button>
  </main>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip13/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip13/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 13 - Redux Counter and Console</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip13/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-13",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1",
    "@reduxjs/toolkit": "^2.8.2",
    "react-redux": "^9.2.0"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

################################################################################
# SLIP 14 : Calculator
################################################################################

QUESTION

2) Create a react application to create a Calculator.          (12 Marks)

FOLDER STRUCTURE

slip14/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   `-- main.jsx
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip14/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(<App />);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip14/src/App.jsx
--------------------------------------------------------------------------------
import React, { useState } from 'react';

export default function App() {
  const [first, setFirst] = useState('');
  const [second, setSecond] = useState('');
  const [result, setResult] = useState('');
  function calculate(operator) {
    const a = Number(first), b = Number(second);
    if (!first.trim() || !second.trim() || !Number.isFinite(a) || !Number.isFinite(b)) {
      setResult('Enter two valid numbers.'); return;
    }
    switch (operator) {
      case '+': setResult(a + b); break;
      case '-': setResult(a - b); break;
      case '*': setResult(a * b); break;
      case '/': setResult(b === 0 ? 'Cannot divide by zero.' : a / b); break;
      default: break;
    }
  }
  return <main><h1>Calculator</h1>
    <label>First Number<input type="number" step="any" value={first} onChange={e => setFirst(e.target.value)} /></label>
    <label>Second Number<input type="number" step="any" value={second} onChange={e => setSecond(e.target.value)} /></label>
    <div className="buttons">{['+', '-', '*', '/'].map(op => <button key={op} onClick={() => calculate(op)}>{op}</button>)}
      <button onClick={() => { setFirst(''); setSecond(''); setResult(''); }}>Clear</button></div>
    <h2>Result: {result}</h2>
  </main>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip14/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip14/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 14 - Calculator</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip14/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-14",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

################################################################################
# SLIP 15 : Counter using actions and reducer
################################################################################

QUESTION

2) Create a React application to create a simple counter using actions and reducers.
                                                                                 (12 Marks)

FOLDER STRUCTURE

slip15/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   |-- main.jsx
|   `-- store.js
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

EXTRA LIBRARIES

npm install redux react-redux

--------------------------------------------------------------------------------
FILE : store.js
PATH : slip15/src/store.js
--------------------------------------------------------------------------------
import { legacy_createStore as createStore } from 'redux';

export const increment = () => ({ type: 'INCREMENT' });
export const decrement = () => ({ type: 'DECREMENT' });

function reducer(state = { count: 0 }, action) {
  switch (action.type) {
    case 'INCREMENT': return { count: state.count + 1 };
    case 'DECREMENT': return { count: state.count - 1 };
    default: return state;
  }
}
export const store = createStore(reducer);

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip15/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';
import { Provider } from 'react-redux';
import { store } from './store.js';

createRoot(document.getElementById('root')).render(<Provider store={store}><App /></Provider>);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip15/src/App.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { increment, decrement } from './store.js';

export default function App() {
  const count = useSelector(state => state.count);
  const dispatch = useDispatch();
  return <main><h1>Counter Using Actions and Reducer</h1><h2>Count: {count}</h2>
    <button onClick={() => dispatch(increment())}>Increment</button>{' '}
    <button onClick={() => dispatch(decrement())}>Decrement</button>
  </main>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip15/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip15/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 15 - Counter Using Actions and Reducer</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip15/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-15",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1",
    "redux": "^5.0.1",
    "react-redux": "^9.2.0"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

################################################################################
# SLIP 16 : Traditional DOM vs Virtual DOM
################################################################################

QUESTION

2) Create a react application to demonstrate the concept of virtual DOM by comparing
   traditional DOM vs React rendering through a counter example.           (12 Marks)

FOLDER STRUCTURE

slip16/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   `-- main.jsx
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip16/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(<App />);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip16/src/App.jsx
--------------------------------------------------------------------------------
import React, { useState } from 'react';

let domCount = 0;
function incrementDOM() {
  domCount++;
  document.getElementById('dom-count').textContent = domCount;
}
function ReactCounter() {
  const [count, setCount] = useState(0);
  return <section><h2>React Virtual DOM</h2><p>Count: {count}</p>
    <button onClick={() => setCount(count + 1)}>Increment React</button>
    <p>React updates the DOM from state.</p></section>;
}
export default function App() {
  return <main><h1>Traditional DOM vs React</h1>
    <section><h2>Traditional DOM</h2><p>Count: <span id="dom-count">0</span></p>
      <button onClick={incrementDOM}>Increment DOM</button>
      <p>JavaScript directly updates the DOM element.</p></section>
    <hr /><ReactCounter />
  </main>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip16/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip16/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 16 - Traditional DOM vs Virtual DOM</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip16/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-16",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

################################################################################
# SLIP 17 : Sign In and Sign Out
################################################################################

QUESTION

2) Create a React application for Sign-In and Sign-Out functionality using useState()
   hook. When sign in button is clicked then the display message is Hello, Welcome in
   Home Page and the sign out button is clicked then the display message is “Please sign
   in first”.
                                                                          (12 Marks)

FOLDER STRUCTURE

slip17/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   `-- main.jsx
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip17/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(<App />);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip17/src/App.jsx
--------------------------------------------------------------------------------
import React, { useState } from 'react';

export default function App() {
  const [signedIn, setSignedIn] = useState(false);
  return <main><h1>Sign In / Sign Out</h1>
    <h2 role="status">{signedIn ? 'Hello, Welcome in Home Page' : 'Please sign in first'}</h2>
    <button onClick={() => setSignedIn(true)}>Sign In</button>{' '}
    <button onClick={() => setSignedIn(false)}>Sign Out</button>
  </main>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip17/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip17/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 17 - Sign In and Sign Out</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip17/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-17",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

################################################################################
# SLIP 18 : Profile with name, bio and image
################################################################################

QUESTION

2)    Create a React application that displays your name, a short bio, and an image and
      description of your profile.                                               (12 Marks)

FOLDER STRUCTURE

slip18/
|-- public/
|   `-- profile.svg
|-- src/
|   |-- App.jsx
|   |-- index.css
|   `-- main.jsx
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip18/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(<App />);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip18/src/App.jsx
--------------------------------------------------------------------------------
import React from 'react';

export default function App() {
  return <main className="profile"><h1>My Profile</h1>
    <img className="profile-image" src="/profile.svg" alt="Sample profile avatar" />
    <h2>Your Name</h2>
    <p><strong>Bio:</strong> I am a student learning web development.</p>
    <p><strong>Profile:</strong> I enjoy learning React, JavaScript and software testing.</p>
  </main>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip18/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip18/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 18 - Profile with Name Bio and Image</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip18/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-18",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

--------------------------------------------------------------------------------
FILE : profile.svg
PATH : slip18/public/profile.svg
--------------------------------------------------------------------------------
<svg xmlns="http://www.w3.org/2000/svg" width="240" height="240" viewBox="0 0 240 240"><rect width="240" height="240" rx="24" fill="#dbeafe"/><circle cx="120" cy="83" r="44" fill="#64748b"/><path d="M35 214c0-53 36-82 85-82s85 29 85 82" fill="#64748b"/></svg>

################################################################################
# SLIP 19 : Ten favorite movies
################################################################################

QUESTION

2) Create a react application to design a functional component which will display a list
   of 10 favorite movies using JSX.
                                                                              (12 Marks)

FOLDER STRUCTURE

slip19/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   `-- main.jsx
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip19/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(<App />);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip19/src/App.jsx
--------------------------------------------------------------------------------
import React from 'react';

function FavoriteMovies() {
  const movies = ['3 Idiots', 'Dangal', 'Interstellar', 'Inception', 'The Dark Knight',
    'Taare Zameen Par', 'Drishyam', 'Chhichhore', 'The Lion King', 'Zindagi Na Milegi Dobara'];
  return <section><h2>My 10 Favorite Movies</h2>
    <ol>{movies.map(movie => <li key={movie}>{movie}</li>)}</ol></section>;
}
export default function App() {
  return <main><h1>Favorite Movies</h1><FavoriteMovies /></main>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip19/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip19/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 19 - Ten Favorite Movies</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip19/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-19",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

################################################################################
# SLIP 20 : Login and dynamic route parameters
################################################################################

QUESTION

2) Create a login system to pass parameters through routes and display the dynamic
   data (e.g., /user/:id should show user details).                         (12 Marks)

FOLDER STRUCTURE

slip20/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   `-- main.jsx
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

EXTRA LIBRARIES

npm install react-router-dom@6

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip20/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(<App />);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip20/src/App.jsx
--------------------------------------------------------------------------------
import React, { useState } from 'react';
import { BrowserRouter, Routes, Route, Link, useNavigate, useParams } from 'react-router-dom';

const users = {
  '1': { name: 'Amit', email: 'amit@example.com' },
  '2': { name: 'Neha', email: 'neha@example.com' }
};
function Login() {
  const [id, setId] = useState('');
  const [password, setPassword] = useState('');
  const [message, setMessage] = useState('');
  const navigate = useNavigate();
  function submit(e) {
    e.preventDefault();
    if (Object.hasOwn(users, id.trim()) && password === 'Pass123') navigate('/user/' + id.trim());
    else setMessage('Invalid user ID or password');
  }
  return <section><h2>Login</h2><form onSubmit={submit}>
    <label>User ID<input value={id} onChange={e => setId(e.target.value)} /></label>
    <label>Password<input type="password" value={password} onChange={e => setPassword(e.target.value)} /></label>
    <button>Login</button></form><p role="status">{message}</p>
    <small>Demo: user ID 1 or 2, password Pass123.</small></section>;
}
function UserDetails() {
  const { id } = useParams();
  if (!Object.hasOwn(users, id)) return <h2>User Not Found</h2>;
  const user = users[id];
  return <section><h2>User Details</h2><p>User ID: {id}</p><p>Name: {user.name}</p><p>Email: {user.email}</p></section>;
}
export default function App() {
  return <BrowserRouter><main><h1>Dynamic User Routes</h1><nav><Link to="/">Login</Link></nav>
    <Routes><Route path="/" element={<Login />} /><Route path="/user/:id" element={<UserDetails />} />
      <Route path="*" element={<h2>404 Error, Page Not Found</h2>} /></Routes>
  </main></BrowserRouter>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip20/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip20/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 20 - Login and Dynamic Route Parameters</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip20/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-20",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1",
    "react-router-dom": "^6.30.6"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}

################################################################################
# SLIP 21 : Even/Odd and palindrome
################################################################################

QUESTION

2) Create a React Application to take input from the user (number, string). Check
   whether the number is even or odd and also check whether the string is palindrome or
   not. Display appropriate messages to the user.                            (12 Marks)

FOLDER STRUCTURE

slip21/
|-- src/
|   |-- App.jsx
|   |-- index.css
|   `-- main.jsx
|-- .gitignore
|-- QUESTION.txt
|-- RUN_ME.txt
|-- index.html
`-- package.json

--------------------------------------------------------------------------------
FILE : main.jsx
PATH : slip21/src/main.jsx
--------------------------------------------------------------------------------
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(<App />);

--------------------------------------------------------------------------------
FILE : App.jsx
PATH : slip21/src/App.jsx
--------------------------------------------------------------------------------
import React, { useState } from 'react';

export default function App() {
  const [number, setNumber] = useState('');
  const [text, setText] = useState('');
  const [numberResult, setNumberResult] = useState('');
  const [stringResult, setStringResult] = useState('');
  function check(e) {
    e.preventDefault();
    const value = number.trim();
    if (!value) setNumberResult('Please enter a number.');
    else if (!/^[+-]?\d+$/.test(value)) setNumberResult('Invalid number. Enter an integer.');
    else setNumberResult(Number(value.slice(-1)) % 2 === 0 ? 'Even Number' : 'Odd Number');
    const word = text.trim().toLowerCase();
    if (!word) setStringResult('Please enter a string.');
    else setStringResult(word === Array.from(word).reverse().join('') ? 'Palindrome' : 'Not a Palindrome');
  }
  return <main><h1>Even/Odd and Palindrome</h1><form onSubmit={check}>
    <label>Number<input value={number} onChange={e => setNumber(e.target.value)} /></label>
    <label>String<input value={text} onChange={e => setText(e.target.value)} /></label>
    <button>Check</button></form><p role="status">{numberResult}</p><p role="status">{stringResult}</p></main>;
}

--------------------------------------------------------------------------------
FILE : index.css
PATH : slip21/src/index.css
--------------------------------------------------------------------------------
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f1f5f9; color: #1e293b; }
main { max-width: 540px; margin: 40px auto; padding: 24px; background: white; border: 1px solid #cbd5e1; border-radius: 10px; }
h1 { margin-top: 0; font-size: 26px; color: #1e3a8a; }
label { display: block; margin: 12px 0; font-weight: bold; }
input, textarea { display: block; width: 100%; padding: 10px; margin-top: 5px; border: 1px solid #94a3b8; border-radius: 4px; font: inherit; }
button { padding: 9px 15px; border: 0; border-radius: 4px; background: #2563eb; color: white; cursor: pointer; font: inherit; }
button:hover { opacity: .85; }
button:focus-visible, a:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }
nav, .buttons { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
a { color: #1d4ed8; }
li { margin: 10px 0; overflow-wrap: anywhere; }
p { overflow-wrap: anywhere; line-height: 1.5; }
.full-page { min-height: 100vh; padding: 1px 12px; }
.profile { text-align: center; }
.profile-image { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; }
@media (max-width: 600px) { main { margin: 20px 12px; padding: 16px; } }

--------------------------------------------------------------------------------
FILE : index.html
PATH : slip21/index.html
--------------------------------------------------------------------------------
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>React Slip 21 - Even Odd and Palindrome</title>
</head>
<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

--------------------------------------------------------------------------------
FILE : package.json
PATH : slip21/package.json
--------------------------------------------------------------------------------
{
  "name": "react-slip-21",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite --host 127.0.0.1",
    "start": "vite --host 127.0.0.1",
    "build": "vite build",
    "preview": "vite preview --host 127.0.0.1"
  },
  "dependencies": {
    "react": "18.3.1",
    "react-dom": "18.3.1"
  },
  "devDependencies": {
    "vite": "^6.4.2"
  }
}
