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
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
Top 5 free APIs for web developers
🧵👇
1️⃣ Custom Search API
- Create your own custom search engine. You can search for image, videos, and news.
🔗 https://t.co/nTvv3c3W06
2️⃣ Movie Database API
- Access movie and TV information similar to that of IMDB.
🔗
3️⃣ Dad Jokes API
- Get random endless dad jokes
🔗
4️⃣ COVID-19 Data API
- Every 15 minutes updated statistic about Coronavirus. Latest stats by country, are collected from several reliable sources.
🔗
🧵👇
1️⃣ Custom Search API
- Create your own custom search engine. You can search for image, videos, and news.
🔗 https://t.co/nTvv3c3W06
2️⃣ Movie Database API
- Access movie and TV information similar to that of IMDB.
🔗
3️⃣ Dad Jokes API
- Get random endless dad jokes
🔗
4️⃣ COVID-19 Data API
- Every 15 minutes updated statistic about Coronavirus. Latest stats by country, are collected from several reliable sources.
🔗
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
🧵👇🏻
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