If you're familiar with class components then you might know that we have various lifecycle methods but in functional components, we don't have any lifecycle methods. Instead we have a powerful hook called useEffect
React Hooks are the functions which "hook into" React state and lifecycle features from function components. Hooks allows you to manipulate state and other React feature without writing a class. Let's talk about widely used hook
useEffect hook at a glance 🧵👇🏻
If you're familiar with class components then you might know that we have various lifecycle methods but in functional components, we don't have any lifecycle methods. Instead we have a powerful hook called useEffect
So let's start by understanding the syntax first
3/15
The function inside the useEffect will run every single time component re-render. Consider this piece of code and check the output in next tweet
{ 4 / 15 }
{ 5 / 15 }
For example, let me modify the code little bit so that you can understand it better
{ 6 / 15 }
{ 7 / 15 }
No matter how many times you render your component, the useEffect will run only once because the value of empty array never going to change
{ 8 / 15 }
If we return a function within the method, this function perform basically a clean up of what we did last time.
{ 9 / 15 }
useEffect(() => {
console.log({ render });
return () => {
console.log("I'm cleanup function");
};
}, [render]);
Everytime I click the button, first our useEffect perform clean up then run the effect function
10/15
Let's build something useful using it. We will be using useEffect for fetching some COVID data
{ 11 / 15 }
On the basis of the value entered by user we will store that in "country" and change that value in our API link
{ 12 / 15 }
- on form submit, store the input value in "country"
Print the confirmed cases on screen as simple as that
check the entire code
{ 13 / 15 }
More from Pratham
5 amazing GitHub repositories for every self taught developer
A Thread 🧵
1️⃣ Computer Science
🎓 Path to a free self-taught education in Computer Science!
🔗 https://t.co/67jB5zqIes
2️⃣ Free Certifications
Curated list of free courses & certifications
🔗 https://t.co/4XtlAVlovs
3️⃣ Free Programming Books
📚 Freely available programming books
🔗 https://t.co/eOWLCtwtIV
4️⃣ JavaScript Question
A long list of (advanced) JavaScript questions, and their explanations ✨
🔗 https://t.co/UvEl1Esvh3
A Thread 🧵
1️⃣ Computer Science
🎓 Path to a free self-taught education in Computer Science!
🔗 https://t.co/67jB5zqIes
2️⃣ Free Certifications
Curated list of free courses & certifications
🔗 https://t.co/4XtlAVlovs
3️⃣ Free Programming Books
📚 Freely available programming books
🔗 https://t.co/eOWLCtwtIV
4️⃣ JavaScript Question
A long list of (advanced) JavaScript questions, and their explanations ✨
🔗 https://t.co/UvEl1Esvh3
You can check out these websites if you're learning HTML, CSS and JavaScript 🧵...
HTML 🧱
1. Learn HTML
https://t.co/NlQZAFwthT
2. HTML best practice
https://t.co/PyPf3lP9bX
3. HTML
CSS 🎨
1. CSS reference
https://t.co/Hhk8NKglpf
2. Learn to code
https://t.co/CLEsHgSrEk
3. CSS layout
https://t.co/9yiXkP3mWi
4. CSS tutorial
https://t.co/fR6AeVTdZv
5. Learn about colors
https://t.co/7vrD10j0jU
6. Learn gird
JavaScript ⚙️
1. JavaScript visualizer
https://t.co/9NId4GjGAq
2. Learn JavaScript
https://t.co/5WbtISS11I
https://t.co/4h27qOC1fO
3. JavaScript tutorial
https://t.co/taSKnEPxMS
4. JavaScript 30
https://t.co/j2wEIHVU8S
5. JavaScript
HTML 🧱
1. Learn HTML
https://t.co/NlQZAFwthT
2. HTML best practice
https://t.co/PyPf3lP9bX
3. HTML
CSS 🎨
1. CSS reference
https://t.co/Hhk8NKglpf
2. Learn to code
https://t.co/CLEsHgSrEk
3. CSS layout
https://t.co/9yiXkP3mWi
4. CSS tutorial
https://t.co/fR6AeVTdZv
5. Learn about colors
https://t.co/7vrD10j0jU
6. Learn gird
JavaScript ⚙️
1. JavaScript visualizer
https://t.co/9NId4GjGAq
2. Learn JavaScript
https://t.co/5WbtISS11I
https://t.co/4h27qOC1fO
3. JavaScript tutorial
https://t.co/taSKnEPxMS
4. JavaScript 30
https://t.co/j2wEIHVU8S
5. JavaScript
6 websites that are so fantastic you'll wonder how they even exist (for developers):
1. ScribeHow (@ScribeHow)
Turn any process into a step-by-step guide, instantly.
• Click record
• Do the thing you want to show someone (like how to reset a password)
• Get a beautiful auto-generated guide
No manual screenshots.
🔗 https://t.co/8EnpUIvIeR
2. SourceAI
Explain what you want in plain English, and AI will generate a code snippet for you.
🔗 https://t.co/KFLbBBjllm
3. Blackbox
Turn any questions into a code snippet or extract a code snippet from a video.
🔗 https://t.co/6Z4fM5ieWn
4. Figstack
One-stop for developers.
• Understand code in any programming language
• Translate programming languages
• Automate documentation for your functions
• Get the time complexity of your program
🔗 https://t.co/koY4cmciR3
1. ScribeHow (@ScribeHow)
Turn any process into a step-by-step guide, instantly.
• Click record
• Do the thing you want to show someone (like how to reset a password)
• Get a beautiful auto-generated guide
No manual screenshots.
🔗 https://t.co/8EnpUIvIeR
2. SourceAI
Explain what you want in plain English, and AI will generate a code snippet for you.
🔗 https://t.co/KFLbBBjllm
3. Blackbox
Turn any questions into a code snippet or extract a code snippet from a video.
🔗 https://t.co/6Z4fM5ieWn
4. Figstack
One-stop for developers.
• Understand code in any programming language
• Translate programming languages
• Automate documentation for your functions
• Get the time complexity of your program
🔗 https://t.co/koY4cmciR3
Use these 5 websites to learn web development for free in 2023 (take a look):
1. Codedamn
All-in-one platform for learning web development:
• Hands-on practice and projects bundled
• Video content along with interactive labs, quizzes, and articles
• Every course comes with a certificate
• code brushes AI in playgrounds
🔗 https://t.co/mXmUtJZnOU
2. Codepip
Codepip is the platform for your favorite web development games. Gain an edge in your following interview or project.
🔗 https://t.co/MjHNsLvkiL
3. RapidAPI Comics
Learn API development with RapidAPI Comics (sketch notes and fun analogies).
🔗 https://t.co/KONorFomgu
4. JS Visualizer 9000
Learn JavaScript by visualizing your code.
🔗 https://t.co/9NId4GjGAq
1. Codedamn
All-in-one platform for learning web development:
• Hands-on practice and projects bundled
• Video content along with interactive labs, quizzes, and articles
• Every course comes with a certificate
• code brushes AI in playgrounds
🔗 https://t.co/mXmUtJZnOU
2. Codepip
Codepip is the platform for your favorite web development games. Gain an edge in your following interview or project.
🔗 https://t.co/MjHNsLvkiL
3. RapidAPI Comics
Learn API development with RapidAPI Comics (sketch notes and fun analogies).
🔗 https://t.co/KONorFomgu
4. JS Visualizer 9000
Learn JavaScript by visualizing your code.
🔗 https://t.co/9NId4GjGAq
More from Webdev
5 great gradient background sites for every web developer and designer 🎨
🧵👇🏻
1️⃣ uiGradients
- A handpicked collection of beautiful color gradients for designers and developers.
🔗 https://t.co/EainhiePop
2️⃣ Eggradient
- Ready to use gradient background colors. ✓ Cool Gradients are prepared according to the latest design trends
🔗 https://t.co/F0uYVsZbA4
3️⃣ Mesh Gradients
- Create beautiful gradient like aurora UI in few clicks
🔗 https://t.co/MV8PT7q3Kz
4️⃣ CSS Gradient
- Create beatiful gradeint either linear or radial on different angles
🔗 https://t.co/dlCExilHAT
🧵👇🏻
1️⃣ uiGradients
- A handpicked collection of beautiful color gradients for designers and developers.
🔗 https://t.co/EainhiePop
2️⃣ Eggradient
- Ready to use gradient background colors. ✓ Cool Gradients are prepared according to the latest design trends
🔗 https://t.co/F0uYVsZbA4
3️⃣ Mesh Gradients
- Create beautiful gradient like aurora UI in few clicks
🔗 https://t.co/MV8PT7q3Kz
4️⃣ CSS Gradient
- Create beatiful gradeint either linear or radial on different angles
🔗 https://t.co/dlCExilHAT