<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Mihaela</title>
    <description>The latest articles on Forem by Mihaela (@mihaelapopa).</description>
    <link>https://forem.com/mihaelapopa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F511756%2Fcb045d38-5dac-4119-ba66-28c8c76d9614.jpeg</url>
      <title>Forem: Mihaela</title>
      <link>https://forem.com/mihaelapopa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mihaelapopa"/>
    <language>en</language>
    <item>
      <title>Building An Infinite Scroll Into Your React App</title>
      <dc:creator>Mihaela</dc:creator>
      <pubDate>Wed, 08 Jun 2022 15:57:07 +0000</pubDate>
      <link>https://forem.com/workshub/building-an-infinite-scroll-into-your-react-app-4f6b</link>
      <guid>https://forem.com/workshub/building-an-infinite-scroll-into-your-react-app-4f6b</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;Infinite scroll has become a major feature in apps we use in our day to day life like Twitter Instagram and just generally content feed apps that just want your undivided attention daily, on a functionality point of view infinite scroll outperforms pagination approaches to loading data due to it being seamless to the user and only loads more data when the user reaches the end of the scroll.&lt;/p&gt;

&lt;h4&gt;
  
  
  Infinite scroll
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;Infinite scroll&lt;/code&gt; is  a feature where data is loaded onto the user’s page when the user reaches the end or almost the end of the scroll page, this is done by calling a paginated API,&lt;br&gt;
A paginated API for reference is an API that returns a list of data whenever we call the API and can return different sets of data based on the page count that we passed into it an example of a paginated API would be the API we use in this example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`https://jsonplaceholder.typicode.com/photos?_page=${page}&amp;amp;_limit=10`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;page&lt;/code&gt; is the variable we pass into the API it is going to be a number that we track and increment after loading every page. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Infinite scroll&lt;/code&gt; although an excellent approach to loading data isn't the most optimal  for all projects,  some projects do function better with pagination, but infinite scrolling works best when loading related data that is loaded in a preferably chronological order based on time or relevance, pagination though is useful when users need to load data that far back, let's say you have some bank transaction records and you know that the records are a month away you can skip to the farthest page and circle back if you overshoot the page,  but in reality, infinite scroll and a good date filter  can solve that problem &lt;/p&gt;

&lt;h4&gt;
  
  
  Prerequisite
&lt;/h4&gt;

&lt;p&gt;Building this application would require some basic knowledge of a couple of things we would be using in our application.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React&lt;/li&gt;
&lt;li&gt;Javascript&lt;/li&gt;
&lt;li&gt;REST API’s &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Implementation
&lt;/h3&gt;

&lt;p&gt;In react we have 2 options to implement infinite scroll in our app.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using an exciting library (The smart boring way)&lt;/li&gt;
&lt;li&gt;Implement the infinite scroll (The fun slow way)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Using an exciting library (The smart boring way)
&lt;/h4&gt;

&lt;p&gt;A fast way to implement infinite scrolling in react would be to use a third-party library one of my go-to libraries for this feature would be the &lt;code&gt;react-infinite-scroll-component&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;react-infinite-scroll-component&lt;/code&gt; is a simple library that exports an &lt;code&gt;&amp;lt;InfiniteScroll/&amp;gt;&lt;/code&gt; component that can be used in our application and its feature-rich with props and events you can call before and after loading more data into the app, also a cool thing would be a refresh function you can call whenever you want to load new data to the top of your table.&lt;/p&gt;

&lt;h4&gt;
  
  
  Installing
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; npm install --save react-infinite-scroll-component
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add react-infinite-scroll-component
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In our &lt;code&gt;App.jsx&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; import React from "react";
import InfiniteScroll from "react-infinite-scroll-component";
import axios from "axios";

let page = 1;
const fetchData = (setItems, items) =&amp;gt; {
 axios
   .get(`https://jsonplaceholder.typicode.com/photos?_page=${page}&amp;amp;_limit=10`)
   .then((res) =&amp;gt; {
     setItems([...items, ...res.data]);
     page = page + 1;
   });
};

const refresh = (setItems) =&amp;gt; {};

