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

What's hot (20)

PPTX
React hooks
Ramy ElBasyouni
 
PPTX
Introduction to React JS for beginners
Varun Raj
 
PPTX
React workshop
Imran Sayed
 
PPTX
Its time to React.js
Ritesh Mehrotra
 
PDF
React js
Rajesh Kolla
 
PPTX
React js
Oswald Campesato
 
PPTX
Reactjs
Neha Sharma
 
PPTX
Introduction to spring boot
Santosh Kumar Kar
 
PPTX
Angular modules in depth
Christoffer Noring
 
PPTX
React JS - A quick introduction tutorial
Mohammed Fazuluddin
 
PDF
ReactJS presentation
Thanh Tuong
 
PDF
Angular Directives
iFour Technolab Pvt. Ltd.
 
PPTX
React state
Ducat
 
PPTX
React hooks
Assaf Gannon
 
PPTX
reactJS
Syam Santhosh
 
PPTX
React JS: A Secret Preview
valuebound
 
PDF
Introduction to Spring's Dependency Injection
Richard Paul
 
PDF
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Edureka!
 
PPTX
React js programming concept
Tariqul islam
 
React hooks
Ramy ElBasyouni
 
Introduction to React JS for beginners
Varun Raj
 
React workshop
Imran Sayed
 
Its time to React.js
Ritesh Mehrotra
 
React js
Rajesh Kolla
 
Reactjs
Neha Sharma
 
Introduction to spring boot
Santosh Kumar Kar
 
Angular modules in depth
Christoffer Noring
 
React JS - A quick introduction tutorial
Mohammed Fazuluddin
 
ReactJS presentation
Thanh Tuong
 
Angular Directives
iFour Technolab Pvt. Ltd.
 
React state
Ducat
 
React hooks
Assaf Gannon
 
reactJS
Syam Santhosh
 
React JS: A Secret Preview
valuebound
 
Introduction to Spring's Dependency Injection
Richard Paul
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Edureka!
 
React js programming concept
Tariqul islam
 

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

PDF
Important React Hooks
Knoldus Inc.
 
PDF
Understanding React hooks | Walkingtree Technologies
Walking Tree Technologies
 
PDF
React hooks Episode #1: An introduction.
ManojSatishKumar
 
PPTX
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
Karmanjay Verma
 
PPTX
Unit 2 Fundamentals of React -------.pptx
krishitajariwala72
 
PPTX
React-JS.pptx
AnmolPandita7
 
PPTX
Presentation1
Kshitiz Rimal
 
PDF
Fundamental concepts of react js
StephieJohn
 
PPT
Lesson11 more behavioural patterns
OktJona
 
PDF
100 React Interview questions 2024.pptx.pdf
codevincent624
 
PPTX
Pluginkla2019 - React Presentation
Angela Lehru
 
PPTX
React Hooks Best Practices in 2022.pptx
BOSC Tech Labs
 
PPTX
an Introduction to Redux
Amin Ashtiani
 
PPTX
Salesforce lwc development workshops session #6
Rahul Gawale
 
PDF
Getting started with react basics
Knoldus Inc.
 
PPT
Lesson10 behavioral patterns
OktJona
 
PDF
Advanced web application architecture - Talk
Matthias Noback
 
PPTX
React gsg presentation with ryan jung & elias malik
Lama K Banna
 
PDF
Getting Started with React, When You’re an Angular Developer
Fabrit Global
 
PPTX
Dyanaimcs of business and economics unit 2
jpm071712
 
Important React Hooks
Knoldus Inc.
 
Understanding React hooks | Walkingtree Technologies
Walking Tree Technologies
 
React hooks Episode #1: An introduction.
ManojSatishKumar
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
Karmanjay Verma
 
Unit 2 Fundamentals of React -------.pptx
krishitajariwala72
 
React-JS.pptx
AnmolPandita7
 
Presentation1
Kshitiz Rimal
 
Fundamental concepts of react js
StephieJohn
 
Lesson11 more behavioural patterns
OktJona
 
100 React Interview questions 2024.pptx.pdf
codevincent624
 
Pluginkla2019 - React Presentation
Angela Lehru
 
React Hooks Best Practices in 2022.pptx
BOSC Tech Labs
 
an Introduction to Redux
Amin Ashtiani
 
Salesforce lwc development workshops session #6
Rahul Gawale
 
Getting started with react basics
Knoldus Inc.
 
Lesson10 behavioral patterns
OktJona
 
Advanced web application architecture - Talk
Matthias Noback
 
React gsg presentation with ryan jung & elias malik
Lama K Banna
 
Getting Started with React, When You’re an Angular Developer
Fabrit Global
 
Dyanaimcs of business and economics unit 2
jpm071712
 
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
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 

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