SlideShare a Scribd company logo
Kickstart to ReactJS
GDSC NIT Silchar
React is a JavaScript library for building user interfaces.
What is ReactJS..??
Is it worth to learn?
Market needs React Devs !!
So why not become one..?
In today’s Session
• React Setup
• Components and Its types
• What’s JSX..?
• Using JS in HTML
• Importing CSS and CSS Modules
• Props
• Hooks!!
• UseState
Setting Up React
Directory Structure
What are React Components..??
Components are independent and reusable chunk of code. They serve the
same purpose as JavaScript functions, but work in isolation and return
HTML.
Stateful Class
Components
Stateless Functional
Components
React
Components
Class v/s Functional Components
Which is better..?
HTML in JS..??
JSX!!
● JSX stands for JavaScript XML.
● Syntax extension of JavaScript. It allows us to directly write HTML in React.
● Compiled using Babel.
● De-reference variables using {}.
● CSS Modules let you use the same CSS class name in different files without
worrying about naming clashes.
● Locally Scoped
CSS Modules
React Hooks
Hooks allow us to "hook" into React features such as state and lifecycle
methods.
There are 3 rules for hooks:
● Hooks can only be called inside React function components.
● Hooks can only be called at the top level of a component.
● Hooks cannot be conditional
The All Round Updater!!
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.
useState()
Kickstart to ReactJS
Pratik Majumdar
@codadept
Day 2 | Part 2
SPA v/s Non-SPA
ReactJS for SPA
● Non-Single Page Application
○ When you go to a new page a request is sent to
the server, the page is retrieved and rendered.
● Single Page Application
○ Loads only single HTML Document file and then
loads different pages via Javascript API and
Logics.
v6
• Pages are created from Components in React
• React Router intercepts any request for any particular page and renders
the needful component accordingly
• Programmatic rendering of Pages
React Router
React Router continued . . .
still v6
• index.html - The single HTML file where all of our components are
rendered programmatically
• When you go to /movies then index.html will be rewritten with
component’s logic
GDSC NITS Presents Kickstart into ReactJS
Installing
react-router-dom
pnpm install react-router-dom@6
Let’s code
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import { BrowserRouter } from "react-router-dom";
ReactDOM.render(
<BrowserRouter>
<App />
</BrowserRouter>,
document.getElementById("root")
);
Data Fetching from API
GET: /api/v1/movies
● Front-end applications need to fetch data from
APIs
● Handle different states of the app before, during
and after fetching.
fetching...
• The states to be managed
○ loading
○ data
○ error
Managing states
Different State Management Tools
More hooks?
Redux
Context
API
useState()
App Wide Local
Creating States
states
const [data, setData] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
Can use external libraries like, axios too.
Fetching
fetch(url, {
method: "GET" // default, so we can ignore
})
We will use a free online mock API, called JSONPlaceholder to fetch data
https://jsonplaceholder.typicode.com/
Where to write your fetch()?
useEffect() hook?
● fetch() causes side-effects
○ Side-effect, are actions performed with the outside world
○ Unpredictable. For eg. in fetch() result in
■ success
■ Error
● For side-effects: useEffect()
useEffect(() => {
// data fetching here
}, []);
Let’s code
useEffect(() => {
async function getData() {
const response = await fetch(
`https://jsonplaceholder.typicode.com/posts?_limit=10`
)
let actualData = await response.json();
console.log(actualData)
}
getData()
}, [])
Context API
Application-wide state management
● Effectively produce global variables that can be
passed around
● Much better alternative to prop drilling or
passing via props
• Global State (store): The state which needs to be managed application-
wide.
• Producer: Component that provides the state to its children.
• Consumer: Component that consumes and uses the state.
Context API continued . . .
Terminologies
Prop drilling
username
username
username
Using Context API
Each of the Component those who want to Consume
the value (subscriber) can access the username value
without requiring to pass it via props.
Let’s code
function Profile() {
const userDetails =
React.useContext(UserContext);
const setUserDetails =
useContext(UserDispatchContext);
return <h1> {userDetails.username} </h1>;
}
const [userDetails, setUserDetails] =
useState({
username: "John Doe"
});
Context API Demo Code
Resources
RTFM
• React Router
○ https://reactrouter.com/en/main
• Context API
○ https://reactjs.org/docs/context.html
○ https://www.freecodecamp.org/news/react-
context-for-beginners/
Future Read
• React Query
○ https://react-query-v3.tanstack.com/
• React Redux
○ https://react-redux.js.org/
○ https://dev.to/ruppysuppy/redux-vs-context-
api-when-to-use-them-4k3p
• NextJS
○ https://nextjs.org/docs/getting-started
Thank you
Ad

More Related Content

What's hot (20)

ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
DivyanshGupta922023
 
React js
React jsReact js
React js
Rajesh Kolla
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
Thanh Tuong
 