export default function App() {
 const [items, setItems] = React.useState([]);

 React.useEffect(()=&amp;gt;{
   fetchData(setItems,items)
 },[])
 return (
   &amp;lt;InfiniteScroll
     dataLength={items.length} //This is important field to render the next data
     next={() =&amp;gt; {
       fetchData(setItems, items);
     }}
     hasMore={true}
     loader={&amp;lt;h4&amp;gt;Loading...&amp;lt;/h4&amp;gt;}
     endMessage={
       &amp;lt;p style={{ textAlign: "center" }}&amp;gt;
         &amp;lt;b&amp;gt;Yay! You have seen it all&amp;lt;/b&amp;gt;
       &amp;lt;/p&amp;gt;
     }
     // below props only if you need pull down functionality
     refreshFunction={refresh}
     pullDownToRefresh
     pullDownToRefreshThreshold={50}
     pullDownToRefreshContent={
       &amp;lt;h3 style={{ textAlign: "center" }}&amp;gt;&amp;amp;#8595; Pull down to refresh&amp;lt;/h3&amp;gt;
     }
     releaseToRefreshContent={
       &amp;lt;h3 style={{ textAlign: "center" }}&amp;gt;&amp;amp;#8593; Release to refresh&amp;lt;/h3&amp;gt;
     }
   &amp;gt;
     &amp;lt;div style={{ minHeight: "100vh" }}&amp;gt;
       {items.map((user) =&amp;gt; (
         &amp;lt;img src={user.url} height="100px" width="200px" /&amp;gt;
       ))}
     &amp;lt;/div&amp;gt;
   &amp;lt;/InfiniteScroll&amp;gt;
 );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's break our code down into smaller bits.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let page = 1;
const fetchData = (setItems, items) =&amp;gt; {
 axios
   .get(`https://jsonplaceholder.typicode.com/photos?_page=${page}&amp;amp;_limit=10`)
   .then((res) =&amp;gt; {
     setItems([...items, ...res.data]);
     page = page + 1;
   });
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;fetch&lt;/code&gt; function is able to call our API to get new data it's triggered by the &lt;code&gt;&amp;lt;InfiniteScroll/&amp;gt;&lt;/code&gt; component when we scroll to the end of the view, there is a count variable we use to monitor the page loaded and it is incremented after the data is loaded.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const [items, setItems] = React.useState([]);
 React.useEffect(()=&amp;gt;{
   fetchData(setItems,items)
 },[])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;React effect is used to load the first batch of data into the view, we pass the systems function and the items variable into the function (something new I should have been doing a while back to remove API calls from my component)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;InfiniteScroll
     dataLength={items.length} //This is important field to render the next data
     next={() =&amp;gt; {
       fetchData(setItems, items);
     }}
     hasMore={true}&amp;gt;
/////// 

/// code
///////
&amp;gt;
     &amp;lt;div style={{ minHeight: "100vh" }}&amp;gt;
       {items.map((user) =&amp;gt; (
         &amp;lt;img src={user.url} height="100px" width="200px" /&amp;gt;
       ))}
     &amp;lt;/div&amp;gt;
   &amp;lt;/InfiniteScroll&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We call our component and pass data into it if you need documentation you can check it out here &lt;code&gt;https://www.npmjs.com/package/react-infinite-scroll-component&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here is the output.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zxIuw1hQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/63994c51f91d4fd976945fbf5556c808" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zxIuw1hQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/63994c51f91d4fd976945fbf5556c808" alt="Screen Shot 2022-05-22 at 4.05.48 PM.png" width="880" height="472"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Implement the infinite scroll (The fun way)
&lt;/h4&gt;

&lt;p&gt;Implementing a scroll component can be a nice learning project and gives you more control than when you use a component and is pretty easy to set up but can take a bit of time to perform research on how to get it done, luckily I've done that for you.&lt;/p&gt;

&lt;h4&gt;
  
  
  Pros of using custom components
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Customizable&lt;/li&gt;
&lt;li&gt;Very light since its just one component &lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Cons
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Takes a bit of time to set up&lt;/li&gt;
&lt;li&gt;It May is not as robust as an already built component&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Here is our codebase
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { Component } from "react";

class ScrollComponent extends Component {
 constructor() {
   super();
   this.state = {
     loading: false,
     page: 0,
     prevY: 0
   };
 }

 async getItems() {
   try {
     await this.props.loadData();
   } catch (error) {
     console.log(error);
   }
 }

 componentDidMount() {
   this.getItems();

   var options = {
     root: null,
     rootMargin: "0px",
     threshold: 1.0
   };

   this.observer = new IntersectionObserver(
     this.handleObserver.bind(this),
     options
   );
   this.observer.observe(this.loadingRef);
 }

 async handleObserver(entities, observer) {
   const y = entities[0].boundingClientRect.y;
   if (this.state.prevY &amp;gt; y) {
     this.setState({ loading: true });
     console.log(this.state);

     await this.getItems();

     this.setState({ loading: false });
     console.log(this.state);
   }
   this.setState({ prevY: y });
 }

 render() {
   // Additional css
   const loadingCSS = {
     height: "100px",
     margin: "30px"
   };

   // To change the loading icon behavior
   const loadingTextCSS = { display: this.state.loading ? "block" : "none" };

   return (
     &amp;lt;div className="container"&amp;gt;
       &amp;lt;div style={{ minHeight: "800px" }}&amp;gt;
         {/* {this.state.photos.map(user =&amp;gt; (
          &amp;lt;img src={user.url} height="100px" width="200px" /&amp;gt;
        ))} */}
         {this.props.children}
       &amp;lt;/div&amp;gt;
       &amp;lt;div
         className="house"
         ref={(loadingRef) =&amp;gt; (this.loadingRef = loadingRef)}
         style={loadingCSS}
       &amp;gt;
         &amp;lt;span style={loadingTextCSS}&amp;gt;Loading...&amp;lt;/span&amp;gt;
       &amp;lt;/div&amp;gt;
     &amp;lt;/div&amp;gt;
   );
 }
}

export default ScrollComponent;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And in our &lt;code&gt;app.jsx&lt;/code&gt; component we replace the &lt;code&gt;&amp;lt;InfiniteScroll/&amp;gt;&lt;/code&gt; and insert our new component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";
import axios from "axios";
import ScrollComponent from "./scroll";

let page = 1;
const fetchData = async (setItems, items) =&amp;gt; {
 const data = await axios.get(
   `https://jsonplaceholder.typicode.com/photos?_page=${page}&amp;amp;_limit=10`
 );

 setItems([...items, ...data.data]);
 page = page + 1;
};

const refresh = (setItems) =&amp;gt; {};

export default function App() {
 const [items, setItems] = React.useState([]);

 React.useEffect(() =&amp;gt; {
   fetchData(setItems, items);
 }, []);
 return (
   &amp;lt;ScrollComponent
     loadData={() =&amp;gt; {
       fetchData(setItems, items);
     }}
   &amp;gt;
     &amp;lt;div style={{ minHeight: "100vh" }}&amp;gt;
       {items.map((user) =&amp;gt; (
         &amp;lt;img
           key={Math.random()}
           src={user.url}
           height="100px"
           width="200px"
         /&amp;gt;
       ))}
     &amp;lt;/div&amp;gt;
   &amp;lt;/ScrollComponent&amp;gt;
 );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's break our component down into smaller bits so we can understand it.&lt;/p&gt;

&lt;h5&gt;
  
  
  Part 1
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; componentDidMount() {
   this.getItems();

   var options = {
     root: null,
     rootMargin: "0px",
     threshold: 1.0
   };

   this.observer = new IntersectionObserver(
     this.handleObserver.bind(this),
     options
   );
   this.observer.observe(this.loadingRef);
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our &lt;code&gt;componentDidMount&lt;/code&gt; function is run as soon as our component is started and adds an   &lt;code&gt;IntersectionObserver&lt;/code&gt;  observer to the component that checks out the &lt;code&gt;house&lt;/code&gt; and measures the difference between it and the  &lt;code&gt;this.props.children&lt;/code&gt; and calls the &lt;code&gt;handleObserver&lt;/code&gt;  function when the observer is triggered.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; async handleObserver(entities, observer) {
   const y = entities[0].boundingClientRect.y;
   if (this.state.prevY &amp;gt; y) {
     this.setState({ loading: true });
     console.log(this.state);

     await this.getItems();

     this.setState({ loading: false });
     console.log(this.state);
   }
   this.setState({ prevY: y });
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our &lt;code&gt;handleObserver&lt;/code&gt; example function calls out the update function that's passed into the props, this is powerful because we can use the concept of dependency injection to pass in the update function from our component making this component agnostic to its use case&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const [items, setItems] = React.useState([]);

 React.useEffect(() =&amp;gt; {
   fetchData(setItems, items);
 }, []);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We take advantage of react useEffect to set up how we manage data in our component, we need to pass &lt;code&gt;setItems&lt;/code&gt; and &lt;code&gt;items&lt;/code&gt; into  the fetchdata component to pass control initoo the function,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; render() {
   // Additional css
   const loadingCSS = {
     height: "100px",
     margin: "30px"
   };

   // To change the loading icon behavior
   const loadingTextCSS = { display: this.state.loading ? "block" : "none" };

   return (
     &amp;lt;div className="container"&amp;gt;
       &amp;lt;div style={{ minHeight: "800px" }}&amp;gt;
         {/* {this.state.photos.map(user =&amp;gt; (
           &amp;lt;img src={user.url} height="100px" width="200px" /&amp;gt;
         ))} */}
         {this.props.children}
       &amp;lt;/div&amp;gt;
       &amp;lt;div
Class = ‘house’
         ref={(loadingRef) =&amp;gt; (this.loadingRef = loadingRef)}
         style={loadingCSS}
       &amp;gt;
         &amp;lt;span style={loadingTextCSS}&amp;gt;Loading...&amp;lt;/span&amp;gt;
       &amp;lt;/div&amp;gt;
     &amp;lt;/div&amp;gt;
   );
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our render function renders our child component passed into the component, this lets us reuse our component for different types of use cases.&lt;/p&gt;

&lt;p&gt;Replacing our component in the &lt;code&gt;App.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;ScrollComponent loadData={()=&amp;gt;{
     fetchData(setItems, items);
   }}&amp;gt;
     &amp;lt;div style={{ minHeight: "100vh" }}&amp;gt;
       {items.map((user) =&amp;gt; (
         &amp;lt;img src={user.url} height="100px" width="200px" /&amp;gt;
       ))}
     &amp;lt;/div&amp;gt;
   &amp;lt;/ScrollComponent&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our output(similar to our old implementation).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zxIuw1hQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/63994c51f91d4fd976945fbf5556c808" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zxIuw1hQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/63994c51f91d4fd976945fbf5556c808" alt="Screen Shot 2022-05-22 at 4.05.48 PM.png" width="880" height="472"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Infinite scrolling&lt;/code&gt; is becoming an amazing way of showing feed data because it offers a nonstop flow of data that is addictive (talking from a users point of view) and only loads new data when it reaches the end of the page, this is done by monitoring the page count and incrementing the page seen page at the end of every load.&lt;/p&gt;

&lt;p&gt;In this guide, we learned 2 different modes of implementing this feature in react, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using an exciting library (The smart boring way)&lt;/li&gt;
&lt;li&gt;Implement the infinite scroll (The fun way)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each approach gives the same result but comes with different pros and cons that make them perfect for different situations, I personally keep a copy of my own custom component on my PC and copy the custom component into my new project,  it helps to keep it flexible for different project seeing as it is just a component and can be called whenever it's needed, also the concept of injecting the load function makes it easy to use and re-use across projects.&lt;/p&gt;

&lt;p&gt;I hope this article was helpful to you, cheers and till next time!&lt;/p&gt;

&lt;h4&gt;
  
  
  Referrence
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.pluralsight.com/guides/how-to-implement-infinite-scrolling-with-reactjs"&gt;Gaurav Singhal&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Originally written by &lt;a href="https://javascript.works-hub.com/users/8cedbde0-2e7b-4328-8741-f8c981f0b076?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;King Somto&lt;/a&gt; for &lt;a href="https://javascript.works-hub.com/learn/building-a-modular-infinite-scroll-252dd?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;JavaScript Works&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactlearning</category>
      <category>reactiveprogramming</category>
    </item>
    <item>
      <title>JavaScript Libraries You Should Try Out in 2022</title>
      <dc:creator>Mihaela</dc:creator>
      <pubDate>Wed, 08 Jun 2022 15:56:34 +0000</pubDate>
      <link>https://forem.com/workshub/javascript-libraries-you-should-try-out-in-2022-4b4p</link>
      <guid>https://forem.com/workshub/javascript-libraries-you-should-try-out-in-2022-4b4p</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F408b4fba1d5746f4bbfdb5f38b943d55" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F408b4fba1d5746f4bbfdb5f38b943d55" alt="JavaScript Libraries.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;JavaScript libraries have been changing the way we write JavaScript and have helped us in accomplishing our goals easily without the hassle of reinventing the wheel over and over again. That’s why JavaScript libraries are one of the first things that any developer should be aware of when starting out in this industry. Every year, new libraries are developed, old ones are abandoned, and all existing ones need to be updated with the latest advancements made by developers around the world.&lt;/p&gt;

&lt;p&gt;But what’s so special about these libraries that they deserve special attention? These libraries promise to make coding faster, easier, and overall more enjoyable. I recommend taking some time out in 2022 to take them for a spin!&lt;/p&gt;

&lt;p&gt;Here’s a list of the ones you should try out in 2022 if you haven’t already started to work with them. They may not be the most popular right now, but I predict they will be in three years!&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction to JavaScript Libraries 2022
&lt;/h2&gt;

&lt;p&gt;JavaScript is an ever-changing language, meaning that new JS libraries are constantly emerging, and new approaches to JavaScript coding are also being developed. In order to maintain relevance within your industry, it’s important to keep up with these developments. This post will introduce you to a few latest version libraries that you should familiarize yourself with if you want to keep up with future developments within JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Top JavaScript Libraries in 2022
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. jQuery
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F087c48167f7a2d3f97cdd0147542cd8c" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F087c48167f7a2d3f97cdd0147542cd8c" alt="jquery.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The jQuery library is a free software library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. It was released on June 11, 2006, at BarCamp NYC by John Resig. According to JavaScript analytics service Libscore, jQuery is used on more than 60% of all websites whose front-end code can be evaluated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Characteristics&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fast, small, and feature-rich library&lt;/li&gt;
&lt;li&gt;It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Application&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Best used for creating beautiful animations&lt;/li&gt;
&lt;li&gt;It is used for both client-side and server-side scripting.&lt;/li&gt;
&lt;li&gt;Manipulate HTML documents and develop web applications&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. D3.js
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F10e4aa18b720a47bd8c3b09ffa501de3" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F10e4aa18b720a47bd8c3b09ffa501de3" alt="d3.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to life using HTML, CSS, and SVG. D3’s emphasis on web page standards gives you the full capabilities of modern browsers without tying yourself to a proprietary framework, combining powerful visualization components and a data-driven approach to DOM manipulation. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Characteristics&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Supports HTML, CSS, and SVG&lt;/li&gt;
&lt;li&gt;Manipulate the DOM by using a Data-driven approach&lt;/li&gt;
&lt;li&gt;D3.js is a powerful JavaScript library that allows you to create data visualizations using web standards&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Applications&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Allows you to bind arbitrary data to a Document Object Model (DOM)&lt;/li&gt;
&lt;li&gt;Helps to create animated transitions&lt;/li&gt;
&lt;li&gt;D3.js is a powerful JavaScript library that allows for high-level data visualization.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. React.js
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2Fe998ff636792354cc96ed9fec209a224" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2Fe998ff636792354cc96ed9fec209a224" alt="react js.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In simple terms, React.js is a JavaScript library for &lt;a href="https://javascript.works-hub.com/learn/styling-components-in-react-b9673" rel="noopener noreferrer"&gt;building user interfaces&lt;/a&gt;. These are interactive web applications that run on various devices with access to data from back-end servers. The first version of React was released by Facebook in 2011. The technology was developed by Jordan Walke and his team at Facebook’s Instagram subsidiary (which has since been separated into its own company).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Characteristics&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React.js is a library for building interactive user interfaces&lt;/li&gt;
&lt;li&gt;It's composed of reusable UI components that make it easy to create complex and responsive user interfaces without sacrificing performance or SEO.&lt;/li&gt;
&lt;li&gt;It makes use of JavaScript’s ability to manipulate DOM elements and CSS to allow more expressive content presentation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Applications&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is a lightweight JavaScript library that offers a number of additional, convenient features to developers.&lt;/li&gt;
&lt;li&gt;It may not be as comprehensive as other libraries, but it makes up for it with better performance and ease of use.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Lodash
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2Faaa2654039438353c038bc3169c85089" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2Faaa2654039438353c038bc3169c85089" alt="Lodash.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;JavaScript is one of the most widely used programming languages for web design. It has many interesting libraries, but Lodash is among my personal favorites because it’s easy to learn and use, super flexible, and this is a utility library that provides methods and functions on top of JavaScript's native objects to developers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Characteristics&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is a modern JavaScript utility library delivering modularity, performance &amp;amp; extras.&lt;/li&gt;
&lt;li&gt;It is a JavaScript utility library delivering consistency, modularity, performance &amp;amp; extras.&lt;/li&gt;
&lt;li&gt;All Lodash methods are chainable and iteratee-first for cleaner code and better readability.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Applications&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With Lodash, you can format the date and convert it to a string.&lt;/li&gt;
&lt;li&gt;It is a feature-rich library that provides methods for functional programming and helps you write cleaner code by minimizing the verbosity of everyday tasks.&lt;/li&gt;
&lt;li&gt;Lodash comes with all sorts of goodies to help make working with arrays, objects, strings, numbers, etc., easier and more fun.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. Underscore.js
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2Fda9b0ce8ab1b67ce378fe19dc15b124a" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2Fda9b0ce8ab1b67ce378fe19dc15b124a" alt="underscorejs.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Underscore.js is a library that helps you get more out of your JavaScript applications. It’s most commonly used as a utility library, providing lots of functional programming helpers without extending any built-in objects. While developers often use Underscore simply as a utility belt for everyday scripting tasks, it has become very popular with &lt;a href="https://javascript.works-hub.com/frontend-development-jobs" rel="noopener noreferrer"&gt;front-end developers&lt;/a&gt;, due to its role in Backbone.js and other MVC frameworks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Characteristics&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is a utility-belt library for JavaScript that provides a lot of functional programming support.&lt;/li&gt;
&lt;li&gt;It’s small (about 8kb minified and gzipped), and it doesn’t take much to start using it.&lt;/li&gt;
&lt;li&gt;It’s ideal for writing concise code to perform multiple operations on arrays and objects.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Applications&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is a library for JavaScript that provides a whole mess of useful functional programming helpers without extending any built-in objects.&lt;/li&gt;
&lt;li&gt;It’s a dependency of Backbone.js but is also very useful on its own.&lt;/li&gt;
&lt;li&gt;Underscore.js is a JavaScript library that provides a variety of functional programming helpers without extending any built-in objects, just like Prototype.js and other competitors.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Some Useful JavaScript Frameworks That You Must be Known
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Aurelia
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2Fd4f8176733762270158c8cb130a97067" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2Fd4f8176733762270158c8cb130a97067" alt="Aurelia .png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Aurelia is a powerful open-source JavaScript client-side framework that features advanced tooling and state-of-the-art UI components. It offers data binding, templating, MVVM, and more. Aurelia is compatible with multiple browsers and operating systems.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Ember.js
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2Fd06a34c435c59362a80a394c2e670fe0" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2Fd06a34c435c59362a80a394c2e670fe0" alt="ember .png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to create a powerful web application, then you should definitely check out Ember cli. It offers a smooth user experience and has great documentation. The framework is written in JavaScript and HTML5, making it easy for developers to understand. This also makes it easier for them to learn how to use it quickly and effectively.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Node.js
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F4499a2bfa6f9c2d602a73e4274441eca" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F4499a2bfa6f9c2d602a73e4274441eca" alt="node js .png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Node.js, or Node, is an open-source and cross-platform JavaScript run-time environment for developing server-side web applications. Node runs on Chrome’s V8 JavaScript engine. Because of its event-driven architecture, non-blocking I/O model, and lightweight design, it is often used for real-time applications that are data-intensive and require a large number of concurrent connections.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Mocha
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F5275a28842c52bf15887443704957b83" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F5275a28842c52bf15887443704957b83" alt="mocha js  .png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Mocha is a test framework for Node.js and browsers, making asynchronous unit testing painless.  It's easy to write tests with mocha because it handles all of that annoying setup code you don't want to write.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best JavaScript Tools
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. iziModal
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2Ffc4ba9971fac4fae3c9c1f7e6ce34c56" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2Ffc4ba9971fac4fae3c9c1f7e6ce34c56" alt="IZIMODEL.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;iziModal is a lightweight and modular JavaScript library that allows you to create smooth and responsive modal dialogs. It works with any CSS framework, such as Bootstrap or Foundation. It is a modal component built with Vue.js, and it aims to provide an easy way to add a beautiful and flexible modal window to your application. &lt;/p&gt;

&lt;p&gt;It’s lightweight (2kb gzipped), simple to use, customizable, and has no dependencies. iziModal can be used anywhere you need a modal window: from websites to mobile applications or even desktop applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Shave
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F24276f462dd4657dae022928eaa7d7ad" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F24276f462dd4657dae022928eaa7d7ad" alt="SHAVE .png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The shave is one of the most useful tools in JavaScript. It allows you to use CSS selectors to get elements from your HTML and manipulate them with JavaScript, just like jQuery, but without the jQuery dependency. This makes it ideal for projects that don’t need all of jQuery’s features.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Webpack
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F917ae799a1ac63b8c6fda892add6c8e0" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F917ae799a1ac63b8c6fda892add6c8e0" alt="WEBPACK .png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Webpack is a module bundler that simplifies web development by handling asset management and builds. Webpack works with any type of library or framework. It can bundle CSS, LESS, SASS, CoffeeScript, TypeScript, and more. It also has plugins for other languages like Java, C++, PHP, etc.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Babel
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F36cb7a6cbedbdc3706db34a1c7281ec6" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F36cb7a6cbedbdc3706db34a1c7281ec6" alt="BABEL W-T.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Babel is a JavaScript compiler that helps you to use new features introduced by ECMAScript. It allows developers to write code using newer versions of JavaScript and then transpile it into backward-compatible code that can run on older versions of browsers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;For &lt;a href="https://javascript.works-hub.com/javascript-jobs" rel="noopener noreferrer"&gt;JavaScript developers&lt;/a&gt; looking to increase their repertoire of skills, it’s not always easy to choose which new technologies and practices you should keep an eye on. With an ever-growing number of new frameworks emerging all of the time, developers can find themselves lost in a sea of unfamiliar tools. Javascript libraries help you build great web and desktop applications, but it can be hard to choose the right one to get started with.&lt;/p&gt;

&lt;p&gt;There are thousands of articles online that try to predict what will be relevant in five years’ time—but these lists are rarely based on any criteria, and usually just include things that their authors think will be popular. &lt;/p&gt;

&lt;p&gt;I hope you've enjoyed reading my tutorial, and I wish you much success as you learn JavaScript libraries. If you liked it, please share it on social media! In addition, sign up for our newsletter to get the latest news about our articles.&lt;/p&gt;

&lt;p&gt;Originally written by &lt;a href="https://javascript.works-hub.com/users/69be7ad5-5182-4556-b20d-2bb48021093a?utm_source=dev_to&amp;amp;utm_medium=blog_xpost" rel="noopener noreferrer"&gt;Fawzan Hussain &lt;/a&gt; for &lt;a href="https://javascript.works-hub.com/learn/javascript-libraries-you-should-try-out-in-2022-3ef03?utm_source=dev_to&amp;amp;utm_medium=blog_xpost" rel="noopener noreferrer"&gt;JavaScript Works&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>library</category>
    </item>
    <item>
      <title>We’ll Plant a Tree for Every Job Application on Our Platform</title>
      <dc:creator>Mihaela</dc:creator>
      <pubDate>Wed, 25 May 2022 16:27:07 +0000</pubDate>
      <link>https://forem.com/workshub/well-plant-a-tree-for-every-job-application-on-our-platform-4fe</link>
      <guid>https://forem.com/workshub/well-plant-a-tree-for-every-job-application-on-our-platform-4fe</guid>
      <description>&lt;p&gt;At WorksHub, we’re committed to bringing positive change through the work we do every day. For that reason, we decided to step further than spreading awareness and take care of our climate impact.&lt;/p&gt;

&lt;p&gt;As a tech recruitment platform, our mission is to connect software engineers with the best company opportunities out there. &lt;/p&gt;

&lt;p&gt;So, we’re tightening the two together!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We’ll be planting a tree of every &lt;em&gt;job application&lt;/em&gt; on our platform.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We are thrilled to announce our sustainable partnership with &lt;a href="https://ecologi.com/workshub"&gt;Ecologi&lt;/a&gt; - a startup that works with tree planting organisations who are able to responsibly plant millions of trees a month on their community’s behalf. &lt;/p&gt;

&lt;p&gt;Can you plant a tree without actually getting out there in nature and digging a hole in the ground?&lt;/p&gt;

&lt;p&gt;YES, YOU CAN! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--spFnIFWt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/1092798e1bae069758d6a63a31d74314" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--spFnIFWt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/1092798e1bae069758d6a63a31d74314" alt="Plant a Tree with WorksHub.png" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now, why are we doing all this?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You've probably heard the phrase &lt;em&gt;"trees are the lungs of our planet"&lt;/em&gt; countless times. For our health and environment, it is indeed crucial to take action towards rehabilitation of one of the most important resources of our planet - forests.&lt;/p&gt;

&lt;p&gt;After all, trees provide us with life’s essentials, clean air and oxygen, clean water, better soil. &lt;/p&gt;

&lt;p&gt;According to &lt;a href="https://www.nationalgeographic.com/environment/article/deforestation"&gt;National Geographic&lt;/a&gt;, deforestation represents a human-driven and natural loss of trees that affects wildlife, ecosystems, weather patterns, and climate. Forests still cover about 30% of the world’s land area, but they are disappearing at an alarming rate. Since 1990, the world has lost 420 million hectares or about a billion acres of forest.&lt;/p&gt;

&lt;p&gt;This has had a catastrophic impact on climate change. Trees clean the air around us, the one we breathe, filter the water we drink, and provide habitat to over 80% of the world's terrestrial biodiversity. Forests provide jobs to over 1.6 billion people, absorb harmful carbon from the atmosphere, and are key ingredients in 25% of all medicines.&lt;/p&gt;

&lt;p&gt;One of the best and most accessible tools we have today to tackle the climate crisis and keep our temperatures from rising above 1.5C is to &lt;a href="https://www.bbc.co.uk/news/science-environment-48870920"&gt;plant trees&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://ecologi.com/workshub"&gt;Ecologi&lt;/a&gt; - our partners, know how important it is for our present and future, to take prevention steps now. This is why they formed this initiative group where they use donations to support a broad range of projects that are able to evidence that they are reducing greenhouse gas emissions through tree planting.&lt;/p&gt;

&lt;p&gt;Contributing has never been easier. While you are applying for your dream job, you’re also helping make our planet healthier and greener.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let’s plant trees, one application at a time 💚&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.works-hub.com/jobs"&gt;Apply today&lt;/a&gt; and plant a tree with WorksHub!&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Note: We will only count job applications that are approved by our screening software and available for review by the company that received them.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Originally written by &lt;a href="https://www.works-hub.com/users/f5a561bf-0584-4f1d-8436-77da6d8dbc00?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;Mihaela Popa&lt;/a&gt; for &lt;a href="https://www.works-hub.com/learn/well-plant-a-tree-for-every-job-application-on-our-platform-cd8bb?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;WorksHub&lt;/a&gt;&lt;/p&gt;

</description>
      <category>partnership</category>
      <category>announcement</category>
      <category>companyupdate</category>
    </item>
    <item>
      <title>Best Books On Crypto</title>
      <dc:creator>Mihaela</dc:creator>
      <pubDate>Wed, 23 Mar 2022 15:10:54 +0000</pubDate>
      <link>https://forem.com/workshub/best-books-on-crypto-51ae</link>
      <guid>https://forem.com/workshub/best-books-on-crypto-51ae</guid>
      <description>&lt;p&gt;Blockchain and cryptocurrencies have garnered a lot of popularity over the years. And, why not? It's because they can be decentralized, and the data is cryptographically encrypted, meaning no one can access it. Blockchain technology has revolutionarily changed everything, the digital ownership and privacy revolution will someday permeate our daily lives. &lt;/p&gt;

&lt;p&gt;Companies these days often use blockchain to secure how users send and receive money. Banking and investment make the most of blockchain technology more than any other industry. As a result of bitcoin, blockchain has grabbed the curiosity of everyone wishing to invest in recent years.&lt;/p&gt;

&lt;p&gt;You might purchase any random book about cryptocurrencies, but you've come to the correct spot if you're searching for professional guidance on which one is ideal for your requirements. We have investigated in-depth to include the best-rated solutions ideal for various use demands and budget ranges.&lt;/p&gt;

&lt;p&gt;Naturally, if you're interested in it, you'll want to learn more about it. The following is a list of best books on crypto that should be read in no particular order:&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Unlocking Digital Cryptocurrencies: Mastering Bitcoin
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SVltHfP_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/6cedb1c536eae47016fccc89abf4f380" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SVltHfP_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/6cedb1c536eae47016fccc89abf4f380" alt="Book1.png" width="880" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Mastering Bitcoin is a book by Andreas M. Antonopoulos intended for anybody who has a basic grasp of blockchain technology. This book takes a deep dive into bitcoin, and at the end of it, you'll be able to develop your cryptocurrency apps.&lt;/p&gt;

&lt;p&gt;"The Bitcoin Blockchain provides an altogether new foundation upon which our economy can develop, one that will enable an ecosystem as vast and diversified as the Internet itself." Andreas M. Antonopoulos, as one of the world's foremost thinkers, is the ideal candidate to write this book." — Roger Ver, Bitcoin investor and entrepreneur.&lt;br&gt;
Another book by the same author, "Mastering Ethereum," is a fascinating one to read as it explains smart contracts and adds an extra degree of security to Ethereum.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. How the Technology Behind Bitcoin Is Changing Money, Business, and the World: Blockchain Revolution.
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--c0gMQgCd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/2c5de82b2fe8145630c2254c61455fc1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--c0gMQgCd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/2c5de82b2fe8145630c2254c61455fc1" alt="Book2.png" width="880" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This book by Don Tapscott and Alex Tapscott has been listed 14 times out of 19 times on the Best of List, and it is by far the most popular Blockchain book. Don Tapscott is the CEO of the Tapscott Group and one of the world's most important business and social theorists. Don was rated the fourth most influential business thinker globally by Thinkers50 in November 2013. Don was named the most prominent management thinker globally by Forbes in prior social media research.&lt;/p&gt;

&lt;p&gt;Alex Tapscott is the CEO and co-founder of Northwest Passage Ventures, a blockchain advising business. He published the foundational study on controlling digital curren­cies for the Global Solutions Network program at the University of Toronto's Joseph L. Rotman School of Management in 2014.&lt;/p&gt;

&lt;p&gt;"A wonderfully written and meticulously researched book. The 'Internet of Value,' according to the Blockchain Revolution, will alter our lives. "This is a must-read book for our turbulent times," as quoted by (McKinsey &amp;amp; Company's worldwide managing director, Dominic Barton).&lt;/p&gt;

&lt;h2&gt;
  
  
  3.Bitcoin and the Inside Story of the Misfits and Millionaires Trying to Reinvent Money- Book- Digital Gold.
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RtBTLydb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/d75c5035eb6ac6e8d95d41bed1551e61" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RtBTLydb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/d75c5035eb6ac6e8d95d41bed1551e61" alt="Book3.png" width="880" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nathaniel Popper's book tells the exciting history of Bitcoin technology and its rapid rise to recognition as a digital currency system, thanks to the help of several notable figures.&lt;/p&gt;

&lt;p&gt;If you want to learn more about Bitcoin's history, this book is for you. It will take you on tour through Bitcoin's history, beginning with its inception. The author's background as a reporter (at The New York Times) lends itself to his ability to pull together unrelated events in a concise way. The complicated tale of Bitcoin is told in an easy-to-understand manner, with no jargon, keeping the reader captivated by the book. The development of Bitcoin technology is the subject of this book. It is clear for beginners to set their best first step into cryptocurrencies more speculatively.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. The Investor's Guide to Cryptocurrency and Defi, the Decentralized Finance Revolution: The Wall Street Era is Over.
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PguYH-e5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/5de49cbb531128cf71d2a2431684edc0" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PguYH-e5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/5de49cbb531128cf71d2a2431684edc0" alt="Book4.png" width="880" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Wall Street Era is Over by the experts who had been in DeFi explains how to succeed in DeFi, the industry that is paving the way for the Finance 3.0 revolution, and how to invest safely.' The Investor's Guide to Cryptocurrency and DeFi, the Decentralized Finance Revolution' is a comprehensive reference. &lt;/p&gt;

&lt;p&gt;It includes the following primary subjects and many others, like explaining the origins of DeFi and its function in cryptography. The difference between DeFi from traditional finance? DeFi's most essential protocols and how do DeFi protocols make money? The DeFi investor's guide. What is precisely yield farming, and why is it important? How to be a high-yield with crypto assets the innovative investor. How to invest in DeFi with confidence? It also explains the scams involving DeFi, how to avoid them, and how to contract auditing's role smartly. Finally, defining the future of DeFi, incorporating NFTs and other evolving technologies.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Idealism, Greed, Lies, and the Making of the First Big Cryptocurrency Craze-The Cryptopians.
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1rgJixmA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/e0bd98627b1da6d37b4ebffbfc4d7a4e" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1rgJixmA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/e0bd98627b1da6d37b4ebffbfc4d7a4e" alt="Book 5.png" width="880" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This book by Laura Shin takes readers behind the scenes of creating this new type of cryptocurrency network, which allowed users to create their new coins and sparked a new wave of crypto fever in the process. You'll meet people like Vitalik Buterin, the wunderkind whose idea grew into a $100 billion empire in five months; Charles Hoskinson, the project's first CEO who left after five months; and Joe Lubin, a former Goldman Sachs VP who became one of crypto's most well-known billionaires after his early involvement in Bitcoin and Ethereum. As these colossal egos battled for a share of an ostensibly boundless new commercial opportunity, sparks flared. &lt;/p&gt;

&lt;p&gt;This book tries to explain how cryptocurrency's fortunes rise and fall, but those striving to bring it mainstream make and lose futures and careers on it. Does this exciting book portray the cryptocurrency market for what it is? And explains how it's a highly personal fight to shape the coming revolution in money, culture, and power.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. The Fiat Standard: The Debt Slavery Alternative to Human Civilisation.
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gmSNgD0G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/ef81b45b9710621d74d1f82e67590e06" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gmSNgD0G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/ef81b45b9710621d74d1f82e67590e06" alt="Book 6.png" width="880" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This book by Economist Saifedean Ammous's most recent book is widely recognized as one of the classic publications on digital tokens. It discussed Bitcoin's monetary theory, the gold standard, fiat currencies, and contemporary financial reform thought.&lt;/p&gt;

&lt;p&gt;His follow-up book, The Fiat Standard: The Debt Slavery Alternative to Human Civilisation, is due out in 2021 and looks at national currencies as a technology, how debt underpins them, and how governments manage and add to this debt at no cost.&lt;/p&gt;

&lt;p&gt;Mr. Ammous connects the work to our current circumstances by examining the influence of fiat on family, food, health, education, and security. Finally, he considers how fiat currency and Bitcoin could coexist in the future and what would happen if one of them fails.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Cashless: China's Digital Currency Revolution.
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8glkJ6w6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/a4b7aa566c9e3c0e60db48d2fd49958f" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8glkJ6w6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/a4b7aa566c9e3c0e60db48d2fd49958f" alt="Book 7.png" width="880" height="496"&gt;&lt;/a&gt;&lt;br&gt;
This book by Richard Turrin explains China's interoperable cashless society as an example of how digital currencies are already being deployed. In just seven years, digital technology has completely altered the monetary system of the world's second-largest economy, with the central bank's digital currency playing a pivotal role (CBDC).&lt;/p&gt;

&lt;p&gt;Mr. Turrin, a financial insider who spent several years in Shanghai, describes how the new CBDC is being utilized, from street sellers to international monetary transactions, while zooming out to see the ramifications for other nations, including the danger to the US dollar's supremacy.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. The Everything Guide to Investing in Cryptocurrency: From Bitcoin to Ripple, the Safe and Secure Way to Buy, Trade, and my Digital Currencies.
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---x51dJZE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/57a5049736475691988e6a34d23975b0" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---x51dJZE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/57a5049736475691988e6a34d23975b0" alt="Book 8.png" width="880" height="496"&gt;&lt;/a&gt;&lt;br&gt;
This is the finest book by Ryan Derousseau if you want to learn all there is to know about cryptocurrencies. Does it clarify all crypto fundamentals and point to many basics like the difference between BTC and XRP? How is mining carried out? How to make a wallet, and much more.&lt;/p&gt;

&lt;p&gt;Derousseau isn't trying to persuade you to invest in cryptocurrency. He goes into great detail on why you should stay away from cryptocurrencies. If you determine that crypto is the appropriate investment for you, he has some advice on navigating such a turbulent market and how to lock in your profits.&lt;/p&gt;

&lt;h2&gt;
  
  
  Finally!
&lt;/h2&gt;

&lt;p&gt;Seeking the best books on crypto, we decided that a crypto book list was necessary because crypto assets have become such a large alternative asset class. Cryptocurrency has gotten a lot of press, and there are now hundreds of websites dedicated to crypto-related news and marketing. As a result, every man and his dog seems to have written a book about this fascinating topic. Most of these publications try to strike a decent balance between factual knowledge and personal opinion, in our opinion.&lt;/p&gt;

&lt;p&gt;Based on the market movement thus far in 2022, it appears like the current decade is also shaping up to be an age of additional cryptocurrency increases. Still, the cryptocurrency industry always has its fair share of bearish and short-sellers who do not anticipate this to happen.&lt;/p&gt;

&lt;p&gt;Which side do you support? Will cryptocurrencies gain more general acceptability and credibility, or are we approaching 'peak-crypto'?&lt;/p&gt;

&lt;p&gt;Originally written by &lt;a href="https://blockchain.works-hub.com/users/69be7ad5-5182-4556-b20d-2bb48021093a?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;Fawzan Hussain &lt;/a&gt; for &lt;a href="https://blockchain.works-hub.com/learn/best-books-on-crypto-6494a?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;Blockchain Works&lt;/a&gt;&lt;/p&gt;

</description>
      <category>books</category>
      <category>cryptocurrency</category>
    </item>
    <item>
      <title>Create a Distortion Effect Using GSAP</title>
      <dc:creator>Mihaela</dc:creator>
      <pubDate>Wed, 23 Mar 2022 15:10:26 +0000</pubDate>
      <link>https://forem.com/workshub/create-a-distortion-effect-using-gsap-40h5</link>
      <guid>https://forem.com/workshub/create-a-distortion-effect-using-gsap-40h5</guid>
      <description>&lt;p&gt;Animating DOM elements on the web has been one of the many topics with numerous solutions. We have seen the rise of HTML and CSS classic design systems, and how to structure keyframe animations accordingly. Then, we transitioned into using javascript libraries like jQuery, only to now be trumped by more efficient and performant libraries, one of which is GSAP.&lt;/p&gt;

&lt;h4&gt;
  
  
  Introduction
&lt;/h4&gt;

&lt;p&gt;GSAP (GreenSock Animation Platform), as indicated by the Getting Started guide, “is a suite of tools for scripted animations”. What that basically means, is that it is one big ecosystem of ready-made functions and methods you can use to animate literally anything on the DOM. What makes GSAP so great, is that it is fully optimized for performance and scaling, even when building complex animation. This is what makes it trump over jQuery, as well as its minimal code style in contrast to jQuery’s robust syntax.&lt;/p&gt;

&lt;h4&gt;
  
  
  What will we be building?
&lt;/h4&gt;

&lt;p&gt;In this article, you will learn how to build a cool-looking webpage with a distortion effect that gets triggered on hover, using &lt;code&gt;GSAP&lt;/code&gt; and &lt;code&gt;hover-effect&lt;/code&gt; library. This example will help us shorten the learning curve with GSAP.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Credits go to:&lt;/code&gt;&lt;br&gt;
UI Designer: &lt;code&gt;Maxim Nilov | Dribbble&lt;/code&gt;&lt;br&gt;
Github: &lt;a href="https://github.com/codicts/Fashion-Landing-Page"&gt;codicts/Fashion-Landing-Page (github.com)&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Prerequisites
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;GSAP&lt;/code&gt; is a suite that makes rendering on the DOM a lot easier, and this is made possible by using a few key concepts that are related to DOM manipulation, much like every other framework for the web. To this end, you will need to know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTML, CSS and Javascript&lt;/li&gt;
&lt;li&gt;Basic React&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  How does GSAP work?
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;GSAP&lt;/code&gt; has built-in components to help create these animations, and they come with methods that help us set the properties we want to animate. For this example, we will only need one of these components, which is the &lt;code&gt;TweenMax&lt;/code&gt;. (Please check out their &lt;a href="https://greensock.com/get-started/#what-is-gsap"&gt;docs:&lt;/a&gt;).&lt;/p&gt;
&lt;h4&gt;
  
  
  TweenMax
&lt;/h4&gt;

&lt;p&gt;The Tween and TweenMax components are one of the more widely used ones, in that they make it easy to do the simple transitions without writing complex keyframes. The &lt;code&gt;tween&lt;/code&gt; keyword is derived from ‘between’, which basically means “change this property between a given duration from one value to another”. &lt;br&gt;
Let’s take a look at some of the methods that exists within GSAP:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;gsap.to()&lt;/li&gt;
&lt;li&gt;gsap.from()&lt;/li&gt;
&lt;li&gt;gsap.staggerFrom()&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  gsap.to()
&lt;/h4&gt;

&lt;p&gt;Here, we tell &lt;code&gt;gsap&lt;/code&gt; to change the property of a given value to another as well, but in this case, we indicate the starting value of the animation. &lt;br&gt;
Here’s an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gsap.from("#logo", {duration: 1, x: 100});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Gsap.staggerFrom()
&lt;/h4&gt;

&lt;p&gt;Now &lt;code&gt;staggerFrom&lt;/code&gt; works a bit differently from &lt;code&gt;gsap.to()&lt;/code&gt; and &lt;code&gt;gsap.from()&lt;/code&gt;.  With to and from, we deal with a single HTML element that we want to animate, but what if we want to animate a group of elements, particularly children of a parent element? With &lt;code&gt;staggerFrom()&lt;/code&gt;, we can set an animation to take effect for a group of child elements, and even set an interval or “stagger” between the elements, to give it this sequential feel as they get animated.&lt;br&gt;
Here’s an example of using this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    TweenMax.staggerFrom(".media ul li", 1.5, { //TweenMax used in place of gsap
      delay: 1.5,
      opacity: 0,
      x: "-60",
      ease: Expo.easeInOut
    }, 0.08);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First, we call the &lt;code&gt;gsap&lt;/code&gt; library (TweenMax), then we can use the “staggerFrom()” method to target the HTML &lt;code&gt;&amp;lt;li/&amp;gt;&lt;/code&gt; elements under the &lt;code&gt;media&lt;/code&gt; class.  The value &lt;code&gt;1.5&lt;/code&gt; is used to indicate the stagger to be affected between the start time of each child’s animation. This stagger is what helps the animations to have a sequential feel between them. &lt;br&gt;
Then we put in the properties we want for each element. Note the &lt;code&gt;ease&lt;/code&gt; property, which you can learn more about in their documentation.&lt;/p&gt;
&lt;h4&gt;
  
  
  Getting Started with GSAP
&lt;/h4&gt;

&lt;p&gt;Now let’s get started with building our distortion effect page.&lt;br&gt;
Create your folder and in that new folder, create your HTML and CSS files.&lt;br&gt;
Then in your HTML file, you set up your basic HTML markup.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Document&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
Next, our imports:
  &amp;lt;!-- google fonts --&amp;gt;
  &amp;lt;link href="https://fonts.googleapis.com/css?family=Poppins:500,600,700,900&amp;amp;display=swap" rel="stylesheet"&amp;gt;
  &amp;lt;!-- css --&amp;gt;
  &amp;lt;link rel="stylesheet" href="style.css"&amp;gt;
Then our scripts as well, for GSAP and hover-effect (these go on the bottom of the html page)
 &amp;lt;!-- icons --&amp;gt;
  &amp;lt;script src="https://unpkg.com/ionicons@4.5.10-0/dist/ionicons.js"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;!-- gsap --&amp;gt;
  &amp;lt;script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.1.3/TweenMax.min.js"
    integrity="sha256-lPE3wjN2a7ABWHbGz7+MKBJaykyzqCbU96BJWjio86U=" crossorigin="anonymous"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;!-- three js --&amp;gt;
  &amp;lt;script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/108/three.min.js"
    integrity="sha256-3mBEX8I0uMLF7+AUjJeTCelosuorzYpqwBMBPDTyQqY=" crossorigin="anonymous"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are set to get started with our web page.&lt;br&gt;
You can set up the views to your convenience, but for this tutorial, we will first set up the main webpage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;!-- NAVBAR
    =============================== --&amp;gt;
    &amp;lt;nav class="navbar"&amp;gt;
      &amp;lt;div class="menu"&amp;gt;
        &amp;lt;ion-icon name="ios-menu"&amp;gt;&amp;lt;/ion-icon&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div class="lang"&amp;gt;eng&amp;lt;/div&amp;gt;
      &amp;lt;div class="search"&amp;gt;
        &amp;lt;ion-icon name="ios-search"&amp;gt;&amp;lt;/ion-icon&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/nav&amp;gt;


    &amp;lt;!-- SOCIAL MEDIA
    =============================== --&amp;gt;
    &amp;lt;div class="media"&amp;gt;
      &amp;lt;ul&amp;gt;
        &amp;lt;li&amp;gt;facebook&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;instagram&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;twitter&amp;lt;/li&amp;gt;
      &amp;lt;/ul&amp;gt;
    &amp;lt;/div&amp;gt;


    &amp;lt;!-- TEXT
    =============================== --&amp;gt;
    &amp;lt;div class="text"&amp;gt;
      &amp;lt;h1&amp;gt;
        &amp;lt;span class="hidetext"&amp;gt;toni&amp;amp;guy&amp;lt;/span&amp;gt;
      &amp;lt;/h1&amp;gt;
      &amp;lt;h2&amp;gt;duality&amp;lt;/h2&amp;gt;
      &amp;lt;h3&amp;gt;
        &amp;lt;span class="hidetext"&amp;gt;collection 2017 &amp;lt;br&amp;gt; duality&amp;lt;/span&amp;gt;
      &amp;lt;/h3&amp;gt;
      &amp;lt;p&amp;gt;
        &amp;lt;span class="hidetext"&amp;gt;
          Lorem ipsum dolor sit amet consectetur, adipisicing elit. Unde quis, delectus facere
          neque sunt commodi quae
          culpa dolores doloribus magnam?
        &amp;lt;/span&amp;gt;
      &amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;


    &amp;lt;!-- SPONSOR
    =============================== --&amp;gt;
    &amp;lt;div class="sponsor"&amp;gt;
      &amp;lt;img src="./images/sponsor-logo.png" alt=""&amp;gt;
      &amp;lt;p&amp;gt;official sponsor&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then the CSS for the basic webpage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Poppins';
  background: #D8DBE2;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

ul {
  list-style: none;
}

/* NAVBAR
=========================== */
.navbar {
  display: flex;
  justify-content: space-between;
  height: 80px;
  align-items: center;
}

.navbar &amp;gt; div {
  padding: 0 30px;
  font-size: 20px;
}

.navbar .menu {
  margin-right: auto;
}

.navbar .lang {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}


/* SOCIAL MEDIA
=========================== */
.media ul {
  position: absolute;
  bottom: 250px;
  left: -140px;
  transform: rotate(-90deg);
}

.media ul li {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 2px;
  display: inline-block;
  padding: 0 30px;
}


/* TEXT
=========================== */
.text {
  position: absolute;
  top: 200px;
  left: 100px;
  transform: rotate(-90deg);
}

.text h1 {
  font-size: 120px;
  text-transform: uppercase;
  font-weight: 900;
  letter-spacing: -10px;
  margin-bottom: 20px;

  position: relative;
  overflow: hidden;
  height: 150px;
  width: 600px;
}
.text h1 .hidetext {
  position: absolute;
}

.text h2 {
  position: absolute;
  top: 40px;
  left: -80px;
  color: #EFDE74;
  z-index: -1;
  font-size: 150px;
  font-weight: 600;
  letter-spacing: 8px;
  text-transform: uppercase;
}

.text h3 {
  font-size: 40px;
  text-transform: uppercase;
  font-weight: 600;
  line-height: 1;

  position: relative;
  overflow: hidden;
  height: 80px;
}
.text h3 .hidetext {
  position: absolute;
}

.text p {
  width: 200px;
  font-size: 12px;
  margin-top: 30px;
  font-weight: 500;

  position: relative;
  overflow: hidden;
  height: 110px;
}
.text p .hidetext {
  position: absolute;
}


/* SPONSOR
=========================== */
.sponsor {
  position: absolute;
  right: 100px;
  bottom: 100px;
  text-align: center;
}
.sponsor img {
  width: 200px;
  transform: rotate(-90deg);
}
.sponsor p {
  margin-top: 20px;
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 900;
  transform: rotate(180deg);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s examine our webpage:&lt;/p&gt;

&lt;p&gt;Here are a few things we can see: &lt;br&gt;
3 squares animate from bottom to top, to reveal the webpage. Here, we already know they will be 3 divs to have a position absolute, and then we use the “to” method to animate between them.&lt;br&gt;
Navbar above, animate from top to bottom, with changed opacity.&lt;br&gt;
Text on the side changes from 0 to 1 and increases in height.&lt;/p&gt;

&lt;p&gt;For the 3 squares, we create 3 divs to represent them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;div class="overlay first"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="overlay second"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="overlay third"&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we style accordingly in the styles.css&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/*===========================  OVERLAY =========================== */
.overlay {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0%;
  z-index: 99;
}
.first {
  background: #efde74;
}
.second {
  background: #efde74;
  left: 33.3%;
}
.third {
  background: #efde74;
  left: 66.6%;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can set up our animation with &lt;code&gt;GSAP&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; TweenMax.to(".first", 1.5, {
      delay: .5,
      top: "-100%",
      ease: Expo.easeInOut
    });

    TweenMax.to(".second", 1.5, {
      delay: .7,
      top: "-100%",
      ease: Expo.easeInOut
    });

    TweenMax.to(".third", 1.5, {
      delay: .9,
      top: "-100%",
      ease: Expo.easeInOut
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that the delay has been varied by .2 to have that effect. You could also use the &lt;code&gt;staggerFrom()&lt;/code&gt; method to vary between the children and see how the effect varies.&lt;/p&gt;

&lt;p&gt;Next, we animate our navbar and various texts.&lt;br&gt;
Here’s a few things we can see: &lt;br&gt;
3 squares animate from bottom to top, to reveal the webpage. Here, we already know they will be 3 divs to have a position absolute, and then we use the “to” method to animate between them.&lt;br&gt;
Navbar above, animate from top to bottom, with changed opacity.&lt;br&gt;
Text on the side changes from 0 to 1 and increases in height.&lt;/p&gt;

&lt;p&gt;For the 3 squares, we create 3 divs to represent them.&lt;br&gt;
    &lt;/p&gt;
&lt;br&gt;
    &lt;br&gt;
    

&lt;p&gt;Then we style accordingly in the styles.css&lt;br&gt;
/*===========================  OVERLAY =========================== */&lt;br&gt;
.overlay {&lt;br&gt;
  position: absolute;&lt;br&gt;
  width: 100%;&lt;br&gt;
  height: 100%;&lt;br&gt;
  top: 0%;&lt;br&gt;
  z-index: 99;&lt;br&gt;
}&lt;br&gt;
.first {&lt;br&gt;
  background: #efde74;&lt;br&gt;
}&lt;br&gt;
.second {&lt;br&gt;
  background: #efde74;&lt;br&gt;
  left: 33.3%;&lt;br&gt;
}&lt;br&gt;
.third {&lt;br&gt;
  background: #efde74;&lt;br&gt;
  left: 66.6%;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Now we can set up our animation with GSAP:&lt;br&gt;
 TweenMax.to(".first", 1.5, {&lt;br&gt;
      delay: .5,&lt;br&gt;
      top: "-100%",&lt;br&gt;
      ease: Expo.easeInOut&lt;br&gt;
    });&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TweenMax.to(".second", 1.5, {
  delay: .7,
  top: "-100%",
  ease: Expo.easeInOut
});

TweenMax.to(".third", 1.5, {
  delay: .9,
  top: "-100%",
  ease: Expo.easeInOut
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Notice that the delay has been varied by .2 to have that effect. You could also use the staggerFrom() method to vary between the children and see how the effect varies.&lt;/p&gt;

&lt;p&gt;Next, we animate our navbar and various texts.&lt;br&gt;
   // NAVBAR&lt;br&gt;
    TweenMax.staggerFrom(".navbar div", 1.5, {&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  delay: 1.5,
  opacity: 0,
  y: "20",
  ease: Expo.easeInOut
}, 0.08);

// MEDIA
TweenMax.staggerFrom(".media ul li", 1.5, {
  delay: 1.5,
  opacity: 0,
  x: "-60",
  ease: Expo.easeInOut
}, 0.08);

// TEXT
TweenMax.from(".text h1 .hidetext", 1.5, {
  delay: 1,
  y: "100%",
  ease: Expo.easeInOut
});

TweenMax.from(".text h3 .hidetext", 1.5, {
  delay: 1.2,
  y: "100%",
  ease: Expo.easeInOut
});

TweenMax.from(".text p .hidetext", 1.5, {
  delay: 1.3,
  y: "100%",
  ease: Expo.easeInOut
});

TweenMax.from(".text h2", 1.5, {
  delay: 1.5,
  opacity: 0,
  x: "-10000",
  ease: Expo.easeInOut
});

// SPONSOR
TweenMax.from(".sponsor img", 1.5, {
  delay: 1.5,
  opacity: 0,
  y: "20",
  ease: Expo.easeInOut
});

TweenMax.from(".sponsor p", 1.5, {
  delay: 1.6,
  opacity: 0,
  y: "20",
  ease: Expo.easeInOut
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Lastly, for the distortion effect, we will make use of the hover-effect library.&lt;br&gt;
You can get the hover-effect library here, then copy the code, create a new file called hover-effect.umd.js and paste the code. &lt;br&gt;
Then we import our newly created script:&lt;br&gt;
  &amp;lt;!-- hover-effect js --&amp;gt;&lt;br&gt;
  &lt;/p&gt;

&lt;p&gt;Now, how our distortion effect works, is that the library will create a blur of the current image, then transition into a displacement image we will need to provide, then lastly transition to a blurred version of the second image to be transitioned into, and then set the image from a blurred state to a regular state.&lt;br&gt;
So first, we create a div which will represent our distortion image container.&lt;br&gt;
    &amp;lt;!-- DISTORTION =============================== --&amp;gt;&lt;br&gt;
    &lt;/p&gt;

&lt;p&gt;So we need to provide a displacement image, (which should look like a blur effect for convenience), and then the two images to transition between:&lt;br&gt;
    new hoverEffect({&lt;br&gt;
      parent: document.querySelector('.distortion'),&lt;br&gt;
      intensity: 0.2,&lt;br&gt;
      image1: './images/01.png',&lt;br&gt;
      image2: './images/02.png',&lt;br&gt;
      displacementImage: './images/diss.png',&lt;br&gt;
      imagesRatio: 340 / 300&lt;br&gt;&lt;br&gt;
    })&lt;/p&gt;

&lt;p&gt;And that puts together the distortion effect with some animation.&lt;br&gt;
Thanks for reading.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   // NAVBAR
    TweenMax.staggerFrom(".navbar div", 1.5, {

      delay: 1.5,
      opacity: 0,
      y: "20",
      ease: Expo.easeInOut
    }, 0.08);

    // MEDIA
    TweenMax.staggerFrom(".media ul li", 1.5, {
      delay: 1.5,
      opacity: 0,
      x: "-60",
      ease: Expo.easeInOut
    }, 0.08);

    // TEXT
    TweenMax.from(".text h1 .hidetext", 1.5, {
      delay: 1,
      y: "100%",
      ease: Expo.easeInOut
    });

    TweenMax.from(".text h3 .hidetext", 1.5, {
      delay: 1.2,
      y: "100%",
      ease: Expo.easeInOut
    });

    TweenMax.from(".text p .hidetext", 1.5, {
      delay: 1.3,
      y: "100%",
      ease: Expo.easeInOut
    });

    TweenMax.from(".text h2", 1.5, {
      delay: 1.5,
      opacity: 0,
      x: "-10000",
      ease: Expo.easeInOut
    });

    // SPONSOR
    TweenMax.from(".sponsor img", 1.5, {
      delay: 1.5,
      opacity: 0,
      y: "20",
      ease: Expo.easeInOut
    });

    TweenMax.from(".sponsor p", 1.5, {
      delay: 1.6,
      opacity: 0,
      y: "20",
      ease: Expo.easeInOut
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lastly, for the distortion effect, we will make use of the hover-effect library.&lt;br&gt;
You can get the hover-effect library here, then copy the code, create a new file called hover-effect.umd.js and paste the code. &lt;br&gt;
Then we import our newly created script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;!-- hover-effect js --&amp;gt;
  &amp;lt;script src="./hover-effect.umd.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, how our distortion effect works, is that the library will create a blur of the current image, then transition into a displacement image we will need to provide, then lastly transition to a blurred version of the second image to be transitioned into, and then set the image from a blurred state to a regular state.&lt;br&gt;
So first, we create a div that will represent our distortion image container.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;!-- DISTORTION =============================== --&amp;gt;
    &amp;lt;div class="distortion"&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So we need to provide a displacement image, (which should look like a blur effect for convenience), and then the two images to transition between:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    new hoverEffect({
      parent: document.querySelector('.distortion'),
      intensity: 0.2,
      image1: './images/01.png',
      image2: './images/02.png',
      displacementImage: './images/diss.png',
      imagesRatio: 340 / 300   
    })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that puts together the distortion effect with some animation.&lt;/p&gt;

&lt;p&gt;Thanks for reading. &lt;/p&gt;

&lt;p&gt;Originally written by &lt;a href="https://javascript.works-hub.com/users/8cedbde0-2e7b-4328-8741-f8c981f0b076?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;King Somto&lt;/a&gt; for &lt;a href="https://javascript.works-hub.com/learn/create-a-distortion-effect-using-gsap-2cd81?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;JavaScript Works&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>coreanimation</category>
    </item>
    <item>
      <title>A Complete Beginner's Guide to useEffect Hook [Part 3]</title>
      <dc:creator>Mihaela</dc:creator>
      <pubDate>Wed, 23 Mar 2022 15:10:06 +0000</pubDate>
      <link>https://forem.com/workshub/a-complete-beginners-guide-to-useeffect-hook-part-3-50o0</link>
      <guid>https://forem.com/workshub/a-complete-beginners-guide-to-useeffect-hook-part-3-50o0</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;useEffect&lt;/code&gt; is a React Hook that is used to handle side effects in React functional components. Introduced in late October 2018, it provides a single API to handle &lt;code&gt;componentDidMount&lt;/code&gt;, &lt;code&gt;componentDidUnmount&lt;/code&gt;, &lt;code&gt;componentDidUpdate&lt;/code&gt; as what was previously done in class-based React components.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What is useEffect Hook?
&lt;/h2&gt;

&lt;p&gt;According to React's official doc :&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;"The Effect Hook, useEffect, adds the ability to perform side effects from a functional component"&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But what are these side effects that we are talking about?&lt;br&gt;
Well, it means we need to do something after the component renders such as data fetching, changes to the DOM, network requests. These kinds of operation are called effects and can be done using the &lt;code&gt;useEffect&lt;/code&gt; hook. &lt;/p&gt;

&lt;p&gt;A &lt;code&gt;useEffect&lt;/code&gt; hook takes in two parameters, a callback function and a dependency array respectively.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;callbackFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;dependencyArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;value1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...]&lt;/span&gt;

&lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;callbackFunction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dependencyArray&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or quite simply the above can be summed together and usually what we see in codebases:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt; 
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;value1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...]&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  useEffect in action :
&lt;/h2&gt;

&lt;p&gt;Suppose we have a counter button that increases the count by 1 when clicked :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function App() {
 const [count, setCount] = React.useState(0)
 return (
  &amp;lt;div&amp;gt;
    &amp;lt;p&amp;gt;{count}&amp;lt;/p&amp;gt;
    &amp;lt;button onClick={() =&amp;gt; setCount(count + 1)}&amp;gt;click&amp;lt;/button&amp;gt;
  &amp;lt;/div&amp;gt;
);
}

ReactDOM.render(&amp;lt;App /&amp;gt;, document.getElementById("root"));

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What if I want this count value to get dynamically reflected on the page title (i.e. next to the favicon icon), for every button click?&lt;/p&gt;

&lt;p&gt;Now, this does sound like we have to handle an effect triggered by the component, hence a perfect use case for the useEffect hook.&lt;/p&gt;

&lt;p&gt;Let's import useEffect at the top and call the hook inside the component (just as we did for useState hook).&lt;br&gt;
useEffect takes in two arguments, a callback function to trigger and a dependency array, which we will about later in this post :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function App() {
  const [count, setCount] = React.useState(0);

  React.useEffect(() =&amp;gt; {
    document.title = count;
  });

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;{count}&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setCount(count + 1)}&amp;gt;Increment&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

ReactDOM.render(&amp;lt;App /&amp;gt;, document.getElementById("root"));

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's how the above React component will behave :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;App&lt;/code&gt;  functional component will return the HTML and render it to the screen with an initial count of 0, set by the useState hook.&lt;/li&gt;
&lt;li&gt;Immediately, the &lt;code&gt;useEffect&lt;/code&gt; hook runs asynchronously and sets the &lt;code&gt;document.title&lt;/code&gt; to the initial count i.e. 0.&lt;/li&gt;
&lt;li&gt;The rule of thumb is, whenever something inside the component changes(say, click of a button!), the &lt;code&gt;App&lt;/code&gt; component will re-render itself with an updated value.&lt;/li&gt;
&lt;li&gt;Suppose we click the &lt;code&gt;increment&lt;/code&gt; button setting the count value from &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;1&lt;/code&gt;, It will force the &lt;code&gt;App&lt;/code&gt; component to re-render, now with the updated value. useEffect will run asynchronously setting the title to the updated value of count that is &lt;code&gt;1&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Adapting to Correct Mental Model :
&lt;/h2&gt;

&lt;p&gt;While the &lt;code&gt;useEffect&lt;/code&gt; hook seems easy to implement when working with isolated demo components, it is highly likely to run into issues when dealing with large codebases.&lt;br&gt;
The reason being, poor understanding of underlying concepts and continuous comparison with class-based React lifecycle methods.&lt;/p&gt;

&lt;p&gt;Back in the day, when we were using class-based components (no issues if you haven't!), the component side-effects were handled using Lifecycle Methods, and useEffect hook somewhat does the same thing what &lt;br&gt;
&lt;code&gt;componentDidMount&lt;/code&gt;, &lt;code&gt;componentDidUpdate&lt;/code&gt; and &lt;code&gt;componentWillUnmount&lt;/code&gt; APIs did in Lifecycle methods, but they do differ in how the things get handled. Applying Lifecycle's mental model to hooks could result in unnecessary &amp;amp; unexpected behaviour.&lt;/p&gt;

&lt;p&gt;To truly grasp useEffect, we have to "unlearn" the lifecycle way of doing things, as quoted by Dan Abramov,&lt;/p&gt;

&lt;p&gt;** &lt;em&gt;"It’s only after I stopped looking at the useEffect Hook through the prism of the familiar class lifecycle methods that everything came together for me."&lt;/em&gt; **&lt;/p&gt;

&lt;p&gt;Let's create a ** class-based ** component first,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;
 &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;componentDidMount&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;MOUNT&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;onChange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;})}&lt;/span&gt;
    &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see the &lt;code&gt;console&lt;/code&gt; message fires after 3s, what if in between those 3 seconds, we type something to the &lt;code&gt;&amp;lt;input /&amp;gt;&lt;/code&gt; field?&lt;br&gt;
Will the &lt;code&gt;componentDidMount&lt;/code&gt; print empty &lt;code&gt;this.state.name&lt;/code&gt; or would it capture the latest value from the input component?&lt;/p&gt;

&lt;p&gt;The answer is, it would capture the latest value, the reason being how lifecycle methods work in a class-based component. &lt;/p&gt;

&lt;p&gt;render method creates a DOM node -&amp;gt; componentDidMount is called -&amp;gt; State is updated -&amp;gt; DOM is re-rendered fetching the latest value from state.&lt;/p&gt;

&lt;p&gt;Now if we translate the same code to a hook based functional component, it works totally different. The functional component returns a HTML node making initial state value to be empty on the very first mount.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;useLayoutEffect&lt;/code&gt; is another hook that can replicate the class-based example more accurately. Kent C Dodds explains very well when to use each in this &lt;a href="https://kentcdodds.com/blog/useeffect-vs-uselayouteffect/"&gt;post&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Play around with the code here &lt;a href="https://codepen.io/abhinav-anshul/pen/jOBBmPj"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Dependency Array :
&lt;/h2&gt;

&lt;p&gt;The second parameter for &lt;code&gt;useEffect&lt;/code&gt; is a dependency array. It is an array of all the values on which the side-effect should run/ trigger itself.&lt;/p&gt;

&lt;p&gt;For example, let's see this counter component, where when a button is clicked the count value increments by 1, with the help of &lt;code&gt;useState&lt;/code&gt; hook.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;

 &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Running Effect&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)})&lt;/span&gt;
 &lt;span class="nx"&gt;handleChange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


 &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;COMPONENT RE-RENDER&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleChange&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;click&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, what can we learn from the above example? As we can notice, there is an &lt;code&gt;useEffect&lt;/code&gt; hook with no second argument. This would result in re-rendering of the &lt;code&gt;App&lt;/code&gt; component whenever a value inside changes, in this case, the &lt;code&gt;count&lt;/code&gt; value is changing. Hence for every button click the component will keep on re-rendering itself, printing &lt;code&gt;COMPONENT RE-RENDER&lt;/code&gt; to the console.&lt;/p&gt;

&lt;p&gt;** How do we prevent this? **&lt;/p&gt;

&lt;p&gt;By adding a second argument to the &lt;code&gt;useEffect&lt;/code&gt; hook.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;

 &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Running Effect&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)},&lt;/span&gt; &lt;span class="p"&gt;[])&lt;/span&gt; 
 &lt;span class="nx"&gt;handleChange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;   
  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;COMPONENT RE-RENDER&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleChange&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;click&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At the very first mount, we will see both the logs to the console,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Running&lt;/span&gt; &lt;span class="nx"&gt;Effect&lt;/span&gt;
&lt;span class="nx"&gt;COMPONENT&lt;/span&gt; &lt;span class="nx"&gt;RE&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;RENDER&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But this time, as we click on the button there won't be any log from the &lt;code&gt;useEffect&lt;/code&gt; hook as the empty array makes sure to run it just once and all the subsequent logs will be from &lt;code&gt;App&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Running&lt;/span&gt; &lt;span class="nx"&gt;Effect&lt;/span&gt;
&lt;span class="nx"&gt;COMPONENT&lt;/span&gt; &lt;span class="nx"&gt;RE&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;RENDER&lt;/span&gt;
&lt;span class="nx"&gt;COMPONENT&lt;/span&gt; &lt;span class="nx"&gt;RE&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;RENDER&lt;/span&gt;  &lt;span class="c1"&gt;// keep logging as many times as the button clicks&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's go a step further and try filling in the dependency array list with &lt;code&gt;count&lt;/code&gt; value as :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Running Effect&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This time things get interesting as it logs both the console text.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Running&lt;/span&gt; &lt;span class="nx"&gt;Effect&lt;/span&gt;
&lt;span class="nx"&gt;COMPONENT&lt;/span&gt; &lt;span class="nx"&gt;RE&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;RENDER&lt;/span&gt;
&lt;span class="nx"&gt;Running&lt;/span&gt; &lt;span class="nx"&gt;Effect&lt;/span&gt;
&lt;span class="nx"&gt;COMPONENT&lt;/span&gt; &lt;span class="nx"&gt;RE&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;RENDER&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="c1"&gt;// keep logging both the text for button clicks&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first text("Running Effect") is rendered as the effect is triggered whenever the array item modifies(count as mentioned there) and it does for button clicks.&lt;/p&gt;

&lt;p&gt;while the second text("COMPONENT RE-RENDER") is very much expected as the value inside the component itself is changing, so naturally, it has to re-render to update the DOM with the latest value.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codepen.io/abhinav-anshul/pen/JjWqPKE"&gt;codepen&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Incorrect Dependency Array :
&lt;/h2&gt;

&lt;p&gt;It is worth mentioning that incorrect use of dependency array items could lead to issues that are harder to debug. React team strongly advises to always fill in items in the array and not to leave them out.&lt;/p&gt;

&lt;p&gt;There is a very helpful &lt;code&gt;exhaustive-deps&lt;/code&gt; ESlint rule which helps us in issues such as &lt;code&gt;stale closure&lt;/code&gt; which might be due to incorrect dependency or even several other reasons and helps us auto-fix it.&lt;br&gt;
Read more in-depth about the announcement &lt;a href="https://github.com/facebook/react/issues/14920"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  useEffect with cleanup function :
&lt;/h2&gt;

&lt;p&gt;As we have read earlier in this post, &lt;code&gt;useEffect&lt;/code&gt; expects either an undefined or an optional cleanup function as its return value. A Cleanup function can be thought of as a way to clear out the side effects when the component unmounts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// side effect logic here&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// cleanup function&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// logic&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's see cleanup function into action into a very contrived example below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setNumber&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;number is&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;running cleanup function&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;
        &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;number&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;onChange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;setNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
      &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A Cleanup function is used in a very small number of use cases such as clearing out timers, cleaning unnecessary event listeners, unsubscribing to a post etc. If not sanitized properly, they could lead to something called a &lt;a href="https://auth0.com/blog/four-types-of-leaks-in-your-javascript-code-and-how-to-get-rid-of-them/"&gt;Memory leak&lt;/a&gt; in JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Batching multiple useEffects :
&lt;/h2&gt;

&lt;p&gt;What's best, putting different side-effect into one &lt;code&gt;useEffect&lt;/code&gt; hook or in multiple?&lt;br&gt;
Honestly, it depends on the use case and how we are interacting with various components. One important thing to note here is that react will apply effect in the order they were written(in case we have multiple useEffect hooks)&lt;/p&gt;

&lt;p&gt;It is perfectly fine to do this in a single component :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(() =&amp;gt; {
// Second side effect 
})

useEffect(() =&amp;gt; {
// First side effect
})

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conceptual Pitfalls to Avoid :
&lt;/h2&gt;

&lt;p&gt;*&lt;em&gt;1. *&lt;/em&gt; useEffect hook does not truly mimic the &lt;code&gt;componentDidMount&lt;/code&gt; lifecycle method. Same goes for &lt;code&gt;componentDidMount&lt;/code&gt; &amp;amp; &lt;code&gt;componentDidUpdate&lt;/code&gt;. While the end result might look similar when implementing, the order in which they are called and mounted is very distinctive as we've already discussed in the above point.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;2. *&lt;/em&gt; The useEffect hook expects us to return a cleanup function, to unmount/clear the side-effects after a certain condition has been fulfilled, if not provided it returns &lt;code&gt;undefined&lt;/code&gt;. We have to make sure not to return anything else when dealing with an &lt;code&gt;async&lt;/code&gt; function, as an asynchronous function returns a promise.&lt;/p&gt;

&lt;p&gt;The following code is ** wrong ** as it returns an unexpected promise from useEffect Hook&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const App = () =&amp;gt; {   
  useEffect(async () =&amp;gt; {
    const unsubsribe = await subscriberFunction();    
    return () =&amp;gt; {
       unsubscribe()
     }
   }, []) 
return &amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, there are various ways to deal with an &lt;code&gt;async&lt;/code&gt; function inside a &lt;code&gt;useEffect&lt;/code&gt; hook. we can use &lt;code&gt;IIFE&lt;/code&gt; style technique such as :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const App = () =&amp;gt; {
  useEffect(() =&amp;gt; {

    async function subscriberFunction() {
      await fetchIds();
    }   
    subscriberFunction();
  }, []);
return &amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;;
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;3. *&lt;/em&gt; The order in which useEffect has been specified in a component matters while invoking.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up :
&lt;/h2&gt;

&lt;p&gt;React &lt;code&gt;useEffect&lt;/code&gt; hook deviates itself from the class-based lifecycle approach. &lt;br&gt;
It takes time and practice to grasp &lt;code&gt;useEffect's&lt;/code&gt; best patterns and foundational concepts, which when used correctly, can prove to be incredibly powerful for handling side-effects in React Applications.&lt;/p&gt;

&lt;p&gt;** Some Important Resources that I have collected over time: **&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://overreacted.io/a-complete-guide-to-useeffect/"&gt;https://overreacted.io/a-complete-guide-to-useeffect/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/53253940/make-react-useeffect-hook-not-run-on-initial-render?rq=1"&gt;https://stackoverflow.com/questions/53253940/make-react-useeffect-hook-not-run-on-initial-render?rq=1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://reacttraining.com/blog/useEffect-is-not-the-new-componentDidMount/"&gt;https://reacttraining.com/blog/useEffect-is-not-the-new-componentDidMount/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;_ Loved this post? Have a suggestion or just want to say hi? Reach out to me on &lt;a href="https://twitter.com/abhhnv"&gt;Twitter&lt;/a&gt; _&lt;/p&gt;

&lt;p&gt;Originally written by &lt;a href="https://blockchain.works-hub.com/users/c49b5fad-2fef-4acc-aa7a-7cd78f11c9a1?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;Abhinav Anshul&lt;/a&gt; for &lt;a href="https://blockchain.works-hub.com/learn/a-complete-beginners-guide-to-useeffect-hook-83b07?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;Blockchain Works&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>reacthooks</category>
    </item>
    <item>
      <title>Building with React Context Provider Pattern</title>
      <dc:creator>Mihaela</dc:creator>
      <pubDate>Wed, 23 Mar 2022 15:09:31 +0000</pubDate>
      <link>https://forem.com/workshub/building-with-react-context-provider-pattern-315k</link>
      <guid>https://forem.com/workshub/building-with-react-context-provider-pattern-315k</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;In this article, we will be going through the use of the React Context Providers in building React applications. React uses the Context provider to share data across multiple children components in our React App without the need to pass data or functions across multiple components, however, it comes in handy when building applications with lots of dependencies and moving parts.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is React Context API
&lt;/h3&gt;

&lt;p&gt;According to the gospel or the React Docs in the book of Context, it defines the context as “ a way of passing data through the component tree without having to pass props down manually at every level”.&lt;/p&gt;

&lt;p&gt;React applications let parent components pass data long to children components but issues arise when that data is meant to be used by children components multiple layers deep but not by immediate children of that parent component. Let's look at the diagram below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bs9kN9Tx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/54d3dd0f14175609261c6094e7cd1ba8" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bs9kN9Tx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://functionalworks-backend--prod.s3.amazonaws.com/logos/54d3dd0f14175609261c6094e7cd1ba8" alt="Screen Shot 2021-06-27 at 12.02.36 PM.png" width="880" height="506"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Component A is clearly the main parent component with immediate children components B, C, D, these components can receive params from component A and pass that data to the children components, but what about a scenario where Component F needs data from component A and that data is not needed in component B then passing that data to component B becomes redundant, Contex providers provide a cool way of making data readily available to every single child component in the React Application.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is it used for?
&lt;/h3&gt;

&lt;p&gt;Context API provides a way of sharing data with multiple components throughout our React Application this enables us to be creative in how we manage our application state in things like&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Authentication:  Knowing when a user is logged in or has an active user session or just hold user data&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Notifications:  I normally use a Notification provider to expose a notification alert function to components in my &lt;br&gt;
application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Theming: A cool use of this is controlling night mode in applications look at a cool implementation of that &lt;a href="https://javascript.works-hub.com/learn/building-dark-mode-in-react-the-fun-way-424f6"&gt;here&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Loading of data at start of the application&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  React Context Provider example
&lt;/h3&gt;

&lt;p&gt;This is a simple example of a  React context Provider&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```import React, { Component, createContext, useContext } from "react";&lt;br&gt;
export const RandomContext = createContext({ user: null });&lt;/p&gt;

&lt;p&gt;class RandomProvider extends Component {&lt;br&gt;
 state = {&lt;br&gt;
   user: "Somto"&lt;br&gt;
 };&lt;/p&gt;

&lt;p&gt;render() {&lt;br&gt;
   return (&lt;br&gt;
     &lt;br&gt;
       {this.props.children}&lt;br&gt;
     &lt;br&gt;
   );&lt;br&gt;
 }&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;const ComponentTest = () =&amp;gt; {&lt;br&gt;
 const { user } = useContext(RandomContext);&lt;br&gt;
 return (&lt;br&gt;
   &lt;/p&gt;
&lt;br&gt;
     &lt;p&gt;{user}&lt;/p&gt;
&lt;br&gt;
   &lt;br&gt;
 );&lt;br&gt;
};

&lt;p&gt;export default () =&amp;gt; {&lt;br&gt;
 return (&lt;br&gt;
   &lt;/p&gt;
&lt;br&gt;
     &lt;br&gt;
       &lt;br&gt;
     &lt;br&gt;
   &lt;br&gt;
 );&lt;br&gt;
};
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


The user Variable would contain the value Somto.

###Adding useState to React Context 
Combining useState with react context helps to add extra functionality to our React app, now components can interact and change the data present in the Context Provider and these changes can be seen in the entire app.

####Building an example application
For our example application, we are going to build a Simple React counter where we would be able to increase and decrease the value of a number stored in the Context, this would be done by different components by accessing the `usestate`  set Function to change the value.

####Step 1. Build and export the context provider
Let's look at the example below of our new Context Provider.



```js
import React, { Component, createContext, useContext } from "react";
const CountContext = createContext({ count: 0, setCount: () =&amp;gt; {} });

const CountProvider = ({ children }) =&amp;gt; {
 const [count, setCount] = React.useState(0);

 return (
   &amp;lt;CountContext.Provider value={{ count, setCount }}&amp;gt;
     &amp;lt;p&amp;gt;{count}&amp;lt;/p&amp;gt;
     {children}
   &amp;lt;/CountContext.Provider&amp;gt;
 );
};

export const useCountContext = () =&amp;gt; useContext(CountContext);

export default CountProvider;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Let's break this down.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CountContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;&lt;span class="o"&gt;\&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This part of the code is used to create a context to contain the count variable and the &lt;code&gt;setCount&lt;/code&gt; function that would be available throughout the children component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This initiates our &lt;code&gt;useState&lt;/code&gt; variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
 &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;CountContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Provider&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;     &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/CountContext.Provider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we return our ContextProvider, pass in the values variable and pass the children props variable as its own children.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useCountContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;CountContext&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;CountProvider&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Export both the UserCountContext and the Context Provider Itself.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2. Using our provider and calling the &lt;code&gt;setCount&lt;/code&gt;.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./styles.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useContext&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;CountProvider&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useCountContext&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./provider&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useCountContext&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

 &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;
       &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
       &lt;span class="p"&gt;}}&lt;/span&gt;
     &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="nx"&gt;Add&lt;/span&gt;
     &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;     &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;
       &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
       &lt;span class="p"&gt;}}&lt;/span&gt;
     &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="nx"&gt;Subtract&lt;/span&gt;
     &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
 &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;CountProvider&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Component&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/CountProvider&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;,
&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;React context provider offers a way of maintaining state globally across our application, we can read and edit that state in any component we choose to, without passing dependencies in through the tree hierarchy.&lt;/p&gt;

&lt;p&gt;A working example of this code is available &lt;a href="https://codesandbox.io/s/react-context-provider-rms0z?file=/src/index.js"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Originally written by &lt;a href="https://javascript.works-hub.com/users/8cedbde0-2e7b-4328-8741-f8c981f0b076?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;King Somto&lt;/a&gt; for &lt;a href="https://javascript.works-hub.com/learn/building-with-react-context-provider-pattern-1af4b?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;JavaScript Works&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>contextapi</category>
    </item>
    <item>
      <title>Front-End Development Roadmap For 2022</title>
      <dc:creator>Mihaela</dc:creator>
      <pubDate>Thu, 13 Jan 2022 11:27:28 +0000</pubDate>
      <link>https://forem.com/workshub/front-end-development-roadmap-for-2022-1149</link>
      <guid>https://forem.com/workshub/front-end-development-roadmap-for-2022-1149</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Front-end development involves using HTML, CSS, and JavaScript to build a client-side application. The client-side of an online application is the visual part of a web application and also what a user interacts with when an application is opened: colours, fonts, buttons, navigations, animations, etc.&lt;/p&gt;

&lt;p&gt;Front-end development includes the user interface of an application. Everything a user interacts with when a user visits a website such as a login or sign-up page, homepage, contact page falls under the front-end development term.&lt;/p&gt;

&lt;p&gt;A front-end developer is responsible for building and implementing the interface of a website or web application. They build client-side applications using web technologies such as HTML, CSS, and JavaScript.&lt;/p&gt;

&lt;p&gt;In 2022 however, front-end development has gone beyond HTML, CSS, and JavaScript. There are a lot of web technologies you need to learn to be able to excel as a front-end developer this year.&lt;/p&gt;

&lt;p&gt;This article will cover all you need to get started with front-end development in 2022.&lt;/p&gt;

&lt;p&gt;### Basic Terminal Usage (Command line)&lt;/p&gt;

&lt;p&gt;The terminal is an interface used to execute text commands, and it gives you access to the underlying operating system. Basic terminal usage is a skill all developers need regardless of their specialization. Command line is very important so I strongly recommend you study more on how to use it. The better you are with the command line, the more efficient you will be as a front-end developer.&lt;/p&gt;

&lt;h4&gt;
  
  
  Here are some resources to learn command line:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Understanding_client-side_tools/Command_line" rel="noopener noreferrer"&gt;Command-line crash course&lt;/a&gt; - MDN web docs&lt;/li&gt;
&lt;li&gt; &lt;a href="https://www.pluralsight.com/courses/getting-started-linux-command-line%20aid=7010a000002LUv2AAG&amp;amp;promo=&amp;amp;utm_source=non_branded&amp;amp;utm_medium=digital_paid_search_google&amp;amp;utm_campaign=XYZ_EMEA_Dynamic&amp;amp;utm_content=&amp;amp;gclid=CjwKCAiAi_D_BRApEiwASslbJ4Nx1f3ikM1YzwuimkQVOgfC9Gh8irYj9HCshqXV7lpF_vg6TrmwKRoCc7AQAvD_BwE" rel="noopener noreferrer"&gt;Getting Started with the Linux Command Line&lt;/a&gt; - Pluralsight&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.udacity.com/course/linux-command-line-basics--ud595" rel="noopener noreferrer"&gt;Linux Command Line Basics&lt;/a&gt; - Udacity&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://openclassrooms.com/en/courses/4614926-learn-the-command-line-in-terminal" rel="noopener noreferrer"&gt;Learn the Command Line in Terminal&lt;/a&gt; - Openclassrooms&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.codecademy.com/learn/learn-the-command-line" rel="noopener noreferrer"&gt;Learn the Command Line&lt;/a&gt; - Codecademy&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=yz7nYlnXLfE" rel="noopener noreferrer"&gt;Command Line Crash Course&lt;/a&gt; - Freecodecamp&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Git - Version Control
&lt;/h3&gt;

&lt;p&gt;Git is a version control system that enables developers to track changes in their project. Git also helps developers collaborate as a team. Git is needed among developers, to ensure that there are no code conflicts between developers.&lt;/p&gt;

&lt;h4&gt;
  
  
  Here are some resources to learn Git:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://guides.github.com/introduction/git-handbook/" rel="noopener noreferrer"&gt;Git Handbook&lt;/a&gt; - Github guides&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://git-scm.com/videos" rel="noopener noreferrer"&gt;Git&lt;/a&gt; - Git&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://git-scm.com/book/en/v2" rel="noopener noreferrer"&gt;Git book&lt;/a&gt; - Git&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.freecodecamp.org/news/what-is-git-and-how-to-use-it-c341b049ae61/" rel="noopener noreferrer"&gt;An introduction to Git&lt;/a&gt; - Freecodecamp&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.udacity.com/course/version-control-with-git--ud123" rel="noopener noreferrer"&gt;Version Control with Git&lt;/a&gt; - Udacity&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=SWYqp7iY_Tc&amp;amp;t=271s" rel="noopener noreferrer"&gt;Git &amp;amp; GitHub Crash Course For Beginners&lt;/a&gt; - Traversy media
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=USjZcfj8yxE" rel="noopener noreferrer"&gt;Learn Git In 15 Minutes&lt;/a&gt; -  Colt Steele&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=RGOj5yH7evk" rel="noopener noreferrer"&gt;Git and GitHub for Beginners&lt;/a&gt; - Crash Course - Freecodecamp&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Github
&lt;/h3&gt;

&lt;p&gt;GitHub is a code hosting platform for software development. GitHub lets teams work together on projects and it is also used for version control. It can be used among teams to collaborate on a project.  For example, a team of developers wants to build a web application and everyone is given a task that has to be updated daily while working on the project, in this case, Github helps them build a centralized repository where each team member can make updates or manage the code file or repository.&lt;/p&gt;

&lt;p&gt;To get started, sign up for &lt;a href="https://github.com/" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Here are some resources to learn Github:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://guides.github.com/activities/hello-world/" rel="noopener noreferrer"&gt;Github Guides&lt;/a&gt; - Github guides&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=w3jLJU7DT5E" rel="noopener noreferrer"&gt;What is GitHub?&lt;/a&gt; - Github&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=RGOj5yH7evk&amp;amp;t=34s" rel="noopener noreferrer"&gt;Git and GitHub for Beginners&lt;/a&gt; - Crash Course - Freecodecamp&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Text Editor / IDE (Integrated development environment)
&lt;/h3&gt;

&lt;p&gt;The text editor is where you will write your code.  Having the right text editor can improve your productivity.&lt;/p&gt;

&lt;p&gt;There are a lot of IDE to pick from, but let’s look at a few:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;Visual studio code&lt;/a&gt; -  visual studio code is the best IDE for front-end development. It works across all operating systems such as macOS, Windows, and Linux. Visual studio code comes with a great deal of extension which helps in improving productivity as a front-end developer.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.sublimetext.com/" rel="noopener noreferrer"&gt;Sublime text&lt;/a&gt;  -  sublime text is also available on macOS, Windows, and Linux. It is fast, easy, and flexible to use.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://atom.io/" rel="noopener noreferrer"&gt;Atom&lt;/a&gt; - Atom is an open-source code editor for macOS, Linux, and Windows developed by Github with supports for plugins.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Web Fundamentals
&lt;/h3&gt;

&lt;p&gt;It is important to understand how the web works before you start learning any technologies. You should learn about things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Common_questions/How_does_the_Internet_work" rel="noopener noreferrer"&gt;What is the internet and how it works&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol" rel="noopener noreferrer"&gt;HTTP / HTTPS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.freecodecamp.org/news/web-application-security-understanding-the-browser-5305ed2f1dac/" rel="noopener noreferrer"&gt;Browsers and how they work&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Learn HTML
&lt;/h3&gt;

&lt;p&gt;HTML stands for Hypertext Markup Language. It is the markup language for building web pages, it is also the building block of the web. HTML is easy to learn and comprehend. With just HTML, you can build a basic website.&lt;/p&gt;

&lt;p&gt;You need to learn the basics of HTML, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTML Headings- these are what you use to display titles or subtitles on your web pages. It consists of &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; which is the most important heading and &lt;h6&gt; which is the least important.&lt;/h6&gt;
&lt;/li&gt;
&lt;li&gt;HTML Forms - HTML forms are used to collect data inputs such as username, email, contact details.&lt;/li&gt;
&lt;li&gt;HTML Elements - HTML elements define how web browsers will format and display content. Content in the  &lt;code&gt;&amp;lt;i&amp;gt;&lt;/code&gt; tag will be displayed as &lt;em&gt;italics&lt;/em&gt;, content in the &lt;code&gt;&amp;lt;strong&amp;gt;&lt;/code&gt; tag will be displayed as &lt;strong&gt;bold&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;HTML Attributes - HTML attributes provide additional information about the HTML elements. For example, the &lt;img&gt; tag is used to embed an image in a web page, the src attribute will be used to define the path where the image is located.&lt;/li&gt;
&lt;li&gt;HTML layout - HTML layout defines the different ways a website displays content. It is advisable to use semantic HTML elements  such as  &lt;code&gt;&amp;lt;header&amp;gt;&amp;lt;nav&amp;gt;&amp;lt;section&amp;gt;&amp;lt;article&amp;gt;&amp;lt;footer&amp;gt;&lt;/code&gt;, because it clearly describes the element to the browser and developer.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Here are some resources to learn HTML:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.w3schools.com/html/default.asp" rel="noopener noreferrer"&gt;HTML tutorial&lt;/a&gt; - w3schools&lt;/li&gt;
&lt;li&gt;
&lt;a href="//javatpoint.com/html-tutorial"&gt;HTML tutorial&lt;/a&gt; - javaTpoint&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=pQN-pnXPaVg&amp;amp;t=25s" rel="noopener noreferrer"&gt;HTML Full Course&lt;/a&gt; -  Freecodecamp&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=UB1O30fR-EE&amp;amp;t=9s" rel="noopener noreferrer"&gt;HTML Crash Course For Absolute Beginners&lt;/a&gt; -  Traversy Media
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Learn CSS
&lt;/h3&gt;

&lt;p&gt;CSS stands for Cascading Style Sheets. It is the technology to learn after HTML. It is used for styling our HTML. For example, we can use CSS to space our content, colours, fonts, etc.&lt;/p&gt;

&lt;p&gt;The basics of CSS you need to learn are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CSS box model&lt;/strong&gt; - The CSS box model consists of the margin, border, padding, and content. The image below shows us the CSS box model.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F6de1028c70660d608da27ce471210788" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F6de1028c70660d608da27ce471210788" alt="box model.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CSS positioning&lt;/strong&gt; -  CSS positioning helps you manipulate an element to different locations such as fixed, relative, absolute, static, sticky, etc.  The image below shows us CSS positions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CSS grid&lt;/strong&gt;- CSS grid is a two-dimensional system with rows and columns. CSS grid makes it easier to structure a web page without having to use floats.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CSS Flexbox&lt;/strong&gt; - Flexbox is a one-dimensional system that allows us to choose between a row or a column as the main layout or structure of a web page. CSS flexbox also makes it more flexible to structure a web page without having to use floats.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Responsive design and media queries&lt;/strong&gt; - Responsive design is the approach that an application should be built or designed with the user in mind irrespective of their environment such as screen size/devices.  Responsive design is very important and should be in the mind of every developer when building a web application. Media queries are useful when you want to modify your application to fit a device such as Desktops, tablets, and phones. The image below illustrates how an application is viewed on different devices when built with responsive design.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  CSS Preprocessor
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sass&lt;/strong&gt; -  Sass stands for Syntactically Awesome Stylesheet. According to the documentation, Sass is a stylesheet language that’s compiled to CSS. It allows you to use variables, nested rules, mixins, functions, and more, all with a fully CSS-compatible syntax. Sass helps keep large stylesheets well-organized and makes it easy to share design within and across projects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Less&lt;/strong&gt; - Less stands for Leaner Style Sheets is a backwards-compatible language extension for CSS. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  CSS Frameworks
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Tailwind CSS&lt;/strong&gt; - According to the official documentation, Tailwind CSS is a utility-first CSS framework for rapidly building custom user interfaces. Tailwind allows us to use inline styling and achieve incredible results without using a single line of CSS.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bootstrap&lt;/strong&gt; - Bootstrap helps us build fast and responsive websites.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Foundation&lt;/strong&gt; - Foundation is a responsive front-end framework that makes it easier to design responsive websites, apps on any device.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bulma&lt;/strong&gt; -  Bulma is a CSS  framework based on flexbox layout.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Here are some resources to learn CSS:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.w3schools.com/css/default.asp" rel="noopener noreferrer"&gt;CSS tutorials&lt;/a&gt; - w3schools&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=yfoY53QXEnI&amp;amp;t=90s" rel="noopener noreferrer"&gt;CSS Crash Course For Absolute Beginners&lt;/a&gt; - Traversy Media
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=5bMdjkfvONE" rel="noopener noreferrer"&gt;HTML5 &amp;amp; CSS Development&lt;/a&gt;  - Udemy&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=1Rs2ND1ryYc" rel="noopener noreferrer"&gt;CSS Tutorial - Zero to Hero&lt;/a&gt; - Freecodecamp&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.w3schools.com/sass/" rel="noopener noreferrer"&gt;SASS Tutorial&lt;/a&gt; - w3schools&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=JJSoEo8JSnc&amp;amp;t=167s" rel="noopener noreferrer"&gt;Flexbox CSS in 20 minutes&lt;/a&gt; - Traversy media&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=jV8B24rSN5o&amp;amp;t=287s" rel="noopener noreferrer"&gt;CSS Grid Layout Crash Course&lt;/a&gt; - Traversy media&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=YD91G8DdUsw" rel="noopener noreferrer"&gt;Less CSS PreProcessor Tutorial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/results?search_query=tailwind+css" rel="noopener noreferrer"&gt;Tailwind CSS crash course&lt;/a&gt; - Traversy media&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.w3schools.com/bootstrap4/bootstrap_get_started.asp" rel="noopener noreferrer"&gt;Bootstrap 4&lt;/a&gt; - w3school&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=DEu5xYEZx18" rel="noopener noreferrer"&gt;Foundation Framework Crash Course&lt;/a&gt; - Traversy media&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=IiPQYQT2-wg" rel="noopener noreferrer"&gt;Bulma CSS Framework Crash Course&lt;/a&gt;- Traversy media &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Learn JavaScript
&lt;/h3&gt;

&lt;p&gt;JavaScript is one of the most popular programming languages in the world. It is the language of the web. As a front-end developer, it is required you learn JavaScript. JavaScript enables us to create dynamic content. When you create your HTML structure and your style with your CSS, JavaScript makes the website dynamic and alive. &lt;/p&gt;

&lt;h4&gt;
  
  
  Some of the basics of JavaScript you need to learn are:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;JavaScript Syntax&lt;/strong&gt; - Every programming language has its own rules on how a program is written.&lt;br&gt;
The syntax of JavaScript is the set of rules that determine how a program is written by a programmer and interpreted by a browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DOM Manipulation&lt;/strong&gt; - DOM stands for document objects model. According to W3C (World Wide Web Consortium) standard, the DOM is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document.  The DOM is a representation of how the content of a web page is structured. JavaScript manipulates the DOM by updating the content, the style, removing elements, adding new elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Learn Fetch API&lt;/strong&gt; -  API stands for Application Programming Interface. An API is an intermediary that allows two applications to communicate with each other. As a front-end developer, when building a web application, chances are that you will have to work with external data such as Third-party APIs, fetch API allows browsers to make HTTP requests to a web server.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  JavaScript Frameworks/Libraries
&lt;/h4&gt;

&lt;p&gt;After learning the basics of JavaScript,  you can pick any JavaScript framework of your choice. But I highly recommend you pick Vuejs as it is more beginner-friendly.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;React&lt;/strong&gt; - According to the documentation, a JavaScript library for building user interfaces React lets you create reusable components.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vue&lt;/strong&gt; -  Vuejs is an approachable, versatile, performant javascript framework that helps you create a maintainable and testable codebase. Vuejs is also beginner-friendly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Angular&lt;/strong&gt; - According to the documentation, Angular is an application design framework and development platform for creating efficient and sophisticated single-page apps.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Svelte&lt;/strong&gt; - Svelte provides a different method for building web applications. It helps developers build fast web pages and a great user interface.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ember&lt;/strong&gt; - Ember allows developers to create a scalable single page application. It includes everything you need to build a rich user interface that works on any device.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PREACT&lt;/strong&gt; - PREACT is an alternative to React but came with a Fast 3kB and the same modern API.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Here are some resources to learn JavaScript:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.w3schools.com/js/default.asp" rel="noopener noreferrer"&gt;JavaScript Tutorial&lt;/a&gt; - W3schools&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=PkZNo7MFNFg&amp;amp;t=82s" rel="noopener noreferrer"&gt;Learn JavaScript&lt;/a&gt; - Freecodecamp&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=W6NZfCO5SIk" rel="noopener noreferrer"&gt;JavaScript Tutorial for Beginners&lt;/a&gt; - Programming with Mosh&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=Qqx_wzMmFeA" rel="noopener noreferrer"&gt;JavaScript Tutorial for Beginners&lt;/a&gt; - Clever programmers&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=hdI2bqOjy3c&amp;amp;t=122s" rel="noopener noreferrer"&gt;JavaScript Crash Course For Beginners&lt;/a&gt; - Traversy media&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;React Tutorial&lt;/a&gt; - React&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://vuejs.org/v2/guide/" rel="noopener noreferrer"&gt;Getting started with Vue&lt;/a&gt; - Vue Guide&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://vuejs.org/v2/guide/" rel="noopener noreferrer"&gt;Build An Ember.js App&lt;/a&gt; - Program with Erik&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://preactjs.com/guide/v10/getting-started/" rel="noopener noreferrer"&gt;Getting started with PREACT&lt;/a&gt; - PREACT guide&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=uK2RnIzrQ0M" rel="noopener noreferrer"&gt;Svelte Crash Course&lt;/a&gt; - Traversy media&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=Fdf5aTYRW0E" rel="noopener noreferrer"&gt;Angular Crash Course&lt;/a&gt; - Traversy media&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F2e71881dafaf11da0d7a342b1d95ab84" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffunctionalworks-backend--prod.s3.amazonaws.com%2Flogos%2F2e71881dafaf11da0d7a342b1d95ab84" alt="1_KRq7jQOUdQsHNsZa72XcDw.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Package managers
&lt;/h3&gt;

&lt;p&gt;A package manager is a tool that allows users to install, update, configure,  and manage software packages and product dependencies. Examples of package managers are &lt;strong&gt;NPM&lt;/strong&gt; and &lt;strong&gt;Yarn&lt;/strong&gt;. It is recommended you learn the basics of one of them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Accessibility
&lt;/h3&gt;

&lt;p&gt;Web accessibility is the process of making your website usable by all people. Web accessibility is an essential part of front-end development. It is important that as a front-end developer, you need to build web pages with accessibility in mind. When you build with accessibility in mind, there is no restriction to anyone. People with disabilities, slow networks, visual impairments, hearing impairments can have access to all the information on the website without obstructions or difficulties.&lt;/p&gt;

&lt;h4&gt;
  
  
  Here are some resources to learn more about Accessibility:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.udacity.com/course/web-accessibility--ud891" rel="noopener noreferrer"&gt;Web accessibility&lt;/a&gt; -  Udacity&lt;/li&gt;
&lt;li&gt; &lt;a href="https://www.classcentral.com/course/edx-introduction-to-web-accessibility-17252" rel="noopener noreferrer"&gt;Introduction to Web Accessibility&lt;/a&gt; - Class Central&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Performance
&lt;/h3&gt;

&lt;p&gt;According to MDN, web performance is all about making websites fast, including making slow processes seem fast. One of the metrics that a good website/web application should meet is &lt;em&gt;fast page rendering&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;Web performance refers to how long it takes for an application to be rendered in the browser as well as how responsive it is to user interaction. For a better user experience, it is recommended that developers adopt different web optimization techniques. This includes using a Content Delivery Network (CDN) which is a strategically distributed web server that delivers contents to users based on location. Another option is to use image compressing tools like &lt;a href="https://imageoptim.com/online" rel="noopener noreferrer"&gt;imageOptim&lt;/a&gt; to reduce image sizes without compromising its quality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Other methods to adopt include:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use cache - the whole idea about cache revolves around temporarily saving data and web pages to improve page performance. It is advised that developers implement a cache in the best possible situations to increase site performance and overall user experience. Cached data can be stored on local storage and retrieved when needed.&lt;/li&gt;
&lt;li&gt;Minimize the number of HTTP requests that your application makes. &lt;/li&gt;
&lt;li&gt;Load your CSS and JavaScript files asynchronously. This will prevent the browser from waiting for any element that takes extra time to load. It will instead proceed to other elements.&lt;/li&gt;
&lt;li&gt;Remove junk and unwanted codes in your CSS and JavaScript files.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To get the exact performance data of your web application, you can make use of any of the below-listed tools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.loadview-testing.com/" rel="noopener noreferrer"&gt;Loadview&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://loadninja.com/" rel="noopener noreferrer"&gt;LoadNinja&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.neotys.com/" rel="noopener noreferrer"&gt;NeoLoad&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of the above-listed tools though with different unique features will serve you just right.&lt;/p&gt;

&lt;h3&gt;
  
  
  Testing Your Apps
&lt;/h3&gt;

&lt;p&gt;Testing involves scanning a piece of software for a potential bug during development. During testing, the tester performs an action on a piece of software while expecting a specific result. Possible things to test in an application includes security, functionality and ease of use amongst others. Testing does not guarantee that a piece of software will function properly under any circumstance but it, however, provides us with information on how it could behave under certain conditions. An example of a test tool to try out in your application is a &lt;strong&gt;Jest&lt;/strong&gt;. Jest is a framework used to create and run JavaScript tests for applications built with React, Nodejs, Angular, TypeScript, Vue, and more. It has grown in popularity over the years and has become one of the most used test tools. &lt;/p&gt;

&lt;p&gt;Other testing tools and frameworks to try out include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://mochajs.org/" rel="noopener noreferrer"&gt;Mocha&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pptr.dev/" rel="noopener noreferrer"&gt;Puppeteer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://jasmine.github.io/" rel="noopener noreferrer"&gt;Jasmine&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Website Deployment
&lt;/h3&gt;

&lt;p&gt;With the knowledge gotten from HTML, CSS, and JavaScript you can build simple web pages using those technologies. Most time after building, it remains in our computer or Github repo and there is no way people can see what you built. But with web deployments, you can host your simple application on the internet. It is super easy to do. You can use tools like &lt;a href="https://pages.github.com/" rel="noopener noreferrer"&gt;GitHub pages&lt;/a&gt;, or &lt;a href="https://www.netlify.com/" rel="noopener noreferrer"&gt;Netlify&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congrats, you have come to the end of the front-end development roadmap for 2022! With the knowledge shared here, you can easily build real-time website applications. Good luck! &lt;/p&gt;

&lt;p&gt;For more resources like this don't hesitate to &lt;a href="https://javascript.works-hub.com/register?utm_source=blog&amp;amp;utm_medium=organic&amp;amp;utm_campaign=m.popa" rel="noopener noreferrer"&gt;sign up&lt;/a&gt; to join our community of developers!&lt;/p&gt;

&lt;p&gt;Originally written by &lt;a href="https://javascript.works-hub.com/users/4107661d-0fbf-412b-8341-ec9f76e4208e?utm_source=dev_to&amp;amp;utm_medium=blog_xpost" rel="noopener noreferrer"&gt;AMAECHI AMARACHI&lt;/a&gt; for &lt;a href="https://javascript.works-hub.com/learn/front-end-development-roadmap-b08ed?utm_source=dev_to&amp;amp;utm_medium=blog_xpost" rel="noopener noreferrer"&gt;JavaScript Works&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>angular</category>
      <category>react</category>
      <category>html</category>
    </item>
    <item>
      <title>Web Components API: Shadow DOM and Light DOM</title>
      <dc:creator>Mihaela</dc:creator>
      <pubDate>Thu, 13 Jan 2022 10:53:31 +0000</pubDate>
      <link>https://forem.com/workshub/web-components-api-shadow-dom-and-light-dom-4jab</link>
      <guid>https://forem.com/workshub/web-components-api-shadow-dom-and-light-dom-4jab</guid>
      <description>&lt;p&gt;In our series of articles about web components, we have first made an &lt;a href="https://javascript.works-hub.com/learn/web-components-the-vanilla-framework-8b60b"&gt;introduction into the web components world&lt;/a&gt; and looked into how we got to where we are today. Next, we talked about the &lt;a href="https://javascript.works-hub.com/learn/web-components-api-definition-attributes-and-props-886c0"&gt;web components API&lt;/a&gt;, more specifically how to define them, their attributes, and props.&lt;/p&gt;

&lt;p&gt;So far, we know the fundamentals and we're able to define a web component, but, how can we define the content of the component, the markup, and finally, the component's structure?&lt;/p&gt;

&lt;p&gt;Our web component content will be the sum of a Shadow DOM and a Light DOM, using tags like &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;slot&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shadow DOM
&lt;/h2&gt;

&lt;p&gt;Let's sum up, what we talked about Shadow DOM in the first article of the series:&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Shadow DOM&lt;/strong&gt; API is probably the most important API of Web Components. This API brings us encapsulation for both markup and styles. This means that our web component code and styles will not overlap with the rest of the elements of the page where the component belongs to. The encapsulation applies both to the web component on the outside as well as the page inside the web component. For this to be possible an independent DOM subtree (shadow DOM) is attached to the main DOM.&lt;/p&gt;

&lt;p&gt;To make things more clear:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If we execute a &lt;code&gt;document.querySelector()&lt;/code&gt; we won't find any element of the web component.&lt;/li&gt;
&lt;li&gt;If we define some style for, let's say, a &lt;code&gt;&amp;lt;div class="button"&amp;gt;&lt;/code&gt;, and inside the web component there was also a &lt;code&gt;div&lt;/code&gt; with the same class, it would not be affected by the outside styles.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Regarding to code, a web component with Shadow DOM could look in the following way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;my-profile&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"Marty"&lt;/span&gt; &lt;span class="na"&gt;lastname=&lt;/span&gt;&lt;span class="s"&gt;"Mcfly"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  #shadow-root
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"profile-picture"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"marty.png"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Marty Mcfly"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Marty Mcfly&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/my-profile&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have seen what the ShadowDOM means and how it looks like, now let's try to implement it using the API.&lt;/p&gt;

&lt;p&gt;We will add a shadow root to our shadow host (web component). To do that we need to execute the function &lt;code&gt;attachShadow()&lt;/code&gt;, which has the following syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;shadowroot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;attachShadow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;shadowRootInit&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;shadowRootInit&lt;/code&gt; parameter is a settings object with the following structure:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;mode:&lt;/strong&gt; A string specifying the encapsulation mode for the shadow DOM tree. This can be one of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;open&lt;/code&gt;: Elements of the shadow root are accessible from JavaScript outside the root, for example using Element.shadowRoot:&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;closed&lt;/code&gt;: Denies access to the node(s) of a closed shadow root from JavaScript outside it. Not commonly used.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;delegatesFocus:&lt;/strong&gt; A boolean that, when set to true, specifies behavior that mitigates custom element issues around focusability. When a non-focusable part of the shadow DOM is clicked, the first focusable part is given focus, and the shadow host is given any available &lt;code&gt;:focus&lt;/code&gt; styling&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This function must be executed inside the context of our web component's class, specifically, inside the constructor call of our web component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;MyCustomElement&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;HTMLElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="c1"&gt;// ...&lt;/span&gt;

    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;shadowRoot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;attachShadow&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;open&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="c1"&gt;// ...&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="c1"&gt;// our custom element code&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;Element.attachShadow()&lt;/code&gt; method (in our code, &lt;code&gt;this.attachShadow&lt;/code&gt; as &lt;code&gt;this&lt;/code&gt; is pointing to our &lt;code&gt;HTMLElement&lt;/code&gt; class), attaches a shadow DOM tree to the specified element and returns a reference to its ShadowRoot. This reference to that &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot"&gt;ShadowRoot&lt;/a&gt; is what we are storing in &lt;code&gt;this.shadowRoot&lt;/code&gt; variable, in order to make some other operations later, as appending our web component content.&lt;/p&gt;

&lt;p&gt;It's important to note that is not possible to attach a ShadowRoot to all existing elements. We can attach a shadow root to the following elements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;article&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;aside&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;blockquote&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;footer&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;h2&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;h3&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;h4&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;h5&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;h6&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;nav&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;section&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then, once we have a ShadowRoot attached to our element, it's time to define its content. To do that, we will do using the HTML &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt; tag or a String variable with the HTML content. Let's see how it works.&lt;/p&gt;

&lt;h3&gt;
  
  
  Defining content using &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;We can define the web component's content using the &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt; tag. The &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt; allows us to define some HTML content on the client-side that will not be rendered with the page load but will be available to be instantiated. That means, in the web component's context, that we can define our web component's content but this will not be rendered. However, we can instantiate from our web component's code to be attached to our ShadowRoot. This content will only be rendered when our web component will be instantiated.&lt;/p&gt;

&lt;p&gt;As we said, we will define the web component's content in the HTML file and then we will have to get it from the web component's code file (a.k.a JS file).&lt;/p&gt;

&lt;p&gt;Let's say we have an HTML file with our web component's as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;HTML&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&amp;lt;/head&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;

  &lt;span class="c"&gt;&amp;lt;!-- our web component's code --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;template&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"webComponentsHTML"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"profile-picture"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Marty Mcfly"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/HTML&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, from our web component's code, we will access and attach the web component's content to the ShadowRoot as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="c1"&gt;// get the template code&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;template&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#webComponentsHTML&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Attaches a shadow DOM tree to our element (this)&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_shadowRoot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;attachShadow&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;open&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="c1"&gt;// Set our elements code&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_shadowRoot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cloneNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Maybe you're wondering why we're using the &lt;code&gt;cloneNode()&lt;/code&gt; method instead of using directly &lt;code&gt;template.content&lt;/code&gt;. The answer is because we are using the &lt;code&gt;appendChild&lt;/code&gt; method, which moves the appended node from its current position to the new position, so there is no requirement to remove the node from its parent node before appending it to some other node. In order to maintain the template content, we are using &lt;code&gt;cloneNode()&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Defining content using inside the JS file
&lt;/h3&gt;

&lt;p&gt;The other way to define our web component's content is doing it, as we said, inside the JS file using the &lt;code&gt;innerHTML&lt;/code&gt; property of our ShadowRoot instance. We can define our HTML content directly to the &lt;code&gt;innerHTML&lt;/code&gt; property (first snippet) or pointing to another variable if needed (2nd snippet):&lt;/p&gt;

&lt;p&gt;Directly to the &lt;code&gt;innerHTML&lt;/code&gt; property&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="c1"&gt;// component's code&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;componentCode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;div class="profile-picture"&amp;gt;
      &amp;lt;img src alt="Marty Mcfly" /&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="name"&amp;gt;&amp;lt;/div&amp;gt;
  `&lt;/span&gt;
  &lt;span class="c1"&gt;// Attaches a shadow DOM tree to our element (this)&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_shadowRoot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;attachShadow&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;open&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="c1"&gt;// Set our elements code&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_shadowRoot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;componentCode&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pointing to another variable&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="c1"&gt;// Attaches a shadow DOM tree to our element (this)&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_shadowRoot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;attachShadow&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;open&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="c1"&gt;// Set our elements code&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_shadowRoot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;div class="profile-picture"&amp;gt;
      &amp;lt;img src alt="Marty Mcfly" /&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="name"&amp;gt;&amp;lt;/div&amp;gt;
  `&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both ways of defining the component's content accept HTML tags as well style tags in order to define the styles of the content.&lt;/p&gt;

&lt;h3&gt;
  
  
  Declarative ShadowDOM
&lt;/h3&gt;

&lt;p&gt;There is a brand new way to define ShadowDOM: declarative ShadowDOM - implement and use Shadow DOM directly in HTML. As a new web platform API, Declarative Shadow DOM does not have widespread support across all browsers yet. Declarative Shadow DOM is available in Chrome 90 and Edge 91. It can also be enabled using the Experimental Web Platform Features flag in Chrome 85.&lt;/p&gt;

&lt;p&gt;As it's not fully implemented acroos all browsers, we won't go further into this topic, but here are some resources if you want to learn more:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://web.dev/declarative-shadow-dom/"&gt;Declarative Shadow DOM - web.dev&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/WICG/webcomponents/blob/gh-pages/proposals/Declarative-Shadow-DOM.md"&gt;WICG/webcomponents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=xY2rpHsaGlI"&gt;Declarative Shadow DOM - TPAC 2020 breakout session&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Light DOM
&lt;/h2&gt;

&lt;p&gt;You should already have a clear understanding of what ShadowDOM is, now it's time to talk about LightDOM. LightDOM is the other &lt;em&gt;DOM&lt;/em&gt; tree along with ShadowDOM that defines the web component's content. While ShadowDOM points to the main content of the component and it's defined by the web component's developer, LightDOM points to content that is not mandatory and it's defined by the person who is consuming our web component.&lt;/p&gt;

&lt;p&gt;Let's sum up, what we talked about Light DOM and, specifically slots, in the first article of the series:&lt;/p&gt;

&lt;p&gt;Slots allow the author of a web component to define which content will be customizable by the consumer with his own HTML. Slots are the way we have to customize the content of our web component. As they are not part of Shadow DOM, and therefore, are not encapsulated, they are affected by page styles, and can be queried. &lt;/p&gt;

&lt;p&gt;Let's see a use case in order to understand the concept better. Let's say we have a profile card (as we have been seeing in the previous articles) where we have a picture, a name, and a description. Both the name and the description could be set by using attributes, but attributes are limited to primitive types, so only String will be supported. Maybe, when defining our description we want to highlight some parts of it with bold text, using &lt;code&gt;&amp;lt;b&amp;gt;&lt;/code&gt; tag. We can do that by using a slot:&lt;/p&gt;

&lt;p&gt;This would be the web component's definition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"profile-picture"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Marty Mcfly"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"description"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;slot&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"description"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/slot&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would be the web component's usage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;  &lt;span class="nt"&gt;&amp;lt;my-profile&lt;/span&gt; &lt;span class="na"&gt;picture=&lt;/span&gt;&lt;span class="s"&gt;"src/myProfilePicture.jpg"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"Marty McFlY"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;slot=&lt;/span&gt;&lt;span class="s"&gt;"description"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      I am a &lt;span class="nt"&gt;&amp;lt;b&amp;gt;&lt;/span&gt;time traveller&lt;span class="nt"&gt;&amp;lt;/b&amp;gt;&lt;/span&gt; who loves music and plays the electric guitar.
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/my-profile&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;This is not totally true. Attributes can receive complex types as arrays or objects by setting them from JavaScript, but this is not a good practice and it doesn't follow the standards&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The use case described above is a very simple example just to illustrate the slot concept and understand it better. Another case could be, for instance, a tabs component, where we would define the tab content using slot, as the tab content is unpredictable and could have all kind of content (any kind of HTML, remote content fetched from a server... anything).&lt;/p&gt;

&lt;h3&gt;
  
  
  Default and named slots
&lt;/h3&gt;

&lt;p&gt;A web component can have as many slots as needed, so we need a way to differentiate them. To do it we can name it, using the &lt;code&gt;name&lt;/code&gt; attribute in the slot definition and the &lt;code&gt;slot&lt;/code&gt; attribute in the web component usage. On another hand, we can define a default slot as well. The default slot will be the one that has not defined the &lt;code&gt;slot&lt;/code&gt; attribute.&lt;/p&gt;

&lt;p&gt;To understand it better, let's go back to the last example.&lt;/p&gt;

&lt;p&gt;This would be the web component's definition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"profile-picture"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;slot&amp;gt;&amp;lt;slot&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;slot&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/slot&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"description"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;slot&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"description"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/slot&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would be the web component's usage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;  &lt;span class="nt"&gt;&amp;lt;my-profile&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"src/myProfilePicture.jpg"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;slot=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Marty McFly&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Also known as Levis Strauss&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;slot=&lt;/span&gt;&lt;span class="s"&gt;"description"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      I am a &lt;span class="nt"&gt;&amp;lt;b&amp;gt;&lt;/span&gt;time traveller&lt;span class="nt"&gt;&amp;lt;/b&amp;gt;&lt;/span&gt; who loves music and plays the electric guitar.
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/my-profile&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can see, we have two DIVs elements pointing to two slots, but we have a picture (&lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt;), that doesn't have any slot set, so this one will be pointed as the default slot, the one which has no name in the web component's definition.&lt;/p&gt;

&lt;h2&gt;
  
  
  Styling WebComponents (ShadowDOM and LightDOM)
&lt;/h2&gt;

&lt;p&gt;ShadowDom brings us encapsulation for markup as well as for styles, but as web component's author, we can set some ways to customize the web component's appearance from outside.&lt;/p&gt;

&lt;p&gt;On the other hand, as mentioned before since LightDOM is not encapsulated, it's affected by page styles and can be queried. However, we, as web component's authors, can define some default styles that will be applied to slots. &lt;/p&gt;

&lt;p&gt;In the next articles we will explore this deeper, meanwhile, we can list the ways we have to do it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;ShadowDOM&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;::part()&lt;/code&gt; pseudo-element&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:host-context&lt;/code&gt; selector&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:host&lt;/code&gt; selector&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:host&lt;/code&gt; selector and classes&lt;/li&gt;
&lt;li&gt;CSS vars&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;LightDOM&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;::slotted()&lt;/code&gt; pseudo-selector&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Step by step, we are exanding our Web Components knowledge. We are getting really close to being ready to write our first web component from scratch, so make sure to keep an eye on this series!&lt;/p&gt;

&lt;p&gt;Also, ddon't forget to read the first two articles of the series:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://javascript.works-hub.com/learn/web-components-the-vanilla-framework-8b60b"&gt;Web Components: The vanilla framework&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://javascript.works-hub.com/learn/web-components-api-definition-attributes-and-props-886c0"&gt;Web Components API: Definition, attributes and props&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

&lt;p&gt;Originally written by &lt;a href="https://javascript.works-hub.com/users/3e58cda8-299f-41b4-8fd7-f2fd7a988d9d?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;Rafa Romero Dios&lt;/a&gt; for &lt;a href="https://javascript.works-hub.com/learn/web-components-api-shadow-dom-and-light-dom-e18b6?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;JavaScript Works&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>css3</category>
      <category>vanillajavascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Why You Should Learn Functional Programming</title>
      <dc:creator>Mihaela</dc:creator>
      <pubDate>Fri, 26 Nov 2021 17:20:17 +0000</pubDate>
      <link>https://forem.com/workshub/why-you-should-learn-functional-programming-194j</link>
      <guid>https://forem.com/workshub/why-you-should-learn-functional-programming-194j</guid>
      <description>&lt;p&gt;Many of the widely used languages (including C++, Java, and Javascript) are imperative.  In imperative programming, computations are structured as sequences of instructions that operate by making modifications to the state of the program.  Functional languages operate by declaring functions. The output value of a function depends only on the arguments that are passed to the function.  Because of this, functional languages have a few advantages that minimize mistakes.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Sometimes, the elegant implementation is a function.&lt;br&gt;
Not a method. Not a class. Not a framework. Just a function."&lt;br&gt;
--John Carmack&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Until recently, functional languages were considered "academic" and for research only. But the industry has since discovered their advantages and many leaders are adopting functional programming to gain competitiveness.&lt;/p&gt;

&lt;p&gt;In this post, I'll list a few reasons why you should learn functional programming.&lt;/p&gt;

&lt;h2&gt;
  
  
  It makes you a better programmer
&lt;/h2&gt;

&lt;p&gt;Functional programming, especially &lt;em&gt;typed&lt;/em&gt; functional programming, offers a very different mental toolbox than the traditional programmer usually uses. For example:&lt;/p&gt;

&lt;h3&gt;
  
  
  Immutability
&lt;/h3&gt;

&lt;p&gt;Unlike in imperative languages, in functional languages, variables are immutable by default and do not depend on the state of the program.  Along with referential transparency (given the same&lt;br&gt;
inputs, a function always return the same results), this increases consistency. As a result, we have reduced&lt;br&gt;
errors, increased stability, and increased effectiveness of tests. For example, tools like &lt;a href="https://hackage.haskell.org/package/QuickCheck"&gt;QuickCheck&lt;/a&gt; are very effective.&lt;/p&gt;

&lt;h3&gt;
  
  
  Type safety
&lt;/h3&gt;

&lt;p&gt;Modern functional languages are usually statically typed, which means that they type check (verify all functions have the correct input types passed to them and return the correct type) at compile-time as opposed to run-time.  This ensures that all programs in production are type safe.  Even though some imperative languages are also statically typed, they don't offer as many safety guarantees as modern functional languages.&lt;/p&gt;

&lt;h3&gt;
  
  
  Memory safety
&lt;/h3&gt;

&lt;p&gt;Functional programming languages handle allocation and de-allocation for you. The compiler avoids many common memory leaks that imperative programmers see and completely removes the risk of null dereferences.&lt;/p&gt;

&lt;h3&gt;
  
  
  Purity
&lt;/h3&gt;

&lt;p&gt;In pure functional languages like Haskell, you can prove the absence of unwanted side-effects.  Because pure functional languages operate with functions that are type safe, you can control whether a function in the code has any interaction with the outside world more easily.&lt;/p&gt;

&lt;p&gt;And many more! See &lt;a href="https://www.foxhound.systems/blog/why-haskell-for-production/"&gt;here&lt;/a&gt;&lt;br&gt;
and &lt;a href="http://book.realworldhaskell.org/read/why-functional-programming-why-haskell.html"&gt;here&lt;/a&gt; for&lt;br&gt;
more details.&lt;/p&gt;

&lt;p&gt;These new tools and perspectives empower you to write better programs even when you write in&lt;br&gt;
traditional languages. In fact, many modern extensions/frameworks have&lt;br&gt;
functional flavours added. See for example &lt;a href="https://reasonml.github.io/"&gt;ReasonML&lt;/a&gt; and &lt;a href="https://www.typescriptlang.org/"&gt;typescript&lt;/a&gt;. Learning functional programming will give you the necessary building blocks to pick up these frameworks quickly and correctly. &lt;/p&gt;

&lt;h2&gt;
  
  
  It's enjoyable
&lt;/h2&gt;

&lt;p&gt;A far smaller cognitive load is required when writing functional rather than imperative code. As mentioned above, in functional programming the compiler type checks and ensures memory safety. In addition, functions have no side effects. Therefore, many concerns present in imperative languages can be completely offloaded to the compiler. With this tedious cognitive load freed up, the functional&lt;br&gt;
programmer can focus on the more fun part of programming: &lt;strong&gt;designing the implementation&lt;/strong&gt;! When we develop in functional languages we often write much less code, in substantially less time, and with fewer bugs.&lt;/p&gt;

&lt;h2&gt;
  
  
  It gives you great career prospects
&lt;/h2&gt;

&lt;p&gt;Many companies have adopted functional programming and there are many opportunities for functional programmers. Companies using Haskell include Facebook, &lt;a href="https://hasura.io/"&gt;Hasura&lt;/a&gt;, etc. Companies using OCaml include &lt;a href="https://ahrefs.com/"&gt;Ahrefs&lt;/a&gt;, &lt;a href="https://www.janestreet.com/"&gt;Jane Street&lt;/a&gt;, etc. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check out &lt;a href="https://functional.works-hub.com/"&gt;Functional Works&lt;/a&gt; for many more companies that are using functional languages!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Functional languages are prominent in blockchain especially. Blockchain is an increasingly popular technology with applications in many areas. The most common uses of the technology include&lt;br&gt;
cryptocurrencies, banking/FinTech, and smart contracts. They all involve financial transactions that are time-sensitive and mistakes can be very costly. Functional languages can minimize these mistakes and therefore many blockchain and related applications are written in functional languages! For example, &lt;a href="https://minaprotocol.com/"&gt;Mina&lt;/a&gt; and &lt;a href="https://tezos.com/"&gt;Tezos&lt;/a&gt; are written in OCaml. &lt;a href="https://cardano.org/"&gt;Cardano&lt;/a&gt;, &lt;a href="https://www.kadena.io/"&gt;Kadena&lt;/a&gt; and &lt;a href="https://blockapps.net/"&gt;BlockApps&lt;/a&gt; are written in Haskell.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check out &lt;a href="https://blockchain.works-hub.com/"&gt;Blockchain Works&lt;/a&gt; for many more blockchain-related companies that are using functional languages!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In conclusion, functional languages have advantages over imperative languages. They are already well-used in the blockchain world and are really catching on in other areas as well. Whether you want to stay up-to-date, expand your career choices, or broaden your programming knowledge, learning functional programming is the ideal choice!&lt;/p&gt;

&lt;p&gt;If I've got you convinced, I've got more good news for you! I'm going to publish a series of posts introducing functional programming concepts. You don't need to have a background in functional programming or even programming. I'll go through practical concepts from beginner to advanced levels with many code examples.&lt;/p&gt;

&lt;p&gt;Stay tuned!&lt;/p&gt;

&lt;p&gt;Originally written by &lt;a href="https://www.works-hub.com/users/8a724570-86e7-4b45-bcb0-b838f2f226ea?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;Marty Stumpf&lt;/a&gt; for &lt;a href="https://www.works-hub.com/learn/why-you-should-learn-functional-programming-50371?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;WorksHub&lt;/a&gt;&lt;/p&gt;

</description>
      <category>haskell</category>
      <category>ocaml</category>
      <category>blockchain</category>
      <category>typedfunctionalprogramming</category>
    </item>
    <item>
      <title>ES2020: New Features &amp; What's Beyond</title>
      <dc:creator>Mihaela</dc:creator>
      <pubDate>Fri, 26 Nov 2021 17:19:27 +0000</pubDate>
      <link>https://forem.com/workshub/es2020-new-features-whats-beyond-5doc</link>
      <guid>https://forem.com/workshub/es2020-new-features-whats-beyond-5doc</guid>
      <description>&lt;p&gt;The world of &lt;strong&gt;JavaScript&lt;/strong&gt;( &lt;em&gt;officially&lt;/em&gt; ECMAScript ) changes fast and with awesome features getting added each year, it's certainly hard to keep up. The last big overhaul happened in &lt;strong&gt;ES2015&lt;/strong&gt; when a bunch of new features, sugarcoated syntax were added to the language.&lt;/p&gt;

&lt;p&gt;ECMAScript community releases new features every year. In this post, we will have a look at &lt;strong&gt;7&lt;/strong&gt; key features that were introduced in &lt;a href="https://262.ecma-international.org/11.0/"&gt;ES2020&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;*&lt;em&gt;Big Int *&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Nullish Coalescing Operator&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Optional Chaining&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Global this&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Promise.allSettled&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dynamic Import&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;String.prototype.matchAll&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Let's get into each one by one&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Big Int
&lt;/h2&gt;




&lt;p&gt;&lt;code&gt;BigInt&lt;/code&gt; is a special data type introduced in ES2020 to define numbers that exceed the &lt;code&gt;Number&lt;/code&gt; data type range. The &lt;code&gt;Number&lt;/code&gt; data type limits between -(2^53-1) to -(2^53-1), which we can check using&lt;br&gt;
&lt;code&gt;Number.MAX_SAFE_INTEGER&lt;/code&gt; &amp;amp; &lt;code&gt;Number.MIN_SAFE_INTEGER&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MIN_SAFE_INTEGER&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// -9007199254740991&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MAX_SAFE_INTEGER&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// 9007199254740991&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Introduction to &lt;code&gt;BigInt&lt;/code&gt; now increases the total number of &lt;code&gt;primitive&lt;/code&gt; data type to &lt;code&gt;8&lt;/code&gt;, the rest being,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Undefined&lt;/li&gt;
&lt;li&gt;Null&lt;/li&gt;
&lt;li&gt;Number&lt;/li&gt;
&lt;li&gt;String&lt;/li&gt;
&lt;li&gt;Object&lt;/li&gt;
&lt;li&gt;Symbol&lt;/li&gt;
&lt;li&gt;Boolean&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To use BigInt, we simply append &lt;code&gt;n&lt;/code&gt; at the very end of an integer, and that would be parsed as a BigInt.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;BigInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    &lt;span class="c1"&gt;// -&amp;gt; 1n&lt;/span&gt;
&lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    &lt;span class="c1"&gt;// -&amp;gt; "bigint"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  a) BigInt Uses :
&lt;/h3&gt;

&lt;p&gt;BigInt is useful in situations where we have to essentially deal with large integers that are beyond the scope of &lt;code&gt;Number&lt;/code&gt;  type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;18014398509481982&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;18014398509481982&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;// -&amp;gt; 36028797018963964n&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  b) BigInt Operations :
&lt;/h3&gt;

&lt;p&gt;All arithmetic operations are valid, the only exception to this is &lt;code&gt;unary plus operator&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;       &lt;span class="c1"&gt;// -&amp;gt; 2n&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;      &lt;span class="c1"&gt;// -&amp;gt; 2n&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;     &lt;span class="c1"&gt;// -&amp;gt; Unary Operator error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same goes for comparison as well, however, strict equality doesn't hold when compared with the &lt;code&gt;Number&lt;/code&gt; data type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;True&lt;/span&gt;
&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;False&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Nullish Coalescing Operator
&lt;/h2&gt;




&lt;p&gt;The Nullish Coalescing operator is not something new but rather a sugarcoated version of a pattern we have been doing for quite a long time.&lt;/p&gt;

&lt;p&gt;Have a look at this piece of code :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Now, nullish coalescing operator would simplify the above logic to :&lt;/span&gt;
&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In simple terms,&lt;/p&gt;

&lt;p&gt;_ &lt;code&gt;??&lt;/code&gt; returns the first argument if it is defined i.e neither &lt;code&gt;null&lt;/code&gt; nor &lt;code&gt;undefined&lt;/code&gt; _&lt;/p&gt;

&lt;p&gt;_ &lt;code&gt;??&lt;/code&gt; returns the second argument if the first argument is either &lt;code&gt;null&lt;/code&gt; or &lt;code&gt;undefined&lt;/code&gt;  _&lt;/p&gt;

&lt;p&gt;Confused? Well let's have a look at few examples to clear up things&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;  &lt;span class="c1"&gt;// 1 (returns the first argument as its neither null nor undefined)&lt;/span&gt;

&lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;  &lt;span class="c1"&gt;// 1 (returns the second argument as the first one is undefined)&lt;/span&gt;

&lt;span class="c1"&gt;// we can even chain up several arguments as well, and the operator would return the first `defined value`&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;country&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;city&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;London&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;country&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="nx"&gt;city&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// London (returns the first `defined value`)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Use case :
&lt;/h3&gt;

&lt;p&gt;Let's say if a user is logged-in, display the first name else display "Anonymous" :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;When&lt;/span&gt; &lt;span class="nx"&gt;logged&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Anonymous&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Alice&lt;/span&gt;

&lt;span class="nx"&gt;When&lt;/span&gt; &lt;span class="nx"&gt;not&lt;/span&gt; &lt;span class="nx"&gt;logged&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Anonymous&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Anonymous&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3.  Optional Chaining
&lt;/h2&gt;




&lt;p&gt;The Optional Chaining Operator introduced in ES2020 is similar to the &lt;code&gt;.&lt;/code&gt; (dot operator). It solves a very specific problem and is useful when we need a property that is nested deep in an object.&lt;/p&gt;

&lt;p&gt;Consider the example below :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;customer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;isSignedIn&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;details&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;age&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Lucy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;Country&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Estonia&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Given the above example is an API response and we aren't sure if the property we are accessing even exists inside the object or not, then traditionally we have to do something like below to make sure we don't have any &lt;code&gt;nullish&lt;/code&gt; value when nesting inside the &lt;code&gt;response&lt;/code&gt; object properties&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;details&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;details&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, with Optional Chaining, we can do :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;details&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript makes sure at each level of the object the property is not nullish (null or undefined), hence proving &lt;code&gt;?.&lt;/code&gt; much practical than plain ol' dot operator.&lt;/p&gt;

&lt;p&gt;Gotchas with :&lt;br&gt;
Optional Chaining throws an error on the left-hand side of an assignment.&lt;br&gt;
The very first property before the &lt;code&gt;?.&lt;/code&gt; must be defined and cannot be invalid.&lt;br&gt;
Similar to &lt;code&gt;?.&lt;/code&gt; we have slightly different variants too :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;?.[] =&amp;gt; calling arrays&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;?.() =&amp;gt; calling functions&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  4. Global this
&lt;/h2&gt;



&lt;p&gt;Think about the number of environments and platforms we run JavaScript in, browsers, smartphones, servers, robotics equipment.&lt;br&gt;
 For each environment, the JavaScript Object model is different and the global object might point to a different property.&lt;/p&gt;

&lt;p&gt;In browsers, the global object could be &lt;code&gt;window&lt;/code&gt;, &lt;code&gt;self&lt;/code&gt; or &lt;code&gt;frame&lt;/code&gt;, depending on the context. However there is no scope of the above-mentioned properties in NodeJs, hence it uses &lt;code&gt;global&lt;/code&gt; to point to its global object.&lt;/p&gt;

&lt;p&gt;Can we see the chaos here? If we have to run our &lt;code&gt;js&lt;/code&gt; code in a range of different environment we need to figure out its global object first and is exactly what we have been doing for so long.&lt;/p&gt;

&lt;p&gt;A common pattern to figure out the global object is as :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getGlobalObject&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;globalThis&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;undefined&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;globalThis&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;undefined&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;undefined&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nb"&gt;global&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;undefined&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;global&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cannot find the global object&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;getGlobalObject&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;allSettled&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;function&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// the Promise.allSettled() Not available in this environment&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, the above solution has its own limitations and trade-offs.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;globalThis&lt;/code&gt; tries to address the issue by pointing &lt;code&gt;globalThis&lt;/code&gt; keyword to its global object model irrespective of the environment(as it is available everywhere). It was introduced in 2020 and currently stands on stage 4 and is available on most browsers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// nodeJS&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;globalThis&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// returns the global object&lt;/span&gt;
&lt;span class="c1"&gt;// browsers&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;globalThis&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// returns the window object&lt;/span&gt;
&lt;span class="c1"&gt;// web-workers&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;globalThis&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// returns the global web workers context&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the introduction of &lt;code&gt;globalThis&lt;/code&gt;, it would be best practice to stop using &lt;code&gt;this&lt;/code&gt; keyword in the context of global objects and start using &lt;code&gt;globalThis&lt;/code&gt;  instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Promise.allSettled
&lt;/h2&gt;




&lt;p&gt;&lt;code&gt;Promise.allSettled()&lt;/code&gt; is a method that takes an iterable object(array) and returns a promise when all the provided promises have either resolved or rejected, meaning it does not short-circuit in the middle.&lt;/p&gt;

&lt;p&gt;The returned outcome is an object with two things :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_a) value -&amp;gt; If the status is fulfilled._

_b) reason -&amp;gt; If the status is rejected._
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;It's hard not to talk about the ES2015's &lt;code&gt;Promise.all&lt;/code&gt; and its similarities/dissimilarities with &lt;code&gt;allSettled&lt;/code&gt;&lt;br&gt;
A striking difference between these two would be &lt;code&gt;all&lt;/code&gt; short-circuits in the middle if any of the provided promises is rejected, while &lt;code&gt;allSettled&lt;/code&gt; waits for async result and filters them by status and never shortcircuits.&lt;/p&gt;

&lt;p&gt;Let's have a look at its working :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;promise1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;yay&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;promise2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;oh-no&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;


    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;allSettled&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;promise1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;promise2&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
     &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;


    &lt;span class="p"&gt;})();&lt;/span&gt;
 &lt;span class="c1"&gt;// Output:&lt;/span&gt;
 &lt;span class="c1"&gt;// [&lt;/span&gt;
 &lt;span class="c1"&gt;// { status: 'fulfilled', value: 'yay' },&lt;/span&gt;
 &lt;span class="c1"&gt;// { status: 'rejected', reason: 'oh-no' },&lt;/span&gt;
 &lt;span class="c1"&gt;// ]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we compare it with &lt;code&gt;all&lt;/code&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;promise1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;yay&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;promise2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;oh-no&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;


    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;allSettled&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;promise1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;promise2&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
     &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;
     &lt;span class="p"&gt;})()&lt;/span&gt;

 &lt;span class="c1"&gt;// Output:&lt;/span&gt;
 &lt;span class="c1"&gt;// Error : "oh-no" &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Dynamic Import
