SlideShare a Scribd company logo
🙋 An introduction.
< MSK Tutorials />
React hooks
Manoj Satish Kumar
Web developer Tutorials
MSK
Episode #1
< MSK Tutorials />
The bar for adding a new primitive
to React is extremely high.
😲
What are hooks ?
• Hooks are functions that let you
“hook into” React state and lifecycle
features from function components.
• Hooks don’t work inside classes — they
let you use React without classes.
• Hooks will reduce your component size
significantly and have many other
benefits.
🤔
They are created for a reason. A big reason.
< MSK Tutorials />
3 rules of using hooks.
• Only call Hooks at the top level. Don’t call
Hooks inside loops, conditions, or nested
functions.
• Only call Hooks from React function
components. Don’t call Hooks from regular
JavaScript functions.
• There is just one other valid place to call
hooks - your own custom hooks.

😇
Because rules are meant to be followed. Not broken.
< MSK Tutorials />
< MSK Tutorials />
Feeling lazy to remember these
rules while coding ?
👨💻
Install eslint-plugin-react-hooks npm package to
enforce the rules in your project.
😪
😉
React hooks
When
upgrading to
React 16.8,
don't forget to
update React
DOM
Don’t worry.
Classes will not be
removed from React
No breaking changes.
100% backward compatible
Not compulsory.
Hooks are "opt-in" - you can use
hooks in few components in your app
No more classes.
Hooks allow you to use state and other features of react
without the need of using class components. Hooks
embrace functions
Facebook
has no plans
to
completely
rewrite all
components
with hooks
Hooks solve
the problems
present in
class
components
Same internals.
Hooks provide "Direct
APIs" to the React
concepts you already
know - props, state,
context, refs, and lifecycle
Hooks got introduced in
React v16.8
😲
Hold on.
🤯
< MSK Tutorials />
Problems associated with
Class components
🤯
It’s hard to reuse stateful logic between components.
• Patterns like render-props and higher-
order-components tried to give us a way to
"attach" reusable behaviour to a component
( like connecting it to a store). But you need
to re-structure your components before
using them.
• You will find wrapper-hell in React DevTools
( providers, consumers, higher-order
components, render props, and other
abstractions )
😡
👎
👎
Problem #1
< MSK Tutorials />
Solution
• Hooks let you extract stateful logic from
a component so it can be tested
independently and reused.
• Hooks allow you to reuse stateful logic
without changing your component
hierarchy.
😍
👍
👍
Hooks take reusability to the next level.
< MSK Tutorials />
Problem #2
Complex components become hard to understand.
• Life-cycle methods can contain code of unrelated
logic ( ex., Component will perform data-fetching in
componentDidMount but it may also contain
unrelated logic that sets up event listeners )
• It is difficult to break these components into smaller
ones because stateful logic is all over the place.
• It becomes difficult to test these components. So
people abstract the state with 3rd party libraries.
• 3rd party libraries introduce too much abstraction
and increases number of files.
🤬
👎
👎
< MSK Tutorials />
👎
👎
Solution
• Hooks let you split a big component into
smaller functions with related pieces.
• Hooks provide internal state to react
component. So testing becomes easy.
• 3rd party state management libraries
can be avoided for smaller use cases.
🥳
👍
👍
Hooks enable better organisation of code.
< MSK Tutorials />
👍
Problem #3
Classes confuse both people and machines.
• You have to understand how this works in
JavaScript. Which is confusing to many. Till today.
• You have to remember to bind the event handlers.
You will forget it for sure.
• When to use class vs when to use functions lead to
disagreements even between experienced react
developers.
• Classes don’t minify very well, and they make hot
reloading flaky and unreliable.
🥴
👎
👎
< MSK Tutorials />
👎
👎
Solution
• Function components are easier to
understand than classes.
• No need to bind event handlers
explicitly.
• You don’t have to deal with this too
much. Code becomes more readable.
🤩
👍
👍
Hooks embrace function components.
< MSK Tutorials />
👍
Adoption
Don’t start
using hooks in
all your projects
in production
immediately.
Take it easy.
Classes are here to stay
and support prod code.
Co existence.
Hooks and classes can live
together in a project.
Chillax.
There is no rush to migrate to Hooks.
One step at a time.
it’s best to use Hooks in new and non-critical components
first, and ensure that everybody on your team feels
comfortable with them.
Facebook
has tens of
thousands of
components
written in
classes.
Once you
get hooked,
there is no
going back !
Time to think differently.
It takes a bit of a mind shift
for developers to start
“thinking in Hooks”.

So take your time.
Hooks are completely
"opt-in"
😪
Hold on.
❤
Strategy
😃
Manoj Satish Kumar
Web developer
I believe knowledge is useless
if not shared. Let’s learn together.
I’m with you. It’s our journey.
“Follow me
on LinkedIn
TUTORIALS
MSK
< MSK Tutorials />

