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 🧵👇🏻

useEffect hook is the heart of React functional components

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
By using useEffect, you tell React that your component needs to do something after render. React will remember the function you passed (we'll refer to it as our “effect”), and call it later after performing the DOM updates

So let's start by understanding the syntax first

useEffect take two parameters, first is a function and second is an array.

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 }
As you can see in the output the function is executed every single time my component re-render

{ 5 / 15 }
But let's say if I add some dependency in the array and pass the array as second parameter then useEffect will only run when the value of dependency array change.

For example, let me modify the code little bit so that you can understand it better

{ 6 / 15 }
As you can see when I click on the re-render button, our useEffect run this is because I have passed render state inside dependency array

{ 7 / 15 }
🚨 Here's an important thing to note is that if you pass an empty array then it will only run on once.
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 }
In useEffect we can also perform clean up

If we return a function within the method, this function perform basically a clean up of what we did last time.

{ 9 / 15 }
For example, consider this piece of code

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

So far we have discussed the basics of useEffect.

Let's build something useful using it. We will be using useEffect for fetching some COVID data

{ 11 / 15 }
We will print total number of confirmed COVID cases of a specific country enter by user in the input field.

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 }
- Make an input field
- 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 }
Check out the source code on this link in more accessible form

{ 14 / 15 }
Awesome! I think we have covered everything related to useEffect hook. It is little tough so try to play around with the code. I hope you like this thread ❤️

Peace out 😉

More from Pratham

Do not write CSS code, use these free generators instead that can help you immensely

A Thread 🧵

1️⃣ Stripes generator

- Pure CSS Stripes Generator that you can use for backgrounds.


2️⃣ Gradient generator

- As a free css gradient generator tool, this website lets you create a colorful gradient background for your website, blog, or social media profile


3️⃣ Pattern generator

- It lets you create background pattern for free


4️⃣ CSS Accordion Slider Generator

- Create fully responsive, css only accordion sliders

5 great code snippet websites for every web developer and designer


1️⃣ 30 Seconds of Code

- Short code snippets for all your development needs


2️⃣ Free Frontend

- Free hand-picked HTML, CSS and JavaScript (jQuery, React, Vue) code examples, tutorials and articles


3️⃣ Little Snippets

- A free collection of HTML and CSS code snippets


4️⃣ CSS Deck

- Collection of Awesome CSS and JS Creations to help out frontend developers and designers.


More from Webdev

Are you a web developer?

Here's a list of websites that offer free & beautiful website templates:


1. HTML5UP: Very modern, unique responsive HTML5/CSS3 themes

2. Templatemo: Minimal, resume, gallery themes and more

3. Templated .co: Tons of minimalistic HTML5/CSS3

4. FreeHTML5: Free & premium HTML5 and Bootstrap themes

5. StyleShout: Brilliantly crafted free website templates

6. Start Bootstrap: Bootstrap starter

7. Zerotheme: HTML5, Bootstrap, Prestashop templates

8. HTML5xCSS3: Collection of wonderful templates in different categories

9. Colorlib: Almost any category of theme you can think

10: Free CSS: Huge collection of free templates

11. Hubspot: Templates, infographics, banners and much more

12. Mobirise: Great looking HTML5/CSS3
6 beginner friendly websites that will boost your HTML and CSS learning process 🚀


1️⃣ Learn HTML

- The easiest way to learn HTML & CSS. Learn HTML provides an interactive tutorial that explains how to build HTML & CSS websites step by step.


2️⃣ HTML best practice

- A very well written document on HTML best practice


3️⃣ Learn to Code HTML & CSS

- Learn to Code HTML & CSS is a simple and comprehensive guide dedicated to helping beginners learn HTML and CSS


4️⃣ Hex Invaders

- Hex Invaders is a fun way to learn and understand what hex codes are and how they work


You May Also Like

I'm going to do two history threads on Ethiopia, one on its ancient history, one on its modern story (1800 to today). 🇪🇹

I'll begin with the ancient history ... and it goes way back. Because modern humans - and before that, the ancestors of humans - almost certainly originated in Ethiopia. 🇪🇹 (sub-thread):

The first likely historical reference to Ethiopia is ancient Egyptian records of trade expeditions to the "Land of Punt" in search of gold, ebony, ivory, incense, and wild animals, starting in c 2500 BC 🇪🇹

Ethiopians themselves believe that the Queen of Sheba, who visited Israel's King Solomon in the Bible (c 950 BC), came from Ethiopia (not Yemen, as others believe). Here she is meeting Solomon in a stain-glassed window in Addis Ababa's Holy Trinity Church. 🇪🇹

References to the Queen of Sheba are everywhere in Ethiopia. The national airline's frequent flier miles are even called "ShebaMiles". 🇪🇹