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

More Related Content

PPTX
Introduction to React
PPTX
PPTX
Reactjs
PPTX
React JS - A quick introduction tutorial
PDF
Full Stack React Workshop [CSSC x GDSC]
PPTX
Angularjs PPT
PPTX
PPTX
reactJS
Introduction to React
Reactjs
React JS - A quick introduction tutorial
Full Stack React Workshop [CSSC x GDSC]
Angularjs PPT
reactJS

What's hot (20)

PPTX
React JS: A Secret Preview
PDF
React js
PPTX
Design Beautiful REST + JSON APIs
PDF
Angular vs React vs Vue | Javascript Frameworks Comparison | Which One You Sh...
PPTX
React workshop presentation
PPTX
Introduction to React JS for beginners | Namespace IT
PDF
Developing Faster with Swagger
PDF
Angular
PDF
ReactJS presentation
PPTX
Angular interview questions
PPTX
ReactJS presentation.pptx
PPTX
Introducing Swagger
PDF
PDF
React - Introdução
PPT
Word Dictionary - Software Development Project 1
PDF
Session7-XSS & CSRF
PDF
PPTX
React hooks
PPTX
Progressive Web App
PDF
Service Worker Presentation
React JS: A Secret Preview
React js
Design Beautiful REST + JSON APIs
Angular vs React vs Vue | Javascript Frameworks Comparison | Which One You Sh...
React workshop presentation
Introduction to React JS for beginners | Namespace IT
Developing Faster with Swagger
Angular
ReactJS presentation
Angular interview questions
ReactJS presentation.pptx
Introducing Swagger
React - Introdução
Word Dictionary - Software Development Project 1
Session7-XSS & CSRF
React hooks
Progressive Web App
Service Worker Presentation
Ad

Similar to GDSC NITS Presents Kickstart into ReactJS (20)

PPTX
unit 2 React js.pptxdgdgdgdgdgdgdgdgdsgdgdg
PPTX
React API and Hooksfjhfhjfjhfhjfjfjhfjhf
PDF
react hook and wesite making structure ppt
PPTX
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
PDF
100 React Interview questions 2024.pptx.pdf
PDF
Understanding react hooks
PPTX
Presentation on "An Introduction to ReactJS"
PPTX
React Workshop: Core concepts of react
PPTX
2.React tttttttttttttttttttttttttttttttt
PPTX
React workshop
PPTX
reacts js with basic details Detailed_ReactJS_Presentation.pptx
PPTX
PDF
0900 learning-react
PDF
react.pdf
PDF
Learning React js Learn React JS From Scratch with Hands On Projects 2nd Edit...
PPTX
React - Start learning today
PPSX
REACTJS1.ppsx
PDF
a-detailed-guide-everything-you-need-to-know-about-reactjs.pdf
PDF
React Interview Question & Answers PDF By ScholarHat
PPTX
This Is the ppt of How the react js work in the dealy life
unit 2 React js.pptxdgdgdgdgdgdgdgdgdsgdgdg
React API and Hooksfjhfhjfjhfhjfjfjhfjhf
react hook and wesite making structure ppt
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
100 React Interview questions 2024.pptx.pdf
Understanding react hooks
Presentation on "An Introduction to ReactJS"
React Workshop: Core concepts of react
2.React tttttttttttttttttttttttttttttttt
React workshop
reacts js with basic details Detailed_ReactJS_Presentation.pptx
0900 learning-react
react.pdf
Learning React js Learn React JS From Scratch with Hands On Projects 2nd Edit...
React - Start learning today
REACTJS1.ppsx
a-detailed-guide-everything-you-need-to-know-about-reactjs.pdf
React Interview Question & Answers PDF By ScholarHat
This Is the ppt of How the react js work in the dealy life
Ad

Recently uploaded (20)

PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Approach and Philosophy of On baking technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
KodekX | Application Modernization Development
PDF
Spectral efficient network and resource selection model in 5G networks
Mobile App Security Testing_ A Comprehensive Guide.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Review of recent advances in non-invasive hemoglobin estimation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Network Security Unit 5.pdf for BCA BBA.
Building Integrated photovoltaic BIPV_UPV.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Approach and Philosophy of On baking technology
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation_ Review paper, used for researhc scholars
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
KodekX | Application Modernization Development
Spectral efficient network and resource selection model in 5G networks

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