안드로이드 윈도우 마스터 되기
안드로이드 윈도우 마스터 되기안드로이드 윈도우 마스터 되기
안드로이드 윈도우 마스터 되기
Myungwook Ahn
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
Varun Raj
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
Nikolaus Graf
 
React workshop presentation
React workshop presentationReact workshop presentation
React workshop presentation
Bojan Golubović
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
MicroPyramid .
 
React js
React jsReact js
React js
Jai Santhosh
 
Reactjs
Reactjs Reactjs
Reactjs
Neha Sharma
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
GDSC UofT Mississauga
 
Best Practice-React
Best Practice-ReactBest Practice-React
Best Practice-React
Yang Yang
 
React for Beginners
React for BeginnersReact for Beginners
React for Beginners
Derek Willian Stavis
 
Intro to React
Intro to ReactIntro to React
Intro to React
Eric Westfall
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
Emanuele DelBono
 
React hooks
React hooksReact hooks
React hooks
Sadhna Rana
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
Javier Lafora Rey
 
React JS part 1
React JS part 1React JS part 1
React JS part 1
Diluka Wittahachchige
 
WEB DEVELOPMENT USING REACT JS
 WEB DEVELOPMENT USING REACT JS WEB DEVELOPMENT USING REACT JS
WEB DEVELOPMENT USING REACT JS
MuthuKumaran Singaravelu
 
ReactJS
ReactJSReactJS
ReactJS
Hiten Pratap Singh
 

Similar to GDSC NITS Presents Kickstart into ReactJS (20)

NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfgNEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
zmulani8
 
React JS .NET
React JS .NETReact JS .NET
React JS .NET
Jennifer Estrada
 
Reactjs notes.pptx for web development- tutorial and theory
Reactjs  notes.pptx for web development- tutorial and theoryReactjs  notes.pptx for web development- tutorial and theory
Reactjs notes.pptx for web development- tutorial and theory
jobinThomas54
 
How to create components in react js
How to create components in react jsHow to create components in react js
How to create components in react js
BOSC Tech Labs
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
Nitin Tyagi
 
Learn react by Etietop Demas
Learn react by Etietop DemasLearn react by Etietop Demas
Learn react by Etietop Demas
Etietop Demas
 
ReactJS - frontend web developing reactjs
ReactJS - frontend web developing reactjsReactJS - frontend web developing reactjs
ReactJS - frontend web developing reactjs
ducpvcontact
 
react-slides.pptx
react-slides.pptxreact-slides.pptx
react-slides.pptx
DayNightGaMiNg
 
React Basic and Advance || React Basic
React Basic and Advance   || React BasicReact Basic and Advance   || React Basic
React Basic and Advance || React Basic
rafaqathussainc077
 
Full Stack_Reac web Development and Application
Full Stack_Reac web Development and ApplicationFull Stack_Reac web Development and Application
Full Stack_Reac web Development and Application
Jeyarajs7
 
An Overview of the React Ecosystem
An Overview of the React EcosystemAn Overview of the React Ecosystem
An Overview of the React Ecosystem
FITC
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
Eric Deng
 
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer ReplacementMidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
Zach Lendon
 
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Zach Lendon
 
react-slides.pdf gives information about react library
react-slides.pdf gives information about react libraryreact-slides.pdf gives information about react library
react-slides.pdf gives information about react library
janet736113
 
react-slides.pdf
react-slides.pdfreact-slides.pdf
react-slides.pdf
DayNightGaMiNg
 
Angular or React
Angular or ReactAngular or React
Angular or React
Orkhan Gasimov
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
Andrew Rota
 
netbeans
netbeansnetbeans
netbeans
tutorialsruby
 
netbeans
netbeansnetbeans
netbeans
tutorialsruby
 
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfgNEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
zmulani8
 
Reactjs notes.pptx for web development- tutorial and theory
Reactjs  notes.pptx for web development- tutorial and theoryReactjs  notes.pptx for web development- tutorial and theory
Reactjs notes.pptx for web development- tutorial and theory
jobinThomas54
 
How to create components in react js
How to create components in react jsHow to create components in react js
How to create components in react js
BOSC Tech Labs
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
Nitin Tyagi
 
Learn react by Etietop Demas
Learn react by Etietop DemasLearn react by Etietop Demas
Learn react by Etietop Demas
Etietop Demas
 
ReactJS - frontend web developing reactjs
ReactJS - frontend web developing reactjsReactJS - frontend web developing reactjs
ReactJS - frontend web developing reactjs
ducpvcontact
 
React Basic and Advance || React Basic
React Basic and Advance   || React BasicReact Basic and Advance   || React Basic
React Basic and Advance || React Basic
rafaqathussainc077
 
Full Stack_Reac web Development and Application
Full Stack_Reac web Development and ApplicationFull Stack_Reac web Development and Application
Full Stack_Reac web Development and Application
Jeyarajs7
 