&lt;/h2&gt;




&lt;p&gt;The amount of JS heavy apps we ship these days can be quite overwhelming and with these lot of javascript files, the module import/export should be effective.&lt;/p&gt;

&lt;p&gt;ES2020's dynamic import addresses this issue to make the page load ups, first meaningful paint etc efficient and fast.&lt;br&gt;
This is done by dynamically importing the files that we need at that point in time.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;import&lt;/code&gt; keyword was introduced in &lt;code&gt;ES2015&lt;/code&gt;, and we have been importing modules like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;ES2020 allows us to use &lt;code&gt;import&lt;/code&gt; as a function (although it looks like a function, it is not)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// we dont need to set type of module below&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./add.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;//returns 10&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;// log error here);&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above piece of code makes sure the &lt;code&gt;add.js&lt;/code&gt; module is only imported when we need to sum up two numbers. It doesn't unnecessarily bloat up the js code which could make page loads slow. &lt;/p&gt;

&lt;h2&gt;
  
  
  7. String.prototype.matchAll
&lt;/h2&gt;




&lt;p&gt;&lt;code&gt;matchAll&lt;/code&gt; is a new method that is added to the string prototype. This returns an iterator matching against a regular expression that we have given.&lt;/p&gt;

&lt;p&gt;A simple example to demonstrate the same :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;climbing, oranges, jumping, flying, carrot&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;regex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;([&lt;/span&gt;&lt;span class="sr"&gt;a-z&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="sr"&gt;ing/g&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;matches&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;matchAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;)];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="c1"&gt;// outputs the following :&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;climb&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;jump&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fly&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;While we just finished learning &lt;strong&gt;ES2020&lt;/strong&gt;, the &lt;strong&gt;ES2021&lt;/strong&gt; has already been drafted for its next release. Here's what's in the box for us :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;String.prototype.replaceAll&lt;/li&gt;
&lt;li&gt;Promise.any&lt;/li&gt;
&lt;li&gt;Logical Operators and Assignment Expressions&lt;/li&gt;
&lt;li&gt;Numeric Separators&lt;/li&gt;
&lt;li&gt;WeakRefs&lt;/li&gt;
&lt;li&gt;Intl.ListFormat&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;*&lt;em&gt;Some Important Resources that I have collected over time: *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;i. &lt;a href="https://auth0.com/blog/javascript-whats-new-es2020/"&gt;https://auth0.com/blog/javascript-whats-new-es2020/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;ii. &lt;a href="https://www.martinmck.com/posts/es2020-everything-you-need-to-know/"&gt;https://www.martinmck.com/posts/es2020-everything-you-need-to-know/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;iii. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;iv. &lt;a href="https://blog.tildeloop.com/posts/javascript-the-difference-between-match-and-matchall"&gt;https://blog.tildeloop.com/posts/javascript-the-difference-between-match-and-matchall&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Loved this post? Have a suggestion or just want to say hi? Reach out to me on &lt;a href="https://twitter.com/abhinavanshul03"&gt;Twitter&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Originally written by &lt;a href="https://javascript.works-hub.com/users/c49b5fad-2fef-4acc-aa7a-7cd78f11c9a1?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;Abhinav Anshul&lt;/a&gt; for &lt;a href="https://javascript.works-hub.com/learn/es2020-new-features-and-whats-beyond-157e2?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;JavaScript Works&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>vanillajavascript</category>
    </item>
    <item>
      <title>A Complete Beginner's Guide to React useState hook [Part 1]</title>
      <dc:creator>Mihaela</dc:creator>
      <pubDate>Fri, 26 Nov 2021 17:17:36 +0000</pubDate>
      <link>https://forem.com/workshub/a-complete-beginners-guide-to-react-usestate-hook-part-1-1hff</link>
      <guid>https://forem.com/workshub/a-complete-beginners-guide-to-react-usestate-hook-part-1-1hff</guid>
      <description>&lt;p&gt;Hi 👋&lt;/p&gt;

