KEMBAR78
component-based JavaScript library in react.pptx
React JS
ReactJS is a component-based JavaScript
library used to build dynamic and interactive
user interfaces.
01
React JS
02
It simplifies the creation of single-page applications (SPAs) with a focus on
performance and maintainability.
 It is developed and by Facebook & now maintained by community developer.
 Uses a virtual DOM for faster updates.
 Supports a declarative approach to designing UI components.
 Ensures better application control with one-way data binding.
What is react component ?
03
 components are the building blocks of a React application
 A component is essentially a reusable, self-contained piece of UI.
 React allows you to break down a complex UI into smaller, manageable pieces
 React offers two main types of components: functional components and class
components.
Tools Need
04
First react project using vite
05
 Vite is a modern frontend build tool that provides a faster development
experience & development server experience for modern web projects .
npm create vite@latest
Why vite ?
06
Why vite ?
07
 Vite is a fast, modern build tool with Hot Module Replacement features
created by the founder of Vue.js Evan You ,
 designed for optimized development and production workflows.
Top Reasons to Use Vite
⚡ 1. Ultra-Fast Development Server
 ite uses native ES modules to serve files directly to the browser.
Why vite ?
08
 No bundling during development = instant startup.
 Changes in code are reflected almost instantly with Hot Module Replacement
(HMR).
⚡ 1. Uses Rollup under the hood for efficient bundling.
 Automatically splits code, removes unused code (tree-shaking), and minifies output.
📦 2. Optimized Production Build
Why vite ?
09
🚀 3. Out-of-the-Box Modern Features
 ES6+ support, TypeScript, JSX, CSS modules, PostCSS, and more — no extra
config needed.
 Built-in support for .env files, dynamic imports, and asset handling.
🎯 4. Minimal Config & Easy Setup
 Create a working project in seconds using:
npm create vite@latest
Why vite ?
10
💡 5. Great DX (Developer Experience)
 Cleaner error messages.
 Fast feedback loop = higher productivity.
 Plugins and integrations are simpler.
🧩 6. Framework Agnostic, But Optimized
 Works great with Vue 3, React, Svelte, Lit, Solid, and even plain JavaScript.
 Official templates for each framework.
Why vite ?
11
🔄 7. Fast Refresh & HMR
 When you save a file, only the module that changed is updated in the browser.
 This leads to a smoother and faster dev workflow compared to traditional
bundlers.
🌍 8. Strong Community & Ecosystem
 Backed by Evan You (Vue’s creator).
 Active plugin ecosystem.
 Popular among frontend frameworks and open source tools.
Run React Project
12
npm run dev npx vite
OR
For build
npm run build npx vite build
OR
vite.config.js
13
npm run dev npx vite
OR
For build
npm run build npx vite build
OR
React Project Structure
14
Distribution Node Modules
Public Src
main.jsx node_modules
.gitignore App.jsx
useRef Hook
15
built-in React Hook that returns a mutable reference object (ref) that persists
across renders
Accessing and manipulating DOM elements without triggering re-renders.
Persisting values across renders without causing re-renders.
Storing previous state values to compare changes between renders
Optimizing performance by avoiding unnecessary state updates
useRef Hook
16
useRef Hook
17
useRef Hook Working With Attribute
18
useRef Working With Input Element
19
[Hook] useRef Working With CSS Class
20
[Hook] useRef Working With Persisted Mutable Property
21
The value of mutable property is only
updated
component is not re-rendered
[Hook] useRef Caching Expensive Computation
22
useRef holds a persistent value that survives across renders
but doesn’t cause re-renders when updated
When can use it
 When you need to re-use result multiple times without re-rendering
 Cache expensive computations
 Store previous values
 Avoid recalculating something unnecessarily
 Preventing reinitialization of complex objects
Where can use it
 For API Calling
 Avoiding duplicate form submissions
[Hook] useRef Caching Expensive Computation
23
If state change occure then re-render the component
24
The React useState Hook allows us to track state in a function component.
State generally refers to data or properties that need to be tracking in an application
When to Use useState
 We need a simple state management solution.
 We component has state that changes over time.
 The state does not require complex updates or dependencies.
[Hook] useState Understading Inside
25
[Hook] useState Understading Inside
State
Holds all data
view
26
[Hook] useState Understading Inside
27
[Hook] useState Understading Inside
[Hook] useState Working With Immutable Object
28
Immutability : state can’t modify or mutate directly , but
previous object can be change by creating and replacing by new
object
React can’t track prevoius state if you change the state directly
React can’t re-render the component if you change the state directly
29
[Hook] useState Working With Immutable Object
27
[Hook] useState Working With Immutable Object
31
[Hook] useState Working With Immutable Array
 don't modify or mutate directly
 Make new copy using spread (...) operator
 use setState process for update
