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

If you know CSS then you can use these amazing generators and save your time

Thread 🧵👇🏻

1️⃣ CSS Box Shadow Generator

- Generate CSS3 Box Shadow code for your Div, Frame, Buttons or any other HTML element with Outline, and Inset (inner) type shadow effects

🔗
https://t.co/6La36IzBLj


2️⃣ Glassmorphism

- Generate glassmorphic design easily

🔗 https://t.co/qrKqDV5tzY


3️⃣ Cool Backgrounds

- Explore a beautifully curated selection of cool backgrounds that you can add to your next project

🔗 https://t.co/df7VSaRSh9


4️⃣ Pixel art

- Create CSS pixel art, export the results to CSS and download them.

🔗 https://t.co/ojD8qwzuhx
If you start with the right course then the process becomes a little easier

I found some amazing YouTube videos and courses that will help you start your Web Development journey

🧵👇🏻

HTML and CSS

- A great way to arouse your web dev journey with Gary's (@designcoursecom) course on YouTube

🔗
https://t.co/xjm7nfV2L2


JavaScript

- Although it's impossible to learn JavaScript in 2 hours but JavaScript mastery is one the best YouTube chanel for JavaScript. This 2 hours long crash course will help you start your journey and gives you quick overview.

🔗 https://t.co/1zcSeu4zKE


Git and GitHub

Git is an essential tool. And after learning JavaScript, I think one should go for Git and GitHub. Check out this free great course on Udemy

🔗 https://t.co/E14cibOLXb


React

What you'll learn
- what problems React can solve
- how React solves those problems under the hood
- what JSX is and how it translates to regular JavaScript function calls and objects
- manage state with hooks
- build forms

🔗 https://t.co/3z22aeVQFc
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

More from Webdev

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.

🔗
https://t.co/W1XytKL1MI


2️⃣ HTML best practice

- A very well written document on HTML best practice

🔗 https://t.co/6PTcY1U5Cw


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

🔗 https://t.co/LwY9E2qUNS


4️⃣ Hex Invaders

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

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

You May Also Like

क्या आप जानते हैं कि क्या है, पितृ पक्ष में कौवे को खाना देने के पीछे का वैज्ञानिक कारण!

श्राद्ध पक्ष में कौओं का बड़ा ही महत्व है। कहते है कौआ यम का प्रतीक है, यदि आपके हाथों दिया गया भोजन ग्रहण कर ले, तो ऐसा माना जाता है कि पितरों की कृपा आपके ऊपर है और वे आपसे ख़ुश है।


कुछ लोग कहते हैं की व्यक्ति मरकर सबसे पहले कौवे के रूप में जन्म लेता है और उसे खाना खिलाने से वह भोजन पितरों को मिलता है

शायद हम सबने अपने घर के किसी बड़े बुज़ुर्ग, किसी पंडित या ज्योतिषाचार्य से ये सुना होगा। वे अनगिनत किस्से सुनाएंगे, कहेंगे बड़े बुज़ुर्ग कह गए इसीलिए ऐसा करना

शायद ही हमें कोई इसके पीछे का वैज्ञानिक कारण बता सके।

हमारे ऋषि मुनि और पौराणिक काल में रहने वाले लोग मुर्ख नहीं थे! कभी सोचियेगा कौवों को पितृ पक्ष में खिलाई खीर हमारे पूर्वजों तक कैसे पहुंचेगी?

हमारे ऋषि मुनि विद्वान थे, वे जो बात करते या कहते थे उसके पीछे कोई न कोई वैज्ञानिक कारण छुपा होता था।

एक बहुत रोचक तथ्य है पितृ पक्ष, भादो( भाद्रपद) प्रकृति और काक के बीच।

एक बात जो कह सकते कि हम सब ने स्वतः उग आये पीपल या बरगद का पेड़/ पौधा किसी न किसी दीवार, पुरानी

इमारत, पर्वत या अट्टालिकाओं पर ज़रूर देखा होगा। देखा है न?

ज़रा सोचिये पीपल या बरगद की बीज कैसे पहुंचे होंगे वहाँ तक? इनके बीज इतने हल्के भी नहीं होते के हवा उन्हें उड़ाके ले जा सके।