&lt;p&gt;In this article, we will deep dive into the world of React hooks, &lt;code&gt;useState&lt;/code&gt; in particular from a beginner's point of view.&lt;br&gt;
React Hooks are the result of a continuous rise in functional programming over the years.&lt;/p&gt;

&lt;p&gt;We will have a look at its working, common mistakes we are likely to encounter, comparing it with class-based components and best practices.&lt;/p&gt;

&lt;p&gt;useState is a &lt;a href="https://reactjs.org/docs/hooks-intro.html"&gt;React Hook&lt;/a&gt; introduced late in &lt;a href="https://www.youtube.com/watch?v=dpw9EHDh2bM&amp;amp;ab_channel=ReactConf"&gt;October 2018&lt;/a&gt;, which allows us to have state variables in the JSX functional component. we pass an initial value to this function, and it returns a variable with a new state based on functional logic.&lt;/p&gt;

&lt;p&gt;Let's go through the following topic one-by-one:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is React useState hook?&lt;/li&gt;
&lt;li&gt;Declaration useState hook in React&lt;/li&gt;
&lt;li&gt;Understanding &amp;amp; implementation using a simple counter application.&lt;/li&gt;
&lt;li&gt;Comparing it to a class-based component&lt;/li&gt;
&lt;li&gt;Handling multiple states in a single component.&lt;/li&gt;
&lt;li&gt;Gotchas&lt;/li&gt;
&lt;li&gt;Common Mistakes&lt;/li&gt;
&lt;li&gt;Why someone would use a hook?&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  1. What is React useState hook?
&lt;/h3&gt;