32
[Hook] useState Working With Immutable Array
33
useState Spread Operator And Immutability Principle
Main
Object/Origi
nal DOM
Clone Object
1/Virtual
DOM1
Clone Object
3/Virtual
DOM3
Clone Object
2/Virtual DOM2
diffting
Reconciliation
34
[Hook] useState Working With Immutable Array
 The spread operator (...) in React.js is a powerful feature that simplifies working with
arrays and objects, particularly when managing component state.
 Used to expand the iterable items , The three dots syntax (...) is used
 spread operator (...) is used for cloning, merging, or passing props, arrays, or objects
in a concise and readable way to a component
 React state should be immutable . It allows you to create shallow copies of arrays and
objects, making it easier to update them without directly modifying the original data.
 It’s a JavaScript feature, not unique to React
35
[Hook] useState Working With Immutable Array
 The spread operator helps create new objects or arrays with the desired changes, leaving
the original data untouched.
 In React, it's crucial to maintain immutability of state.
 Directly modifying state can lead to unexpected behavior and hinder performance
optimizations.
Immutability:
36
[Hook] useEffect understanding arguments and uses
🔸 useEffect Has Two Arguments
1. Callback Function — () => { ... }
 This is the function that runs after the component renders.
 You perform your side effects here — like calling an API,
setting up intervals, adding event listeners, etc.
useEffect(() => {
console.log("Component mounted");
}, []);
📍 Only runs once, like componentDidMount.
37
[Hook] useEffect understanding arguments and uses
🔸 useEffect Has Two Arguments
2. Dependency Array — [dep1, dep2, ...] (optional)
 This array tells React when to run the effect.
 React compares the current values with the previous ones
 If any dependency has changed, the effect runs again.
 If the array is empty ([]), the effect runs only once on mount.
 If you omit the array, the effect runs after every render.
useEffect(() => {
console.log("Count changed:");
}, [1]);
📍 Runs every time count changes.
useEffect : perform side effects in function components, like data fetching,
subscriptions, DOM manipulation, etc.
38
[Hook] useEffect understanding arguments and uses
38
[Hook] useEffect understanding arguments and uses promises style
Api Call
Do’t go next step
If previous step fails
38
[Hook] useEffect understanding arguments and uses , async await process
Api Call
Do’t go next step
If previous step fails