An Overview of the React Ecosystem
An Overview of the React EcosystemAn Overview of the React Ecosystem
An Overview of the React Ecosystem
FITC
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
Eric Deng
 
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer ReplacementMidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
Zach Lendon
 
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Zach Lendon
 
react-slides.pdf gives information about react library
react-slides.pdf gives information about react libraryreact-slides.pdf gives information about react library
react-slides.pdf gives information about react library
janet736113
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
Andrew Rota
 
Ad

Recently uploaded (20)

TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Ad

GDSC NITS Presents Kickstart into ReactJS

  • 2. React is a JavaScript library for building user interfaces. What is ReactJS..?? Is it worth to learn?
  • 3. Market needs React Devs !! So why not become one..?
  • 4. In today’s Session • React Setup • Components and Its types • What’s JSX..? • Using JS in HTML • Importing CSS and CSS Modules • Props • Hooks!! • UseState
  • 7. What are React Components..?? Components are independent and reusable chunk of code. They serve the same purpose as JavaScript functions, but work in isolation and return HTML. Stateful Class Components Stateless Functional Components React Components
  • 8. Class v/s Functional Components Which is better..?
  • 9. HTML in JS..?? JSX!! ● JSX stands for JavaScript XML. ● Syntax extension of JavaScript. It allows us to directly write HTML in React. ● Compiled using Babel. ● De-reference variables using {}.
  • 10. ● CSS Modules let you use the same CSS class name in different files without worrying about naming clashes. ● Locally Scoped CSS Modules
  • 11. React Hooks Hooks allow us to "hook" into React features such as state and lifecycle methods. There are 3 rules for hooks: ● Hooks can only be called inside React function components. ● Hooks can only be called at the top level of a component. ● Hooks cannot be conditional
  • 12. The All Round Updater!! 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. useState()
  • 13. Kickstart to ReactJS Pratik Majumdar @codadept Day 2 | Part 2
  • 14. SPA v/s Non-SPA ReactJS for SPA ● Non-Single Page Application ○ When you go to a new page a request is sent to the server, the page is retrieved and rendered. ● Single Page Application ○ Loads only single HTML Document file and then loads different pages via Javascript API and Logics.
  • 15. v6 • Pages are created from Components in React • React Router intercepts any request for any particular page and renders the needful component accordingly • Programmatic rendering of Pages React Router
  • 16. React Router continued . . . still v6 • index.html - The single HTML file where all of our components are rendered programmatically • When you go to /movies then index.html will be rewritten with component’s logic
  • 19. Let’s code import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; import App from './App'; import { BrowserRouter } from "react-router-dom"; ReactDOM.render( <BrowserRouter> <App /> </BrowserRouter>, document.getElementById("root") );
  • 20. Data Fetching from API GET: /api/v1/movies ● Front-end applications need to fetch data from APIs ● Handle different states of the app before, during and after fetching.
  • 21. fetching... • The states to be managed ○ loading ○ data ○ error Managing states
  • 22. Different State Management Tools More hooks? Redux Context API useState() App Wide Local
  • 23. Creating States states const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null);
  • 24. Can use external libraries like, axios too. Fetching fetch(url, { method: "GET" // default, so we can ignore }) We will use a free online mock API, called JSONPlaceholder to fetch data https://jsonplaceholder.typicode.com/
  • 25. Where to write your fetch()? useEffect() hook? ● fetch() causes side-effects ○ Side-effect, are actions performed with the outside world ○ Unpredictable. For eg. in fetch() result in ■ success ■ Error ● For side-effects: useEffect() useEffect(() => { // data fetching here }, []);
  • 26. Let’s code useEffect(() => { async function getData() { const response = await fetch( `https://jsonplaceholder.typicode.com/posts?_limit=10` ) let actualData = await response.json(); console.log(actualData) } getData() }, [])
  • 27. Context API Application-wide state management ● Effectively produce global variables that can be passed around ● Much better alternative to prop drilling or passing via props
  • 28. • Global State (store): The state which needs to be managed application- wide. • Producer: Component that provides the state to its children. • Consumer: Component that consumes and uses the state. Context API continued . . . Terminologies
  • 30. Using Context API Each of the Component those who want to Consume the value (subscriber) can access the username value without requiring to pass it via props.
  • 31. Let’s code function Profile() { const userDetails = React.useContext(UserContext); const setUserDetails = useContext(UserDispatchContext); return <h1> {userDetails.username} </h1>; } const [userDetails, setUserDetails] = useState({ username: "John Doe" });
  • 33. Resources RTFM • React Router ○ https://reactrouter.com/en/main • Context API ○ https://reactjs.org/docs/context.html ○ https://www.freecodecamp.org/news/react- context-for-beginners/
  • 34. Future Read • React Query ○ https://react-query-v3.tanstack.com/ • React Redux ○ https://react-redux.js.org/ ○ https://dev.to/ruppysuppy/redux-vs-context- api-when-to-use-them-4k3p • NextJS ○ https://nextjs.org/docs/getting-started