More Related Content

What's hot

React hooks
React hooksReact hooks
React hooks
Ramy ElBasyouni
 
State management in react applications (Statecharts)
State management in react applications (Statecharts)State management in react applications (Statecharts)
State management in react applications (Statecharts)
Tomáš Drenčák
 
React-JS.pptx
React-JS.pptxReact-JS.pptx
React-JS.pptx
AnmolPandita7
 
React-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsReact-JS Component Life-cycle Methods
React-JS Component Life-cycle Methods
ANKUSH CHAVAN
 
React js use contexts and useContext hook
React js use contexts and useContext hookReact js use contexts and useContext hook
React js use contexts and useContext hook
Piyush Jamwal
 
Important React Hooks
Important React HooksImportant React Hooks
Important React Hooks
Knoldus Inc.
 
Introduction to React Hooks
Introduction to React HooksIntroduction to React Hooks
Introduction to React Hooks
Felicia O'Garro
 
React JS & Functional Programming Principles
React JS & Functional Programming PrinciplesReact JS & Functional Programming Principles
React JS & Functional Programming Principles
Andrii Lundiak
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
Varun Raj
 
Workshop 21: React Router
Workshop 21: React RouterWorkshop 21: React Router
Workshop 21: React Router
Visual Engineering
 
What is component in reactjs
What is component in reactjsWhat is component in reactjs
What is component in reactjs
manojbkalla
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
Tariqul islam
 
React js
React jsReact js
Lets make a better react form
Lets make a better react formLets make a better react form
Lets make a better react form
Yao Nien Chung
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
DivyanshGupta922023
 
JUnit 5
JUnit 5JUnit 5
Junit
JunitJunit
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
Garrett Welson
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
WebStackAcademy
 
React introduction
React introductionReact introduction
React introduction
Võ Duy Tuấn
 

What's hot (20)

React hooks
React hooksReact hooks
React hooks
 
State management in react applications (Statecharts)
State management in react applications (Statecharts)State management in react applications (Statecharts)
State management in react applications (Statecharts)
 
React-JS.pptx
React-JS.pptxReact-JS.pptx
React-JS.pptx
 
React-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsReact-JS Component Life-cycle Methods
React-JS Component Life-cycle Methods
 
React js use contexts and useContext hook
React js use contexts and useContext hookReact js use contexts and useContext hook
React js use contexts and useContext hook
 
Important React Hooks
Important React HooksImportant React Hooks
Important React Hooks
 
Introduction to React Hooks
Introduction to React HooksIntroduction to React Hooks
Introduction to React Hooks
 
React JS & Functional Programming Principles
React JS & Functional Programming PrinciplesReact JS & Functional Programming Principles
React JS & Functional Programming Principles
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
 
Workshop 21: React Router
Workshop 21: React RouterWorkshop 21: React Router
Workshop 21: React Router
 
What is component in reactjs
What is component in reactjsWhat is component in reactjs
What is component in reactjs
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
React js
React jsReact js
React js
 
Lets make a better react form
Lets make a better react formLets make a better react form
Lets make a better react form
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Junit
JunitJunit
Junit
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
 
React introduction
React introductionReact introduction
React introduction
 

Similar to React hooks Episode #1: An introduction.

React.js hooks feb 23rd meetup
React.js hooks feb 23rd meetupReact.js hooks feb 23rd meetup
React.js hooks feb 23rd meetup
Jaikant Kumaran
 
Mcknight well built extensions
Mcknight well built extensionsMcknight well built extensions
Mcknight well built extensions
Richard McKnight
 
React Best Practices All Developers Should Follow in 2024.pdf
React Best Practices All Developers Should Follow in 2024.pdfReact Best Practices All Developers Should Follow in 2024.pdf
React Best Practices All Developers Should Follow in 2024.pdf
BOSC Tech Labs
 
Workshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdfWorkshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdf
TobiasGoeschel
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
Alex Borsuk
 
CQRS recepies
CQRS recepiesCQRS recepies
CQRS recepies
Francesco Garavaglia
 
ReactCodemod: An automated approach for refactoring class based components to...
ReactCodemod: An automated approach for refactoring class based components to...ReactCodemod: An automated approach for refactoring class based components to...
ReactCodemod: An automated approach for refactoring class based components to...
IRJET Journal
 
Daniel Steigerwald - Este.js - konec velkého Schizma
Daniel Steigerwald - Este.js - konec velkého SchizmaDaniel Steigerwald - Este.js - konec velkého Schizma
Daniel Steigerwald - Este.js - konec velkého Schizma
Develcz
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)
stanbridge
 