component-based JavaScript library in react.pptx

  • 1.
    React JS ReactJS isa component-based JavaScript library used to build dynamic and interactive user interfaces. 01
  • 2.
    React JS 02 It simplifiesthe creation of single-page applications (SPAs) with a focus on performance and maintainability.  It is developed and by Facebook & now maintained by community developer.  Uses a virtual DOM for faster updates.  Supports a declarative approach to designing UI components.  Ensures better application control with one-way data binding.
  • 3.
    What is reactcomponent ? 03  components are the building blocks of a React application  A component is essentially a reusable, self-contained piece of UI.  React allows you to break down a complex UI into smaller, manageable pieces  React offers two main types of components: functional components and class components.
  • 4.
  • 5.
    First react projectusing vite 05  Vite is a modern frontend build tool that provides a faster development experience & development server experience for modern web projects . npm create vite@latest
  • 6.
  • 7.
    Why vite ? 07 Vite is a fast, modern build tool with Hot Module Replacement features created by the founder of Vue.js Evan You ,  designed for optimized development and production workflows. Top Reasons to Use Vite ⚡ 1. Ultra-Fast Development Server  ite uses native ES modules to serve files directly to the browser.
  • 8.
    Why vite ? 08 No bundling during development = instant startup.  Changes in code are reflected almost instantly with Hot Module Replacement (HMR). ⚡ 1. Uses Rollup under the hood for efficient bundling.  Automatically splits code, removes unused code (tree-shaking), and minifies output. 📦 2. Optimized Production Build
  • 9.
    Why vite ? 09 🚀3. Out-of-the-Box Modern Features  ES6+ support, TypeScript, JSX, CSS modules, PostCSS, and more — no extra config needed.  Built-in support for .env files, dynamic imports, and asset handling. 🎯 4. Minimal Config & Easy Setup  Create a working project in seconds using: npm create vite@latest
  • 10.
    Why vite ? 10 💡5. Great DX (Developer Experience)  Cleaner error messages.  Fast feedback loop = higher productivity.  Plugins and integrations are simpler. 🧩 6. Framework Agnostic, But Optimized  Works great with Vue 3, React, Svelte, Lit, Solid, and even plain JavaScript.  Official templates for each framework.
  • 11.
    Why vite ? 11 🔄7. Fast Refresh & HMR  When you save a file, only the module that changed is updated in the browser.  This leads to a smoother and faster dev workflow compared to traditional bundlers. 🌍 8. Strong Community & Ecosystem  Backed by Evan You (Vue’s creator).  Active plugin ecosystem.  Popular among frontend frameworks and open source tools.
  • 12.
    Run React Project 12 npmrun dev npx vite OR For build npm run build npx vite build OR
  • 13.
    vite.config.js 13 npm run devnpx vite OR For build npm run build npx vite build OR
  • 14.
    React Project Structure 14 DistributionNode Modules Public Src main.jsx node_modules .gitignore App.jsx
  • 15.
    useRef Hook 15 built-in ReactHook that returns a mutable reference object (ref) that persists across renders Accessing and manipulating DOM elements without triggering re-renders. Persisting values across renders without causing re-renders. Storing previous state values to compare changes between renders Optimizing performance by avoiding unnecessary state updates
  • 16.
  • 17.
  • 18.
    useRef Hook WorkingWith Attribute 18
  • 19.
    useRef Working WithInput Element 19
  • 20.
    [Hook] useRef WorkingWith CSS Class 20
  • 21.
    [Hook] useRef WorkingWith Persisted Mutable Property 21 The value of mutable property is only updated component is not re-rendered
  • 22.
    [Hook] useRef CachingExpensive Computation 22 useRef holds a persistent value that survives across renders but doesn’t cause re-renders when updated When can use it  When you need to re-use result multiple times without re-rendering  Cache expensive computations  Store previous values  Avoid recalculating something unnecessarily  Preventing reinitialization of complex objects Where can use it  For API Calling  Avoiding duplicate form submissions
  • 23.
    [Hook] useRef CachingExpensive Computation 23
  • 24.
    If state changeoccure then re-render the component 24 The React useState Hook allows us to track state in a function component. State generally refers to data or properties that need to be tracking in an application When to Use useState  We need a simple state management solution.  We component has state that changes over time.  The state does not require complex updates or dependencies. [Hook] useState Understading Inside
  • 25.
    25 [Hook] useState UnderstadingInside State Holds all data view
  • 26.
  • 27.
  • 28.
    [Hook] useState WorkingWith Immutable Object 28 Immutability : state can’t modify or mutate directly , but previous object can be change by creating and replacing by new object React can’t track prevoius state if you change the state directly React can’t re-render the component if you change the state directly
  • 29.
    29 [Hook] useState WorkingWith Immutable Object
  • 30.
    27 [Hook] useState WorkingWith Immutable Object
  • 31.
    31 [Hook] useState WorkingWith Immutable Array  don't modify or mutate directly  Make new copy using spread (...) operator  use setState process for update
  • 32.
    32 [Hook] useState WorkingWith Immutable Array
  • 33.
    33 useState Spread OperatorAnd Immutability Principle Main Object/Origi nal DOM Clone Object 1/Virtual DOM1 Clone Object 3/Virtual DOM3 Clone Object 2/Virtual DOM2 diffting Reconciliation
  • 34.
    34 [Hook] useState WorkingWith Immutable Array  The spread operator (...) in React.js is a powerful feature that simplifies working with arrays and objects, particularly when managing component state.  Used to expand the iterable items , The three dots syntax (...) is used  spread operator (...) is used for cloning, merging, or passing props, arrays, or objects in a concise and readable way to a component  React state should be immutable . It allows you to create shallow copies of arrays and objects, making it easier to update them without directly modifying the original data.  It’s a JavaScript feature, not unique to React
  • 35.
    35 [Hook] useState WorkingWith Immutable Array  The spread operator helps create new objects or arrays with the desired changes, leaving the original data untouched.  In React, it's crucial to maintain immutability of state.  Directly modifying state can lead to unexpected behavior and hinder performance optimizations. Immutability:
  • 36.
    36 [Hook] useEffect understandingarguments and uses 🔸 useEffect Has Two Arguments 1. Callback Function — () => { ... }  This is the function that runs after the component renders.  You perform your side effects here — like calling an API, setting up intervals, adding event listeners, etc. useEffect(() => { console.log("Component mounted"); }, []); 📍 Only runs once, like componentDidMount.
  • 37.
    37 [Hook] useEffect understandingarguments and uses 🔸 useEffect Has Two Arguments 2. Dependency Array — [dep1, dep2, ...] (optional)  This array tells React when to run the effect.  React compares the current values with the previous ones  If any dependency has changed, the effect runs again.  If the array is empty ([]), the effect runs only once on mount.  If you omit the array, the effect runs after every render. useEffect(() => { console.log("Count changed:"); }, [1]); 📍 Runs every time count changes. useEffect : perform side effects in function components, like data fetching, subscriptions, DOM manipulation, etc.
  • 38.
  • 39.
    38 [Hook] useEffect understandingarguments and uses promises style Api Call Do’t go next step If previous step fails
  • 40.
    38 [Hook] useEffect understandingarguments and uses , async await process Api Call Do’t go next step If previous step fails