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

3/15
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

10/15
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

https://t.co/r9G6i7EAIW

{ 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.

🔗
https://t.co/5uTPrwA5xD


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

🔗 https://t.co/Yr6pueoWgx


3️⃣ Pattern generator

- It lets you create background pattern for free

🔗 https://t.co/NQuV7pxLIz


4️⃣ CSS Accordion Slider Generator

- Create fully responsive, css only accordion sliders

🔗 https://t.co/x0qaDhN0z9
I've brought you some amazing GitHub repositories of web development tips and tricks 🌟

THREAD🧵🔽

1️⃣ JS Tips

- A huge list of 73 great tips and tricks of JavaScript

🔗
https://t.co/r0J9vW8WrH


2️⃣ CSS Protips

- A collection of tips to help take your CSS skills pro. Definitely check it out

🔗 https://t.co/5haB2xTWuz


3️⃣ JS Tips and Tricks

- Some advanced tips and tricks of JavaScript that can help you to take your skills onto next level

🔗 https://t.co/NvfoANwweV


4️⃣ Git Tips

- Git is an essential tool for very programmer. in this repo you'll find the most commonly used git tips and tricks

🔗 https://t.co/34qvOhYCZE
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

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
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

You May Also Like

हिमालय पर्वत की एक बड़ी पवित्र गुफा थी।उस गुफा के निकट ही गंगा जी बहती थी।एक बार देवर्षि नारद विचरण करते हुए वहां आ पहुंचे।वह परम पवित्र गुफा नारद जी को अत्यंत सुहावनी लगी।वहां का मनोरम प्राकृतिक दृश्य,पर्वत,नदी और वन देख उनके हृदय में श्रीहरि विष्णु की भक्ति अत्यंत बलवती हो उठी।


और देवर्षि नारद वहीं बैठकर तपस्या में लीन हो गए।इन्द्र नारद की तपस्या से घबरा गए।उन्हें हमेशा की तरह अपना सिंहासन व स्वर्ग खोने का डर सताने लगा।इसलिए इन्द्र ने नारद की तपस्या भंग करने के लिए कामदेव को उनके पास भेज दिया।वहां पहुंच कामदेव ने अपनी माया से वसंतऋतु को उत्पन्न कर दिया।


पेड़ और पौधों पर रंग बिरंगे फूल खिल गए और कोयलें कूकने लगी,पक्षी चहकने लगे।शीतल,मंद,सुगंधित और सुहावनी हवा चलने लगी।रंभा आदि अप्सराएं नाचने लगीं ।किन्तु कामदेव की किसी भी माया का नारद पे कोई प्रभाव नहीं पड़ा।तब कामदेव को डर सताने लगा कि कहीं नारद क्रोध में आकर मुझे श्राप न देदें।

जैसे ही नारद ने अपनी आंखें खोली, उसी क्षण कामदेव ने उनसे क्षमा मांगी।नारद मुनि को तनिक भी क्रोध नहीं आया और उन्होने शीघ्र ही कामदेव को क्षमा कर दिया।कामदेव प्रसन्न होकर वहां से चले गए।कामदेव के चले जाने पर देवर्षि के मन में अहंकार आ गया कि मैने कामदेव को हरा दिया।

नारद फिर कैलाश जा पहुंचे और शिवजी को अपनी विजयगाथा सुनाई।शिव समझ गए कि नारद अहंकारी हो गए हैं और अगर ये बात विष्णु जी जान गए तो नारद के लिए अच्छा नहीं होगा।ये सोचकर शिवजी ने नारद को भगवन विष्णु को ये बात बताने के लीए मना किया। परंतु नारद जी को ये बात उचित नहीं लगी।
Funny, before the election I recall lefties muttering the caravan must have been a Trump setup because it made the open borders crowd look so bad. Why would the pro-migrant crowd engineer a crisis that played into Trump's hands? THIS is why. THESE are the "optics" they wanted.


This media manipulation effort was inspired by the success of the "kids in cages" freakout, a 100% Stalinist propaganda drive that required people to forget about Obama putting migrant children in cells. It worked, so now they want pics of Trump "gassing children on the border."

There's a heavy air of Pallywood around the whole thing as well. If the Palestinians can stage huge theatrical performances of victimhood with the willing cooperation of Western media, why shouldn't the migrant caravan organizers expect the same?

It's business as usual for Anarchy, Inc. - the worldwide shredding of national sovereignty to increase the power of transnational organizations and left-wing ideology. Many in the media are true believers. Others just cannot resist the narrative of "change" and "social justice."

The product sold by Anarchy, Inc. is victimhood. It always boils down to the same formula: once the existing order can be painted as oppressors and children as their victims, chaos wins and order loses. Look at the lefties shrieking in unison about "Trump gassing children" today.