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 best color palette for every web developer and designer ๐จ
๐งต๐
1. Color hunt
- Color Hunt is a free and open platform for color inspiration with thousands of trendy hand- picked color palettes
๐๏ธ https://t.co/xR0FVTjK0L
2. Adobe color wheel
Explore and create accessible color palettes using color wheel, in variety of color variations and contrast levels. It will tell you automatically if two colors are not accessible
๐๏ธ https://t.co/ndsgBauTEc
3. Palette Ninja
Palette ninja is an online color scheme generator that allows you to create harmonious color schemes in seconds
๐๏ธ https://t.co/cuzP21tn2Z
4. My color space
Here you can find the perfect matching color scheme for your next project! Generate nice color palettes, color gradients and much more! Your space for everything that has to do with color
๐๏ธ https://t.co/kmjrXOceAj
๐งต๐

1. Color hunt
- Color Hunt is a free and open platform for color inspiration with thousands of trendy hand- picked color palettes
๐๏ธ https://t.co/xR0FVTjK0L

2. Adobe color wheel
Explore and create accessible color palettes using color wheel, in variety of color variations and contrast levels. It will tell you automatically if two colors are not accessible
๐๏ธ https://t.co/ndsgBauTEc

3. Palette Ninja
Palette ninja is an online color scheme generator that allows you to create harmonious color schemes in seconds
๐๏ธ https://t.co/cuzP21tn2Z

4. My color space
Here you can find the perfect matching color scheme for your next project! Generate nice color palettes, color gradients and much more! Your space for everything that has to do with color
๐๏ธ https://t.co/kmjrXOceAj

5 great code snippet websites for every web developer and designer
๐งต๐๐ป
1๏ธโฃ 30 Seconds of Code
- Short code snippets for all your development needs
๐ https://t.co/91L4bAxkgF
2๏ธโฃ Free Frontend
- Free hand-picked HTML, CSS and JavaScript (jQuery, React, Vue) code examples, tutorials and articles
๐ https://t.co/2sIAm73EdZ
3๏ธโฃ Little Snippets
- A free collection of HTML and CSS code snippets
๐ https://t.co/qxAyA2wA6U
4๏ธโฃ CSS Deck
- Collection of Awesome CSS and JS Creations to help out frontend developers and designers.
๐ https://t.co/LcZYnipvCy
๐งต๐๐ป

1๏ธโฃ 30 Seconds of Code
- Short code snippets for all your development needs
๐ https://t.co/91L4bAxkgF

2๏ธโฃ Free Frontend
- Free hand-picked HTML, CSS and JavaScript (jQuery, React, Vue) code examples, tutorials and articles
๐ https://t.co/2sIAm73EdZ

3๏ธโฃ Little Snippets
- A free collection of HTML and CSS code snippets
๐ https://t.co/qxAyA2wA6U

4๏ธโฃ CSS Deck
- Collection of Awesome CSS and JS Creations to help out frontend developers and designers.
๐ https://t.co/LcZYnipvCy

APIs in general are so powerful.
Best 5 public APIs you can use to build your next project:
1. Number Verification API
A RESTful JSON API for national and international phone number validation.
๐ https://t.co/fzBmCMFdIj
2. OpenAI API
ChatGPT is an outstanding tool. Build your own API applications with OpenAI API.
๐ https://t.co/TVnTciMpML
3. Currency Data API
Currency Data API provides a simple REST API with real-time and historical exchange rates for 168 world currencies
๐ https://t.co/TRj35IUUec
4. Weather API
Real-Time & historical world weather data API.
Retrieve instant, accurate weather information for
any location in the world in lightweight JSON format.
๐ https://t.co/DCY8kXqVIK
Best 5 public APIs you can use to build your next project:
1. Number Verification API
A RESTful JSON API for national and international phone number validation.
๐ https://t.co/fzBmCMFdIj

2. OpenAI API
ChatGPT is an outstanding tool. Build your own API applications with OpenAI API.
๐ https://t.co/TVnTciMpML

3. Currency Data API
Currency Data API provides a simple REST API with real-time and historical exchange rates for 168 world currencies
๐ https://t.co/TRj35IUUec

4. Weather API
Real-Time & historical world weather data API.
Retrieve instant, accurate weather information for
any location in the world in lightweight JSON format.
๐ https://t.co/DCY8kXqVIK

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

You May Also Like
1/OK, data mystery time.
This New York Times feature shows China with a Gini Index of less than 30, which would make it more equal than Canada, France, or the Netherlands. https://t.co/g3Sv6DZTDE
That's weird. Income inequality in China is legendary.
Let's check this number.
2/The New York Times cites the World Bank's recent report, "Fair Progress? Economic Mobility across Generations Around the World".
The report is available here:
3/The World Bank report has a graph in which it appears to show the same value for China's Gini - under 0.3.
The graph cites the World Development Indicators as its source for the income inequality data.
4/The World Development Indicators are available at the World Bank's website.
Here's the Gini index: https://t.co/MvylQzpX6A
It looks as if the latest estimate for China's Gini is 42.2.
That estimate is from 2012.
5/A Gini of 42.2 would put China in the same neighborhood as the U.S., whose Gini was estimated at 41 in 2013.
I can't find the <30 number anywhere. The only other estimate in the tables for China is from 2008, when it was estimated at 42.8.
This New York Times feature shows China with a Gini Index of less than 30, which would make it more equal than Canada, France, or the Netherlands. https://t.co/g3Sv6DZTDE
That's weird. Income inequality in China is legendary.
Let's check this number.
2/The New York Times cites the World Bank's recent report, "Fair Progress? Economic Mobility across Generations Around the World".
The report is available here:
3/The World Bank report has a graph in which it appears to show the same value for China's Gini - under 0.3.
The graph cites the World Development Indicators as its source for the income inequality data.

4/The World Development Indicators are available at the World Bank's website.
Here's the Gini index: https://t.co/MvylQzpX6A
It looks as if the latest estimate for China's Gini is 42.2.
That estimate is from 2012.
5/A Gini of 42.2 would put China in the same neighborhood as the U.S., whose Gini was estimated at 41 in 2013.
I can't find the <30 number anywhere. The only other estimate in the tables for China is from 2008, when it was estimated at 42.8.