ReactJs Training in Hyderabad | ReactJS Training
ReactJs Training in Hyderabad  | ReactJS TrainingReactJs Training in Hyderabad  | ReactJS Training
ReactJs Training in Hyderabad | ReactJS Training
eshwarvisualpath
 
Generic Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity FrameworkGeneric Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity Framework
Akhil Mittal
 
OOM Unit I - III.pdf
OOM Unit I - III.pdfOOM Unit I - III.pdf
OOM Unit I - III.pdf
ShaikRafikhan1
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
Gaurav Tyagi
 
Unit 2 Fundamentals of React -------.pptx
Unit 2 Fundamentals of React -------.pptxUnit 2 Fundamentals of React -------.pptx
Unit 2 Fundamentals of React -------.pptx
krishitajariwala72
 
Refactoring ASP.NET and beyond
Refactoring ASP.NET and beyondRefactoring ASP.NET and beyond
Refactoring ASP.NET and beyond
DotNetMarche
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
Knoldus Inc.
 
Salesforce lwc development workshops session #6
Salesforce lwc development workshops  session #6Salesforce lwc development workshops  session #6
Salesforce lwc development workshops session #6
Rahul Gawale
 
Green Custard Friday Talk 21: React Hooks
Green Custard Friday Talk 21: React HooksGreen Custard Friday Talk 21: React Hooks
Green Custard Friday Talk 21: React Hooks
Green Custard
 
10 reasons to choose CakePHP as Framework
10 reasons to choose CakePHP as Framework10 reasons to choose CakePHP as Framework
10 reasons to choose CakePHP as Framework
Trusted Web Service
 
Learn reactjs, how to code with example and general understanding thinkwik
Learn reactjs, how to code with example and general understanding   thinkwikLearn reactjs, how to code with example and general understanding   thinkwik
Learn reactjs, how to code with example and general understanding thinkwik
Hetaxi patel
 

Similar to React hooks Episode #1: An introduction. (20)

React.js hooks feb 23rd meetup
React.js hooks feb 23rd meetupReact.js hooks feb 23rd meetup
React.js hooks feb 23rd meetup
 
Mcknight well built extensions
Mcknight well built extensionsMcknight well built extensions
Mcknight well built extensions
 
React Best Practices All Developers Should Follow in 2024.pdf
React Best Practices All Developers Should Follow in 2024.pdfReact Best Practices All Developers Should Follow in 2024.pdf
React Best Practices All Developers Should Follow in 2024.pdf
 
Workshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdfWorkshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdf
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
 
CQRS recepies
CQRS recepiesCQRS recepies
CQRS recepies
 
ReactCodemod: An automated approach for refactoring class based components to...
ReactCodemod: An automated approach for refactoring class based components to...ReactCodemod: An automated approach for refactoring class based components to...
ReactCodemod: An automated approach for refactoring class based components to...
 
Daniel Steigerwald - Este.js - konec velkého Schizma
Daniel Steigerwald - Este.js - konec velkého SchizmaDaniel Steigerwald - Este.js - konec velkého Schizma
Daniel Steigerwald - Este.js - konec velkého Schizma
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)
 
ReactJs Training in Hyderabad | ReactJS Training
ReactJs Training in Hyderabad  | ReactJS TrainingReactJs Training in Hyderabad  | ReactJS Training
ReactJs Training in Hyderabad | ReactJS Training
 
Generic Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity FrameworkGeneric Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity Framework
 
OOM Unit I - III.pdf
OOM Unit I - III.pdfOOM Unit I - III.pdf
OOM Unit I - III.pdf
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
Unit 2 Fundamentals of React -------.pptx
Unit 2 Fundamentals of React -------.pptxUnit 2 Fundamentals of React -------.pptx
Unit 2 Fundamentals of React -------.pptx
 
Refactoring ASP.NET and beyond
Refactoring ASP.NET and beyondRefactoring ASP.NET and beyond
Refactoring ASP.NET and beyond
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
Salesforce lwc development workshops session #6
Salesforce lwc development workshops  session #6Salesforce lwc development workshops  session #6
Salesforce lwc development workshops session #6
 
Green Custard Friday Talk 21: React Hooks
Green Custard Friday Talk 21: React HooksGreen Custard Friday Talk 21: React Hooks
Green Custard Friday Talk 21: React Hooks
 
10 reasons to choose CakePHP as Framework
10 reasons to choose CakePHP as Framework10 reasons to choose CakePHP as Framework
10 reasons to choose CakePHP as Framework
 
Learn reactjs, how to code with example and general understanding thinkwik
Learn reactjs, how to code with example and general understanding   thinkwikLearn reactjs, how to code with example and general understanding   thinkwik
Learn reactjs, how to code with example and general understanding thinkwik
 

