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 great background websites for every web developer and designer
๐งต๐
1. Magic pattern
Beautiful pure CSS background patterns that you can actually use in your projects. They are highly customizable as well.
๐๏ธ https://t.co/ZqczrPfkdZ
2. Cool backgrounds
Collection of cool backgrounds that you can add to blogs, websites, or as desktop and phone wallpapers
๐๏ธ https://t.co/df7VSb9t8H
3. Gradienta
Use pure CSS gradient backgrounds for your next website or app, as a JPG image or CSS code, no attribute required
๐๏ธ https://t.co/R58zrwpZCH
4 Mesh gradient
Creat aurora UI like gradients using few simple clicks
๐๏ธ https://t.co/vOHHDASr1V
๐งต๐
1. Magic pattern
Beautiful pure CSS background patterns that you can actually use in your projects. They are highly customizable as well.
๐๏ธ https://t.co/ZqczrPfkdZ
2. Cool backgrounds
Collection of cool backgrounds that you can add to blogs, websites, or as desktop and phone wallpapers
๐๏ธ https://t.co/df7VSb9t8H
3. Gradienta
Use pure CSS gradient backgrounds for your next website or app, as a JPG image or CSS code, no attribute required
๐๏ธ https://t.co/R58zrwpZCH
4 Mesh gradient
Creat aurora UI like gradients using few simple clicks
๐๏ธ https://t.co/vOHHDASr1V
Top 5 free APIs for web developers
๐งต๐
1๏ธโฃ Custom Search API
- Create your own custom search engine. You can search for image, videos, and news.
๐ https://t.co/nTvv3c3W06
2๏ธโฃ Movie Database API
- Access movie and TV information similar to that of IMDB.
๐
3๏ธโฃ Dad Jokes API
- Get random endless dad jokes
๐
4๏ธโฃ COVID-19 Data API
- Every 15 minutes updated statistic about Coronavirus. Latest stats by country, are collected from several reliable sources.
๐
๐งต๐
1๏ธโฃ Custom Search API
- Create your own custom search engine. You can search for image, videos, and news.
๐ https://t.co/nTvv3c3W06
2๏ธโฃ Movie Database API
- Access movie and TV information similar to that of IMDB.
๐
3๏ธโฃ Dad Jokes API
- Get random endless dad jokes
๐
4๏ธโฃ COVID-19 Data API
- Every 15 minutes updated statistic about Coronavirus. Latest stats by country, are collected from several reliable sources.
๐
12 websites that will help you learn web development faster (completely free): ๐งต
1. How HTTP Works
Everything you need to know about HTTP based system.
๐ https://t.co/gVZS4RzS1a
2. 30 Days of Node
Learn Node step by step with interactive examples and code snippet in 30 days.
๐ https://t.co/9nbtMiNB1C
3. How DNS Works
Learn what happens when you type a website address in your browser
๐ https://t.co/SqMRNnDbc3
4. Git
Check out this excellent free website to learn git visually.
๐ https://t.co/rQJMISBDfS
1. How HTTP Works
Everything you need to know about HTTP based system.
๐ https://t.co/gVZS4RzS1a
2. 30 Days of Node
Learn Node step by step with interactive examples and code snippet in 30 days.
๐ https://t.co/9nbtMiNB1C
3. How DNS Works
Learn what happens when you type a website address in your browser
๐ https://t.co/SqMRNnDbc3
4. Git
Check out this excellent free website to learn git visually.
๐ https://t.co/rQJMISBDfS
More from Webdev
Five great icons websites for every web developer and designer โบ๏ธ
A Thread ๐งต๐๐ป
1๏ธโฃ Icons 8
- Icons8 is just more than icons. You can download illustrations, vector images, music and much more
๐๏ธ https://t.co/inHse0QXBh
2๏ธโฃ Icon Monstr
- Black and white themed minimal icons which looks super great. You can also cuatomize the thickness
๐๏ธ https://t.co/dbQrJi0IHf
3๏ธโฃ Icon Icons
- Over one thousand free icons which you can download as icons or images
๐๏ธ https://t.co/h5NlH5fGGr
4๏ธโฃ Icons finder
Filter through the worldโs largest marketplace for icons with flexibility and ease. Made up by submissions from top designers around the world, and curated by the team
๐๏ธ https://t.co/sqiZ6H9sR7
A Thread ๐งต๐๐ป
1๏ธโฃ Icons 8
- Icons8 is just more than icons. You can download illustrations, vector images, music and much more
๐๏ธ https://t.co/inHse0QXBh
2๏ธโฃ Icon Monstr
- Black and white themed minimal icons which looks super great. You can also cuatomize the thickness
๐๏ธ https://t.co/dbQrJi0IHf
3๏ธโฃ Icon Icons
- Over one thousand free icons which you can download as icons or images
๐๏ธ https://t.co/h5NlH5fGGr
4๏ธโฃ Icons finder
Filter through the worldโs largest marketplace for icons with flexibility and ease. Made up by submissions from top designers around the world, and curated by the team
๐๏ธ https://t.co/sqiZ6H9sR7
12 websites that will help you learn web development faster (completely free): ๐งต
1. How HTTP Works
Everything you need to know about HTTP based system.
๐ https://t.co/gVZS4RzS1a
2. 30 Days of Node
Learn Node step by step with interactive examples and code snippet in 30 days.
๐ https://t.co/9nbtMiNB1C
3. How DNS Works
Learn what happens when you type a website address in your browser
๐ https://t.co/SqMRNnDbc3
4. Git
Check out this excellent free website to learn git visually.
๐ https://t.co/rQJMISBDfS
1. How HTTP Works
Everything you need to know about HTTP based system.
๐ https://t.co/gVZS4RzS1a
2. 30 Days of Node
Learn Node step by step with interactive examples and code snippet in 30 days.
๐ https://t.co/9nbtMiNB1C
3. How DNS Works
Learn what happens when you type a website address in your browser
๐ https://t.co/SqMRNnDbc3
4. Git
Check out this excellent free website to learn git visually.
๐ https://t.co/rQJMISBDfS
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
You May Also Like
Ivor Cummins has been wrong (or lying) almost entirely throughout this pandemic and got paid handsomly for it.
He has been wrong (or lying) so often that it will be nearly impossible for me to track every grift, lie, deceit, manipulation he has pulled. I will use...
... other sources who have been trying to shine on light on this grifter (as I have tried to do, time and again:
Example #1: "Still not seeing Sweden signal versus Denmark really"... There it was (Images attached).
19 to 80 is an over 300% difference.
Tweet: https://t.co/36FnYnsRT9
Example #2 - "Yes, I'm comparing the Noridcs / No, you cannot compare the Nordics."
I wonder why...
Tweets: https://t.co/XLfoX4rpck / https://t.co/vjE1ctLU5x
Example #3 - "I'm only looking at what makes the data fit in my favour" a.k.a moving the goalposts.
Tweets: https://t.co/vcDpTu3qyj / https://t.co/CA3N6hC2Lq
He has been wrong (or lying) so often that it will be nearly impossible for me to track every grift, lie, deceit, manipulation he has pulled. I will use...
... other sources who have been trying to shine on light on this grifter (as I have tried to do, time and again:
Ivor Cummins BE (Chem) is a former R&D Manager at HP (sourcre: https://t.co/Wbf5scf7gn), turned Content Creator/Podcast Host/YouTube personality. (Call it what you will.)
— Steve (@braidedmanga) November 17, 2020
Example #1: "Still not seeing Sweden signal versus Denmark really"... There it was (Images attached).
19 to 80 is an over 300% difference.
Tweet: https://t.co/36FnYnsRT9
Example #2 - "Yes, I'm comparing the Noridcs / No, you cannot compare the Nordics."
I wonder why...
Tweets: https://t.co/XLfoX4rpck / https://t.co/vjE1ctLU5x
Example #3 - "I'm only looking at what makes the data fit in my favour" a.k.a moving the goalposts.
Tweets: https://t.co/vcDpTu3qyj / https://t.co/CA3N6hC2Lq