&lt;p&gt;Hmm, an interesting question! &lt;br&gt;
As we stated earlier, the useState hook allows us to have state variables in the JSX functional component.&lt;br&gt;
It takes one argument which is the &lt;code&gt;initial state&lt;/code&gt; and returns a state value and a function to update it.&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Declaration of useState hook
&lt;/h3&gt;

&lt;p&gt;useState is a named export from React,&lt;br&gt;
So, we can either do&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*or simply, *&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useState&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The former approach is much common across codebases and mentioned in the &lt;a href="https://reactjs.org/docs/hooks-state.html"&gt;official react docs&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  3. Understanding and Implementation
&lt;/h3&gt;

&lt;p&gt;It's always a good idea to try things out ourselves rather than reading documentation, so let's jump right into the code.&lt;/p&gt;

&lt;p&gt;We'll build a counter application and to keep things simpler, we won't go into prevState (yet), see point 7(ii)&lt;/p&gt;

&lt;p&gt;As we can see, we are importing the &lt;code&gt;useState&lt;/code&gt; hook at top of the file, and a handful of CSS styles to keep things centered and clean enough.&lt;/p&gt;

&lt;p&gt;Moving further, we have a functional JSX component called &lt;code&gt;App&lt;/code&gt;, which is rendering increment and decrement buttons and a &lt;code&gt;count&lt;/code&gt; text in between. This count will render every time the state gets updated by the button clicks.&lt;/p&gt;