Recently uploaded

Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
danielkiash986
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
giancarloi8888
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
zuzanka
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
melliereed
 

Recently uploaded (20)

Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
 

React hooks Episode #1: An introduction.

  • 1. 🙋 An introduction. < MSK Tutorials /> React hooks Manoj Satish Kumar Web developer Tutorials MSK Episode #1
  • 2. < MSK Tutorials /> The bar for adding a new primitive to React is extremely high. 😲
  • 3. What are hooks ? • Hooks are functions that let you “hook into” React state and lifecycle features from function components. • Hooks don’t work inside classes — they let you use React without classes. • Hooks will reduce your component size significantly and have many other benefits. 🤔 They are created for a reason. A big reason. < MSK Tutorials />
  • 4. 3 rules of using hooks. • Only call Hooks at the top level. Don’t call Hooks inside loops, conditions, or nested functions. • Only call Hooks from React function components. Don’t call Hooks from regular JavaScript functions. • There is just one other valid place to call hooks - your own custom hooks.
 😇 Because rules are meant to be followed. Not broken. < MSK Tutorials />
  • 5. < MSK Tutorials /> Feeling lazy to remember these rules while coding ? 👨💻 Install eslint-plugin-react-hooks npm package to enforce the rules in your project. 😪 😉
  • 6. React hooks When upgrading to React 16.8, don't forget to update React DOM Don’t worry. Classes will not be removed from React No breaking changes. 100% backward compatible Not compulsory. Hooks are "opt-in" - you can use hooks in few components in your app No more classes. Hooks allow you to use state and other features of react without the need of using class components. Hooks embrace functions Facebook has no plans to completely rewrite all components with hooks Hooks solve the problems present in class components Same internals. Hooks provide "Direct APIs" to the React concepts you already know - props, state, context, refs, and lifecycle Hooks got introduced in React v16.8 😲 Hold on. 🤯
  • 7. < MSK Tutorials /> Problems associated with Class components 🤯
  • 8. It’s hard to reuse stateful logic between components. • Patterns like render-props and higher- order-components tried to give us a way to "attach" reusable behaviour to a component ( like connecting it to a store). But you need to re-structure your components before using them. • You will find wrapper-hell in React DevTools ( providers, consumers, higher-order components, render props, and other abstractions ) 😡 👎 👎 Problem #1 < MSK Tutorials />
  • 9. Solution • Hooks let you extract stateful logic from a component so it can be tested independently and reused. • Hooks allow you to reuse stateful logic without changing your component hierarchy. 😍 👍 👍 Hooks take reusability to the next level. < MSK Tutorials />
  • 10. Problem #2 Complex components become hard to understand. • Life-cycle methods can contain code of unrelated logic ( ex., Component will perform data-fetching in componentDidMount but it may also contain unrelated logic that sets up event listeners ) • It is difficult to break these components into smaller ones because stateful logic is all over the place. • It becomes difficult to test these components. So people abstract the state with 3rd party libraries. • 3rd party libraries introduce too much abstraction and increases number of files. 🤬 👎 👎 < MSK Tutorials /> 👎 👎
  • 11. Solution • Hooks let you split a big component into smaller functions with related pieces. • Hooks provide internal state to react component. So testing becomes easy. • 3rd party state management libraries can be avoided for smaller use cases. 🥳 👍 👍 Hooks enable better organisation of code. < MSK Tutorials /> 👍
  • 12. Problem #3 Classes confuse both people and machines. • You have to understand how this works in JavaScript. Which is confusing to many. Till today. • You have to remember to bind the event handlers. You will forget it for sure. • When to use class vs when to use functions lead to disagreements even between experienced react developers. • Classes don’t minify very well, and they make hot reloading flaky and unreliable. 🥴 👎 👎 < MSK Tutorials /> 👎 👎
  • 13. Solution • Function components are easier to understand than classes. • No need to bind event handlers explicitly. • You don’t have to deal with this too much. Code becomes more readable. 🤩 👍 👍 Hooks embrace function components. < MSK Tutorials /> 👍
  • 14. Adoption Don’t start using hooks in all your projects in production immediately. Take it easy. Classes are here to stay and support prod code. Co existence. Hooks and classes can live together in a project. Chillax. There is no rush to migrate to Hooks. One step at a time. it’s best to use Hooks in new and non-critical components first, and ensure that everybody on your team feels comfortable with them. Facebook has tens of thousands of components written in classes. Once you get hooked, there is no going back ! Time to think differently. It takes a bit of a mind shift for developers to start “thinking in Hooks”. So take your time. Hooks are completely "opt-in" 😪 Hold on. ❤ Strategy 😃
  • 15. Manoj Satish Kumar Web developer I believe knowledge is useless if not shared. Let’s learn together. I’m with you. It’s our journey. “Follow me on LinkedIn