SlideShare a Scribd company logo
5
Most read
10
Most read
17
Most read
Presented By: Abhishek &
Saurabh Choudhary
Basics of React
Hooks
Lack of etiquette and manners is a huge turn off.
KnolX Etiquettes
Punctuality
Join the session 5 minutes prior to
the session start time. We start on
time and conclude on time!
Feedback
Make sure to submit a constructive
feedback for all sessions as it is
very helpful for the presenter.
Silent Mode
Keep your mobile devices in silent
mode, feel free to move out of
session in case you need to attend
an urgent call.
Avoid Disturbance
Avoid unwanted chit chat during
the session.
Our Agenda
01 React In Brief
02 Introduction to Hooks
03 Motivation behind Hooks
04 Types and Rules
05 Our First React Hook (useState Hook)
React In Brief
What is React ?
❖ React.js is an open-source JavaScript library that is used for building user
interfaces specifically for single-page applications.
❖ It is a component-based, front-end library responsible only for the
application’s view layer.
❖ React is not a framework that many of us think rather it is a User
Interface library that helps build beautiful and interactive UIs.
❖ React follows Declarative approach and is totally component-based
where we develop simple components and then combine them together
to build a complex UI.
Basics of React Hooks.pptx.pdf
Introduction to Hooks
What are Hooks ?
(Ques.) What is Hook in General terms ?
❖ Hooks are a new feature addition in React version 16.8
which allow you to use React features without having to
write a class
❖ Ex : State of a Component
(Ans.) a curved piece of metal, plastic, etc. that is used for
hanging or catching something
Motivation behind
Hooks
Why Hooks ?
➢ Understand how this keyword works in JavaScript
➢ Remember to bind event handlers in class components
➢ Classes don’t minify very well and make hot reloading very unreliable
Reason 1: Classes confuse both people and machines
Why Hooks ?
➢ There is no particular way to reuse stateful component logic
➢ HOC (Higher Order Component) and render props patterns do address this
problem but have to do some restructuring of components
➢ Makes the code harder to follow
➢ There is need a to share stateful logic in a better way
Reason 2: Itʼs hard to reuse stateful logic between components
Why Hooks ?
➢ Create components for complex scenarios such as data fetching and
subscribing to events
➢ Related code is not organized in one place
➢ Ex: Data fetching - In componentDidMount and componentDidUpdate
➢ Ex: Event Listeners - In componentDidMount and componentWillUnmount
➢ Because of stateful logic - Cannot break components into smaller ones
Reason 3: Complex components become hard to understand
Types and Rules of
Using Hooks
Types
➢ useState Hooks
➢ useEffect Hook
➢ useRef Hook
➢ useCallback Hook
➢ useMemo Hook
➢ useContext Hook
➢ useReducer Hook
Built-In Hooks :
Custom Hooks :
➢ You can create your own custom hooks if you have stateful logic that is needed by
multiple components in you application.
Rules
➢ Hooks are called only at the top level of a component.
➢ Do not call Hooks inside loops, conditions, or nested functions.
➢ Hooks are called only from React functional Components.
➢ Do not call Hooks from regular JavaScript functions.
There is one other way to call Hooks i.e. in your own custom Hooks
Hooks are normal JavaScript functions, but they impose some additional rules :
Let’s Implement our
First Hook
useState Hook
❖ The useState() is a hook that allows you to have state variables in
functional components.
❖ Basically useSate is the ability to encapsulate local state in a functional
component.
❖ The useSate hook is a special function that takes the initial state as an
argument and returns an array of two entries.
❖ You pass the initial state to this function and it returns a variable with the
current state value(not necessarily the initial state)and another function
to update this value.
How to implement useState()
Import useState() :-
❖ To use the useState hook, we first need to import it into our component.
import { useState } from “react”;
Initialize useState() :-
❖ useState accepts an initial state and returns two values
➢ The current state
➢ A function that updates the state.
function FavoriteColor() {
const [ color, setColor ] = useState(“ ”);
Creating an array state with useState
❖ we destructure the return value of the useState() hook to get a variable
that contains the state array and a method for updating the state.
Demo
References
To learn more about Hooks follow the below links :
https://reactjs.org/docs/hooks-intro.html
You can find Free and Paid courses here :
https://reactjs.org/community/courses.html
Thank You !
Get in touch with us:
Lorem Studio, Lord Building
D4456, LA, USA

More Related Content

PPTX
Understanding react hooks
Maulik Shah
 
PDF
Understanding react hooks
Samundra khatri
 
PPTX
React js
Alireza Akbari
 
PPTX
React JS: A Secret Preview
valuebound
 
PPTX
React web development
Rully Ramanda
 
PPTX
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
Karmanjay Verma
 
PPTX
React hooks
Assaf Gannon
 
PPTX
ReactJs
Sahana Banerjee
 
Understanding react hooks
Maulik Shah
 
Understanding react hooks
Samundra khatri
 
React js
Alireza Akbari
 
React JS: A Secret Preview
valuebound
 
React web development
Rully Ramanda
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
Karmanjay Verma
 
React hooks
Assaf Gannon
 

What's hot (20)

PPTX
Introduction to react_js
MicroPyramid .
 
PPTX
React hooks
Sadhna Rana
 
PPTX
Introduction to React JS for beginners
Varun Raj
 
PPTX
React workshop
Imran Sayed
 
PPTX
React hooks
Ramy ElBasyouni
 
PPTX
reactJS
Syam Santhosh
 
PDF
Important React Hooks
Knoldus Inc.
 
PPTX
[Final] ReactJS presentation
洪 鹏发
 
PPTX
React js
Oswald Campesato
 
PPTX
React Hooks
Erez Cohen
 
PDF
React Context API
NodeXperts
 
ODP
Introduction to ReactJS
Knoldus Inc.
 
PDF
Introduction to Redux
Ignacio Martín
 
PPTX
ReactJS presentation.pptx
DivyanshGupta922023
 
PPTX
Intro to React
Eric Westfall
 
PPTX
ReactJS
Ram Murat Sharma
 
PPTX
Modern JS with ES6
Kevin Langley Jr.
 
PPTX
React workshop presentation
Bojan Golubović
 
PDF
Introduction to React JS
Bethmi Gunasekara
 
PDF
React new features and intro to Hooks
Soluto
 
Introduction to react_js
MicroPyramid .
 
React hooks
Sadhna Rana
 
Introduction to React JS for beginners
Varun Raj
 
React workshop
Imran Sayed
 
React hooks
Ramy ElBasyouni
 
reactJS
Syam Santhosh
 
Important React Hooks
Knoldus Inc.
 
[Final] ReactJS presentation
洪 鹏发
 
React Hooks
Erez Cohen
 
React Context API
NodeXperts
 
Introduction to ReactJS
Knoldus Inc.
 
Introduction to Redux
Ignacio Martín
 
ReactJS presentation.pptx
DivyanshGupta922023
 
Intro to React
Eric Westfall
 
Modern JS with ES6
Kevin Langley Jr.
 
React workshop presentation
Bojan Golubović
 
Introduction to React JS
Bethmi Gunasekara
 
React new features and intro to Hooks
Soluto
 
Ad

Similar to Basics of React Hooks.pptx.pdf (20)

PDF
React.js hooks feb 23rd meetup
Jaikant Kumaran
 
PDF
Understanding React hooks | Walkingtree Technologies
Walking Tree Technologies
 
PPTX
React-JS.pptx
AnmolPandita7
 
PDF
React hooks beyond hype
Magdiel Duarte
 
PDF
React state management and side-effects – A Review of Hooks
IRJET Journal
 
PDF
React – Let’s “Hook” up
InnovationM
 
PDF
Hello, React Hooks!
Heejong Ahn
 
PDF
React hooks Episode #1: An introduction.
ManojSatishKumar
 
PPTX
Green Custard Friday Talk 21: React Hooks
Green Custard
 
PDF
React Hooks: Enhancing Functional Components with useState, useEffect, and Cu...
Akshat Pegwar
 
PPTX
Will React Hooks replace Redux?
Trivikram Kamat
 
PPTX
React Hooks Best Practices in 2022.pptx
BOSC Tech Labs
 
PDF
Introduction to React Hooks
Felicia O'Garro
 
PPTX
React Hooks
Joao Marins
 
PDF
Importance of Hook in Recat Js.pdf
Nishaadequateinfosof
 
PPTX
Pluginkla2019 - React Presentation
Angela Lehru
 
PPTX
Hook me UP ( React Hooks Introduction)
Carlos Mafla
 
PDF
How to build a react native app with the help of react native hooks
Katy Slemon
 
PDF
How do we use hooks
Jim Liu
 
PDF
Plain react, hooks and/or Redux ?
Jörn Dinkla
 
React.js hooks feb 23rd meetup
Jaikant Kumaran
 
Understanding React hooks | Walkingtree Technologies
Walking Tree Technologies
 
React-JS.pptx
AnmolPandita7
 
React hooks beyond hype
Magdiel Duarte
 
React state management and side-effects – A Review of Hooks
IRJET Journal
 
React – Let’s “Hook” up
InnovationM
 
Hello, React Hooks!
Heejong Ahn
 
React hooks Episode #1: An introduction.
ManojSatishKumar
 
Green Custard Friday Talk 21: React Hooks
Green Custard
 
React Hooks: Enhancing Functional Components with useState, useEffect, and Cu...
Akshat Pegwar
 
Will React Hooks replace Redux?
Trivikram Kamat
 
React Hooks Best Practices in 2022.pptx
BOSC Tech Labs
 
Introduction to React Hooks
Felicia O'Garro
 
React Hooks
Joao Marins
 
Importance of Hook in Recat Js.pdf
Nishaadequateinfosof
 
Pluginkla2019 - React Presentation
Angela Lehru
 
Hook me UP ( React Hooks Introduction)
Carlos Mafla
 
How to build a react native app with the help of react native hooks
Katy Slemon
 
How do we use hooks
Jim Liu
 
Plain react, hooks and/or Redux ?
Jörn Dinkla
 
Ad

More from Knoldus Inc. (20)

PPTX
Angular Hydration Presentation (FrontEnd)
Knoldus Inc.
 
PPTX
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Knoldus Inc.
 
PPTX
Self-Healing Test Automation Framework - Healenium
Knoldus Inc.
 
PPTX
Kanban Metrics Presentation (Project Management)
Knoldus Inc.
 
PPTX
Java 17 features and implementation.pptx
Knoldus Inc.
 
PPTX
Chaos Mesh Introducing Chaos in Kubernetes
Knoldus Inc.
 
PPTX
GraalVM - A Step Ahead of JVM Presentation
Knoldus Inc.
 
PPTX
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
PPTX
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
PPTX
DAPR - Distributed Application Runtime Presentation
Knoldus Inc.
 
PPTX
Introduction to Azure Virtual WAN Presentation
Knoldus Inc.
 
PPTX
Introduction to Argo Rollouts Presentation
Knoldus Inc.
 
PPTX
Intro to Azure Container App Presentation
Knoldus Inc.
 
PPTX
Insights Unveiled Test Reporting and Observability Excellence
Knoldus Inc.
 
PPTX
Introduction to Splunk Presentation (DevOps)
Knoldus Inc.
 
PPTX
Code Camp - Data Profiling and Quality Analysis Framework
Knoldus Inc.
 
PPTX
AWS: Messaging Services in AWS Presentation
Knoldus Inc.
 
PPTX
Amazon Cognito: A Primer on Authentication and Authorization
Knoldus Inc.
 
PPTX
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Knoldus Inc.
 
PPTX
Managing State & HTTP Requests In Ionic.
Knoldus Inc.
 
Angular Hydration Presentation (FrontEnd)
Knoldus Inc.
 
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Knoldus Inc.
 
Self-Healing Test Automation Framework - Healenium
Knoldus Inc.
 
Kanban Metrics Presentation (Project Management)
Knoldus Inc.
 
Java 17 features and implementation.pptx
Knoldus Inc.
 
Chaos Mesh Introducing Chaos in Kubernetes
Knoldus Inc.
 
GraalVM - A Step Ahead of JVM Presentation
Knoldus Inc.
 
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
DAPR - Distributed Application Runtime Presentation
Knoldus Inc.
 
Introduction to Azure Virtual WAN Presentation
Knoldus Inc.
 
Introduction to Argo Rollouts Presentation
Knoldus Inc.
 
Intro to Azure Container App Presentation
Knoldus Inc.
 
Insights Unveiled Test Reporting and Observability Excellence
Knoldus Inc.
 
Introduction to Splunk Presentation (DevOps)
Knoldus Inc.
 
Code Camp - Data Profiling and Quality Analysis Framework
Knoldus Inc.
 
AWS: Messaging Services in AWS Presentation
Knoldus Inc.
 
Amazon Cognito: A Primer on Authentication and Authorization
Knoldus Inc.
 
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Knoldus Inc.
 
Managing State & HTTP Requests In Ionic.
Knoldus Inc.
 

Recently uploaded (20)

PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Beyond Automation: The Role of IoT Sensor Integration in Next-Gen Industries
Rejig Digital
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PPT
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Beyond Automation: The Role of IoT Sensor Integration in Next-Gen Industries
Rejig Digital
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 

Basics of React Hooks.pptx.pdf

  • 1. Presented By: Abhishek & Saurabh Choudhary Basics of React Hooks
  • 2. Lack of etiquette and manners is a huge turn off. KnolX Etiquettes Punctuality Join the session 5 minutes prior to the session start time. We start on time and conclude on time! Feedback Make sure to submit a constructive feedback for all sessions as it is very helpful for the presenter. Silent Mode Keep your mobile devices in silent mode, feel free to move out of session in case you need to attend an urgent call. Avoid Disturbance Avoid unwanted chit chat during the session.
  • 3. Our Agenda 01 React In Brief 02 Introduction to Hooks 03 Motivation behind Hooks 04 Types and Rules 05 Our First React Hook (useState Hook)
  • 5. What is React ? ❖ React.js is an open-source JavaScript library that is used for building user interfaces specifically for single-page applications. ❖ It is a component-based, front-end library responsible only for the application’s view layer. ❖ React is not a framework that many of us think rather it is a User Interface library that helps build beautiful and interactive UIs. ❖ React follows Declarative approach and is totally component-based where we develop simple components and then combine them together to build a complex UI.
  • 8. What are Hooks ? (Ques.) What is Hook in General terms ? ❖ Hooks are a new feature addition in React version 16.8 which allow you to use React features without having to write a class ❖ Ex : State of a Component (Ans.) a curved piece of metal, plastic, etc. that is used for hanging or catching something
  • 10. Why Hooks ? ➢ Understand how this keyword works in JavaScript ➢ Remember to bind event handlers in class components ➢ Classes don’t minify very well and make hot reloading very unreliable Reason 1: Classes confuse both people and machines
  • 11. Why Hooks ? ➢ There is no particular way to reuse stateful component logic ➢ HOC (Higher Order Component) and render props patterns do address this problem but have to do some restructuring of components ➢ Makes the code harder to follow ➢ There is need a to share stateful logic in a better way Reason 2: Itʼs hard to reuse stateful logic between components
  • 12. Why Hooks ? ➢ Create components for complex scenarios such as data fetching and subscribing to events ➢ Related code is not organized in one place ➢ Ex: Data fetching - In componentDidMount and componentDidUpdate ➢ Ex: Event Listeners - In componentDidMount and componentWillUnmount ➢ Because of stateful logic - Cannot break components into smaller ones Reason 3: Complex components become hard to understand
  • 13. Types and Rules of Using Hooks
  • 14. Types ➢ useState Hooks ➢ useEffect Hook ➢ useRef Hook ➢ useCallback Hook ➢ useMemo Hook ➢ useContext Hook ➢ useReducer Hook Built-In Hooks : Custom Hooks : ➢ You can create your own custom hooks if you have stateful logic that is needed by multiple components in you application.
  • 15. Rules ➢ Hooks are called only at the top level of a component. ➢ Do not call Hooks inside loops, conditions, or nested functions. ➢ Hooks are called only from React functional Components. ➢ Do not call Hooks from regular JavaScript functions. There is one other way to call Hooks i.e. in your own custom Hooks Hooks are normal JavaScript functions, but they impose some additional rules :
  • 17. useState Hook ❖ The useState() is a hook that allows you to have state variables in functional components. ❖ Basically useSate is the ability to encapsulate local state in a functional component. ❖ The useSate hook is a special function that takes the initial state as an argument and returns an array of two entries. ❖ You pass the initial state to this function and it returns a variable with the current state value(not necessarily the initial state)and another function to update this value.
  • 18. How to implement useState() Import useState() :- ❖ To use the useState hook, we first need to import it into our component. import { useState } from “react”; Initialize useState() :- ❖ useState accepts an initial state and returns two values ➢ The current state ➢ A function that updates the state. function FavoriteColor() { const [ color, setColor ] = useState(“ ”);
  • 19. Creating an array state with useState ❖ we destructure the return value of the useState() hook to get a variable that contains the state array and a method for updating the state.
  • 20. Demo
  • 21. References To learn more about Hooks follow the below links : https://reactjs.org/docs/hooks-intro.html You can find Free and Paid courses here : https://reactjs.org/community/courses.html
  • 22. Thank You ! Get in touch with us: Lorem Studio, Lord Building D4456, LA, USA