SlideShare a Scribd company logo
Presented By: Saurabh Choudhary
Important 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 Hooks Overview
02 Types of Hooks
03 Built-in Hooks
04 Custom Hook
05 Examples
React Hooks Overview
What is React Hooks?
❖ Hooks are the new feature introduced in the React 16.8 version.
❖ It allows you to use state and other React features without writing a class.
❖ Hooks are the functions which "hook into" React state and lifecycle
features from function components.
❖ It does not work inside classes.
Types of 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.
useState() 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 useState 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(“ ”);
useEffect() Hook
useEffect Hook
❖ The useEffect Hook allows you to perform side effects in your
components.
❖ Some examples of side effects are : fetching data, setting up subscriptions,
adding Event Listeners etc.
❖ The useEffect hook is a function that takes two arguments , a function
that needs to be called and an array dependency, where the second
argument is optional.
❖ useEffect runs on every render.
❖ useEffect( <function>, <dependency> ).
How to implement useEffect()
Import useEffect() :-
❖ To use the useState hook, we first need to import it into our component.
import { useEffect } from “react”;
call useEffect() :-
❖ useEffect accepts two arguments
➢ The function to perform side effects
➢ And a dependency array.
function Component() {
useEffect( ()=>{ do something } , [ dependency ] )
useContext() Hook
useContext Hook
❖ React Context is a way to manage state globally.
❖ Context provides a way to pass data or state through the component tree
without having to pass props down manually through each nested
component.
Problem : State should be held by the highest parent component in the stack
that requires access to the state.
Suppose we have so many nested components, component at top and bottom requires the
access to the state. To do this without context, we have to manually pass the state as props to
each component in the tree. This is what we call prop drilling in react.
useContext Hook
Solution : The solution is to create context.
To create context
❖ Import createContext from react : import { createContext } from “react”
❖ Initialize it :
const SomeContext = createContext()
Now let’s see the same example with context.
useRef() Hook
useRef Hook
❖ The useRef hook allows you to persist value between renders.
❖ It can be used to store value that when updated does not cause a re-render.
❖ The useRef hook is used to directly access a dom element.
❖ To use the hook you must first import it from react
import { useRef } from “react”
● You can pass the initial value at the time of initialization like:
const xyz = useRef(0)
● useRef() hook only returns one item, an object called current
● so the above initialization is like doing this :
const xyz = { current : 0 }
useReducer() Hook
useReducer Hook
❖ The useReducer hook is similar to the useState hook and is generally more
preferred over useState.
❖ If you have complex state-building logic, useReducer may be useful.
❖ The useReducer hook takes two arguments :
■ A reducer function
■ and Initial State
➢ And it returns two things
■ the current state and
■ a dispatch method
How to implement useReducer Hook
1. Import it from react
import { useReducer } from “react”
2. Initialize it and pass the required two arguments
const [ state , dispatch ] = useReducer (<reducerFn> , <intitalState> )
3. Call the dispatch method when you want to update the state
dispatch( type: <actionType>, <other required argument> )
Custom Hooks
Custom Hook
❖ Hooks are actually a reusable function.
❖ So If there is a component logic that need to be shared among multiple
components , then we can extract that logic and create a custom hook that
can be used by all the required components.
❖ A custom hook start with use as prefix like we have for Built-in hooks
(useState and useEffect etc.). for Example : useFetch()
Let’s see an Example for better understanding.
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

What's hot (20)

PPTX
React Hooks
Erez Cohen
 
PPTX
React-JS Component Life-cycle Methods
ANKUSH CHAVAN
 
PDF
React new features and intro to Hooks
Soluto
 
PDF
Understanding React hooks | Walkingtree Technologies
Walking Tree Technologies
 
PDF
React hooks Episode #1: An introduction.
ManojSatishKumar
 
PDF
Workshop 21: React Router
Visual Engineering
 
PDF
React js use contexts and useContext hook
Piyush Jamwal
 
PDF
react redux.pdf
Knoldus Inc.
 
PDF
Introduction to Redux
Ignacio Martín
 
PPTX
React workshop
Imran Sayed
 
PDF
Introduction to React JS
Bethmi Gunasekara
 
PPTX
Its time to React.js
Ritesh Mehrotra
 
PDF
ReactJS presentation
Thanh Tuong
 
PPTX
What is component in reactjs
manojbkalla
 
PDF
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
Edureka!
 
PPTX
React js programming concept
Tariqul islam
 
PDF
Lets make a better react form
Yao Nien Chung
 
PPTX
React Hooks
Joao Marins
 
PPTX
React + Redux Introduction
Nikolaus Graf
 
PPTX
Introduction to react_js
MicroPyramid .
 
React Hooks
Erez Cohen
 
React-JS Component Life-cycle Methods
ANKUSH CHAVAN
 
React new features and intro to Hooks
Soluto
 
Understanding React hooks | Walkingtree Technologies
Walking Tree Technologies
 
React hooks Episode #1: An introduction.
ManojSatishKumar
 
Workshop 21: React Router
Visual Engineering
 
React js use contexts and useContext hook
Piyush Jamwal
 
react redux.pdf
Knoldus Inc.
 
Introduction to Redux
Ignacio Martín
 
React workshop
Imran Sayed
 
Introduction to React JS
Bethmi Gunasekara
 
Its time to React.js
Ritesh Mehrotra
 
ReactJS presentation
Thanh Tuong
 
What is component in reactjs
manojbkalla
 
React Components Lifecycle | React Tutorial for Beginners | ReactJS Training ...
Edureka!
 
React js programming concept
Tariqul islam
 
Lets make a better react form
Yao Nien Chung
 
React Hooks
Joao Marins
 
React + Redux Introduction
Nikolaus Graf
 
Introduction to react_js
MicroPyramid .
 

Similar to Important React Hooks (20)

PDF
How to build a react native app with the help of react native hooks
Katy Slemon
 
PDF
React state management and side-effects – A Review of Hooks
IRJET Journal
 
PDF
React – Let’s “Hook” up
InnovationM
 
PPTX
Green Custard Friday Talk 21: React Hooks
Green Custard
 
PDF
How do we use hooks
Jim Liu
 
PPTX
React API and Hooksfjhfhjfjhfhjfjfjhfjhf
DharnaAhuja1
 
PPTX
The new React
Maurice De Beijer [MVP]
 
PPTX
GDSC NITS Presents Kickstart into ReactJS
Pratik Majumdar
 
PDF
Road to react hooks
Younes (omar) Meliani
 
PDF
React hooks beyond hype
Magdiel Duarte
 
PDF
React.js hooks feb 23rd meetup
Jaikant Kumaran
 
PDF
Materi Modern React Redux Power Point.pdf
exiabreak
 
PDF
100 React Interview questions 2024.pptx.pdf
codevincent624
 
PDF
Hello, React Hooks!
Heejong Ahn
 
PPTX
React Hooks Best Practices in 2022.pptx
BOSC Tech Labs
 
PDF
Plain react, hooks and/or Redux ?
Jörn Dinkla
 
PDF
Full Stack React Workshop [CSSC x GDSC]
GDSC UofT Mississauga
 
PPTX
Will React Hooks replace Redux?
Trivikram Kamat
 
PDF
React Hooks: Enhancing Functional Components with useState, useEffect, and Cu...
Akshat Pegwar
 
PDF
React Back to the Future
500Tech
 
How to build a react native app with the help of react native hooks
Katy Slemon
 
React state management and side-effects – A Review of Hooks
IRJET Journal
 
React – Let’s “Hook” up
InnovationM
 
Green Custard Friday Talk 21: React Hooks
Green Custard
 
How do we use hooks
Jim Liu
 
React API and Hooksfjhfhjfjhfhjfjfjhfjhf
DharnaAhuja1
 
The new React
Maurice De Beijer [MVP]
 
GDSC NITS Presents Kickstart into ReactJS
Pratik Majumdar
 
Road to react hooks
Younes (omar) Meliani
 
React hooks beyond hype
Magdiel Duarte
 
React.js hooks feb 23rd meetup
Jaikant Kumaran
 
Materi Modern React Redux Power Point.pdf
exiabreak
 
100 React Interview questions 2024.pptx.pdf
codevincent624
 
Hello, React Hooks!
Heejong Ahn
 
React Hooks Best Practices in 2022.pptx
BOSC Tech Labs
 
Plain react, hooks and/or Redux ?
Jörn Dinkla
 
Full Stack React Workshop [CSSC x GDSC]
GDSC UofT Mississauga
 
Will React Hooks replace Redux?
Trivikram Kamat
 
React Hooks: Enhancing Functional Components with useState, useEffect, and Cu...
Akshat Pegwar
 
React Back to the Future
500Tech
 
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.
 
Ad

Recently uploaded (20)

PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Complete Network Protection with Real-Time Security
L4RGINDIA
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Complete Network Protection with Real-Time Security
L4RGINDIA
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 

Important React Hooks

  • 1. Presented By: Saurabh Choudhary Important 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 Hooks Overview 02 Types of Hooks 03 Built-in Hooks 04 Custom Hook 05 Examples
  • 5. What is React Hooks? ❖ Hooks are the new feature introduced in the React 16.8 version. ❖ It allows you to use state and other React features without writing a class. ❖ Hooks are the functions which "hook into" React state and lifecycle features from function components. ❖ It does not work inside classes.
  • 7. 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.
  • 9. 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 useState 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.
  • 10. 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(“ ”);
  • 12. useEffect Hook ❖ The useEffect Hook allows you to perform side effects in your components. ❖ Some examples of side effects are : fetching data, setting up subscriptions, adding Event Listeners etc. ❖ The useEffect hook is a function that takes two arguments , a function that needs to be called and an array dependency, where the second argument is optional. ❖ useEffect runs on every render. ❖ useEffect( <function>, <dependency> ).
  • 13. How to implement useEffect() Import useEffect() :- ❖ To use the useState hook, we first need to import it into our component. import { useEffect } from “react”; call useEffect() :- ❖ useEffect accepts two arguments ➢ The function to perform side effects ➢ And a dependency array. function Component() { useEffect( ()=>{ do something } , [ dependency ] )
  • 15. useContext Hook ❖ React Context is a way to manage state globally. ❖ Context provides a way to pass data or state through the component tree without having to pass props down manually through each nested component. Problem : State should be held by the highest parent component in the stack that requires access to the state. Suppose we have so many nested components, component at top and bottom requires the access to the state. To do this without context, we have to manually pass the state as props to each component in the tree. This is what we call prop drilling in react.
  • 16. useContext Hook Solution : The solution is to create context. To create context ❖ Import createContext from react : import { createContext } from “react” ❖ Initialize it : const SomeContext = createContext() Now let’s see the same example with context.
  • 18. useRef Hook ❖ The useRef hook allows you to persist value between renders. ❖ It can be used to store value that when updated does not cause a re-render. ❖ The useRef hook is used to directly access a dom element. ❖ To use the hook you must first import it from react import { useRef } from “react” ● You can pass the initial value at the time of initialization like: const xyz = useRef(0) ● useRef() hook only returns one item, an object called current ● so the above initialization is like doing this : const xyz = { current : 0 }
  • 20. useReducer Hook ❖ The useReducer hook is similar to the useState hook and is generally more preferred over useState. ❖ If you have complex state-building logic, useReducer may be useful. ❖ The useReducer hook takes two arguments : ■ A reducer function ■ and Initial State ➢ And it returns two things ■ the current state and ■ a dispatch method
  • 21. How to implement useReducer Hook 1. Import it from react import { useReducer } from “react” 2. Initialize it and pass the required two arguments const [ state , dispatch ] = useReducer (<reducerFn> , <intitalState> ) 3. Call the dispatch method when you want to update the state dispatch( type: <actionType>, <other required argument> )
  • 23. Custom Hook ❖ Hooks are actually a reusable function. ❖ So If there is a component logic that need to be shared among multiple components , then we can extract that logic and create a custom hook that can be used by all the required components. ❖ A custom hook start with use as prefix like we have for Built-in hooks (useState and useEffect etc.). for Example : useFetch() Let’s see an Example for better understanding.
  • 24. 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
  • 25. Thank You ! Get in touch with us: Lorem Studio, Lord Building D4456, LA, USA