&lt;p&gt;The useState hook takes an initial state, &lt;code&gt;count&lt;/code&gt; in this case, and returns a pair of variables, &lt;code&gt;count&lt;/code&gt; and &lt;code&gt;setCount&lt;/code&gt;, where &lt;code&gt;count&lt;/code&gt; is the current state (currently set to 0) whereas &lt;code&gt;setCount&lt;/code&gt; is a function which updates it asynchronously.&lt;/p&gt;

&lt;p&gt;At line number &lt;code&gt;6&lt;/code&gt;, we are using array destructuring to return the pair of variables at array index of 0 &amp;amp; 1.&lt;/p&gt;

&lt;p&gt;(Read more about &lt;strong&gt;array destructuring&lt;/strong&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment"&gt;here&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Moving on, both the button has an &lt;code&gt;onClick&lt;/code&gt; event, which triggers an anonymous function, which increments or decrements the count variable using the &lt;code&gt;setCount&lt;/code&gt; function. This click even results in the re-rendering of the &lt;code&gt;count&lt;/code&gt; state.&lt;/p&gt;

&lt;p&gt;Similar to the &lt;code&gt;count&lt;/code&gt; state variable, we are allowed to use different data types such as objects, arrays, strings, boolean, etc.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;firstname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setFirstname&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setAge&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;isLoggedin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setIsLoggedin&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;form&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setForm&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;username&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;password&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can see, all the above useState hooks are valid state data types.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Comparing it to a class-based component
&lt;/h3&gt;

&lt;p&gt;While the &lt;code&gt;useState&lt;/code&gt; hook is a new addition to the React library, it somewhat does the same thing as &lt;code&gt;this.state&lt;/code&gt; used with class-based components. &lt;br&gt;
Confused?&lt;br&gt;&lt;br&gt;
Let's see how we would write the same counter app in a &lt;code&gt;class&lt;/code&gt; based component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Counter&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// change code below this line&lt;/span&gt;

  &lt;span class="nx"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="nx"&gt;decrement&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;

   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;inc&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Increment&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dec&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;decrement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Decrement&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Current&lt;/span&gt; &lt;span class="nx"&gt;Count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. Handling multiple states in a single component
&lt;/h3&gt;

&lt;p&gt;Oh! what if we have multiple states to handle and not just a silly count variable, what about then? Where do we store those variables? Are they similar to &lt;code&gt;this.state&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;Well, handling of multiple state variables is somewhat different in useState compared to &lt;code&gt;this.state&lt;/code&gt; &lt;br&gt;
In useState, we tend to write as many state hooks as there are states&lt;br&gt;
Like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;lastname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setLastname&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;firstname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setFirstname&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setAge&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or group similar things together using an initial state object&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;islogin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setIslogin&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;username&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;password&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, when building quite a large application it is incredibly difficult to keep track of all the useState hooks and is not very practical, hence useReducer comes into the picture, which is beyond the scope of this article. &lt;br&gt;
Read more about useReducer &lt;a href="https://reactjs.org/docs/hooks-reference.html#usereducer"&gt;here&lt;/a&gt; &lt;/p&gt;
&lt;h3&gt;
  
  
  6. Gotchas
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;i&lt;/strong&gt;. We can only use &lt;code&gt;useState&lt;/code&gt; (or any other hook) inside a function component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ii&lt;/strong&gt;. React Hooks must be called in the same order in every component render, in simpler words, any hook should be at the very top and inside the function component without any unnecessary check, loops, etc&lt;br&gt;
For example, the following code is wrong, and won't behave as we expect&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;iii&lt;/strong&gt; When we update the state, the component re-renders each time.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Common Mistakes
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;i.&lt;/strong&gt; Never ever update the state directly, like this :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;incrementCount&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead, we have a function (remember setCount function?) that will manipulate the state variable as we need,&lt;br&gt;
Similar to this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;incrementCount&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or, we can use an &lt;code&gt;anonymous function&lt;/code&gt; like how we used it in the first counter application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ii.&lt;/strong&gt; Remember, how we talked about, "Keeping things simpler" at the very beginning of this article, well, this is the moment!&lt;/p&gt;

&lt;p&gt;In order to use useState effectively, we absolutely want to change and mutate the state variable based on its &lt;code&gt;initial state&lt;/code&gt;, and don't want unexpected rendering.&lt;br&gt;
To do so, we need to pass a previous state parameter to the function and based on that, mutating the state variable.&lt;br&gt;
Confused?&lt;br&gt;
Okay, Let's see some code!&lt;/p&gt;

&lt;p&gt;&lt;code&gt;setCount(count + 1)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;should be&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;setCount(prevState =&amp;gt; prevState + 1)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here, &lt;code&gt;prevState&lt;/code&gt; ensures us to give us current value of &lt;code&gt;count&lt;/code&gt; no matter what, and in fact a better and recommended way to write hooks!&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Why someone would use a hook?
&lt;/h3&gt;

&lt;p&gt;i. Easier to test.&lt;/p&gt;

&lt;p&gt;ii. Provides good readability.&lt;/p&gt;

&lt;p&gt;iii. Performance boost.&lt;/p&gt;

&lt;p&gt;iv. Reduction in bundle size.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Important Resources that I have collected over time 😃 *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;i. &lt;a href="https://medium.com/@quinnlashinsky/destructuring-arrays-in-javascript-2cb003160b3a"&gt;https://medium.com/@quinnlashinsky/destructuring-arrays-in-javascript-2cb003160b3a&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;ii. &lt;a href="https://levelup.gitconnected.com/react-hooks-gotchas-setstate-in-async-effects-d2fd84b02305"&gt;https://levelup.gitconnected.com/react-hooks-gotchas-setstate-in-async-effects-d2fd84b02305&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;iii. &lt;a href="https://www.youtube.com/watch?v=O6P86uwfdR0&amp;amp;t=221s&amp;amp;ab_channel=WebDevSimplified"&gt;https://www.youtube.com/watch?v=O6P86uwfdR0&amp;amp;t=221s&amp;amp;ab_channel=WebDevSimplified&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Originally written by &lt;a href="https://javascript.works-hub.com/users/c49b5fad-2fef-4acc-aa7a-7cd78f11c9a1?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;Abhinav Anshul&lt;/a&gt; for &lt;a href="https://javascript.works-hub.com/learn/a-complete-beginners-guide-to-react-usestate-hook-f85a0?utm_source=dev_to&amp;amp;utm_medium=blog_xpost"&gt;JavaScript Works&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>beginners</category>
      <category>reacthooks</category>
    </item>
  </channel>
</rss>
