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
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
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
JavaScript is powerful.
But sometimes, you can do great things using CSS.
A long thread of CSS tips and tricks:
1. Smooth
2. Change marker styling
3. Add styling to video
4. Change input caret
But sometimes, you can do great things using CSS.
A long thread of CSS tips and tricks:
1. Smooth
CSS Tip\U0001f4a1
— Pratham (@Prathkum) February 11, 2021
Enable smooth scrolling for the whole page\U0001f447 pic.twitter.com/E7QERt6V3Y
2. Change marker styling
3. Add styling to video
CSS Pro Tip \U0001f3a8
— Pratham (@Prathkum) April 11, 2021
You can style the subtitles of video on your website using ::cue pseudo-element pic.twitter.com/fV56PmxkX7
4. Change input caret
CSS tip\U0001f3a8
— Pratham (@Prathkum) February 23, 2021
You can change the input caret color using CSS\U0001f447
\u27b8 The\xa0caret\xa0is typically a thin vertical line that flashes to help the text area more noticeable pic.twitter.com/VA0paD7d2a
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
More from Webdev
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