SlideShare a Scribd company logo
1 of 35
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
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

More Related Content

What's hot

Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsDinesh U
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorialMohammed Fazuluddin
 
Docker 101: Introduction to Docker
Docker 101: Introduction to DockerDocker 101: Introduction to Docker
Docker 101: Introduction to DockerDocker, Inc.
 
Open infradays 2019_msa_k8s
Open infradays 2019_msa_k8sOpen infradays 2019_msa_k8s
Open infradays 2019_msa_k8sHyoungjun Kim
 
Getting started with Docker
Getting started with DockerGetting started with Docker
Getting started with DockerRavindu Fernando
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_jsMicroPyramid .
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node jsAkshay Mathur
 
WebAssembly WASM Introduction Presentation
WebAssembly WASM Introduction PresentationWebAssembly WASM Introduction Presentation
WebAssembly WASM Introduction PresentationBrad Beiermann
 
IBM WebSphere Application Server traditional and Docker
IBM WebSphere Application Server traditional and DockerIBM WebSphere Application Server traditional and Docker
IBM WebSphere Application Server traditional and DockerDavid Currie
 
React workshop presentation
React workshop presentationReact workshop presentation
React workshop presentationBojan Golubović
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Edureka!
 
Dockerfile Tutorial with Example | Creating your First Dockerfile | Docker Tr...
Dockerfile Tutorial with Example | Creating your First Dockerfile | Docker Tr...Dockerfile Tutorial with Example | Creating your First Dockerfile | Docker Tr...
Dockerfile Tutorial with Example | Creating your First Dockerfile | Docker Tr...Edureka!
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsRob O'Doherty
 
Docker Swarm for Beginner
Docker Swarm for BeginnerDocker Swarm for Beginner
Docker Swarm for BeginnerShahzad Masud
 
Initiation à Express js
Initiation à Express jsInitiation à Express js
Initiation à Express jsAbdoulaye Dieng
 
Introduction to React
Introduction to ReactIntroduction to React
Introduction to ReactRob Quick
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS Ganesh Kondal
 

What's hot (20)

Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
 
Docker 101: Introduction to Docker
Docker 101: Introduction to DockerDocker 101: Introduction to Docker
Docker 101: Introduction to Docker
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Open infradays 2019_msa_k8s
Open infradays 2019_msa_k8sOpen infradays 2019_msa_k8s
Open infradays 2019_msa_k8s
 
Getting started with Docker
Getting started with DockerGetting started with Docker
Getting started with Docker
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
WebAssembly WASM Introduction Presentation
WebAssembly WASM Introduction PresentationWebAssembly WASM Introduction Presentation
WebAssembly WASM Introduction Presentation
 
IBM WebSphere Application Server traditional and Docker
IBM WebSphere Application Server traditional and DockerIBM WebSphere Application Server traditional and Docker
IBM WebSphere Application Server traditional and Docker
 
React workshop presentation
React workshop presentationReact workshop presentation
React workshop presentation
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
Dockerfile Tutorial with Example | Creating your First Dockerfile | Docker Tr...
Dockerfile Tutorial with Example | Creating your First Dockerfile | Docker Tr...Dockerfile Tutorial with Example | Creating your First Dockerfile | Docker Tr...
Dockerfile Tutorial with Example | Creating your First Dockerfile | Docker Tr...
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Docker Swarm for Beginner
Docker Swarm for BeginnerDocker Swarm for Beginner
Docker Swarm for Beginner
 
Initiation à Express js
Initiation à Express jsInitiation à Express js
Initiation à Express js
 
Introduction to React
Introduction to ReactIntroduction to React
Introduction to React
 
Node js for beginners
Node js for beginnersNode js for beginners
Node js for beginners
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
 
Its time to React.js
Its time to React.jsIts time to React.js
Its time to React.js
 

Similar to GDSC NITS Presents Kickstart into ReactJS

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
 
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 theoryjobinThomas54
 
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 jsBOSC 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 DemasEtietop Demas
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Previewvaluebound
 
React Basic and Advance || React Basic
React Basic and Advance   || React BasicReact Basic and Advance   || React Basic
React Basic and Advance || React Basicrafaqathussainc077
 
An Overview of the React Ecosystem
An Overview of the React EcosystemAn Overview of the React Ecosystem
An Overview of the React EcosystemFITC
 
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 NativeEric 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 ReplacementZach 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 libraryjanet736113
 
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 ApplicationAndrew Rota
 
Skill practical javascript diy projects
Skill practical javascript diy projectsSkill practical javascript diy projects
Skill practical javascript diy projectsSkillPracticalEdTech
 

Similar to GDSC NITS Presents Kickstart into ReactJS (20)

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]
 
React JS .NET
React JS .NETReact JS .NET
React JS .NET
 
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
 
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
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
 
Learn react by Etietop Demas
Learn react by Etietop DemasLearn react by Etietop Demas
Learn react by Etietop Demas
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
react-slides.pptx
react-slides.pptxreact-slides.pptx
react-slides.pptx
 
React Basic and Advance || React Basic
React Basic and Advance   || React BasicReact Basic and Advance   || React Basic
React Basic and Advance || React Basic
 
An Overview of the React Ecosystem
An Overview of the React EcosystemAn Overview of the React Ecosystem
An Overview of the React Ecosystem
 
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
 
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
 
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)
 
react-slides.pdf
react-slides.pdfreact-slides.pdf
react-slides.pdf
 
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
 
Angular or React
Angular or ReactAngular or React
Angular or React
 
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
 
netbeans
netbeansnetbeans
netbeans
 
netbeans
netbeansnetbeans
netbeans
 
Skill practical javascript diy projects
Skill practical javascript diy projectsSkill practical javascript diy projects
Skill practical javascript diy projects
 

Recently uploaded

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

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
  • 17.
  • 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