<?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: Narender Saini</title>
    <description>The latest articles on Forem by Narender Saini (@narendersaini32).</description>
    <link>https://forem.com/narendersaini32</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%2F343123%2Fe7cf1914-a35f-4755-9cdb-e0ca01a9125a.png</url>
      <title>Forem: Narender Saini</title>
      <link>https://forem.com/narendersaini32</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/narendersaini32"/>
    <language>en</language>
    <item>
      <title>How to add less and svg support to Nextjs</title>
      <dc:creator>Narender Saini</dc:creator>
      <pubDate>Sun, 18 Oct 2020 03:25:21 +0000</pubDate>
      <link>https://forem.com/narendersaini32/how-to-add-less-and-svg-support-to-nextjs-1h4b</link>
      <guid>https://forem.com/narendersaini32/how-to-add-less-and-svg-support-to-nextjs-1h4b</guid>
      <description>&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%2Fi2.wp.com%2Fblogreact.com%2Fwp-content%2Fuploads%2F2020%2F10%2F1_htbUdWgFQ3a94PMEvBr_hQ.png%3Fresize%3D750%252C428%26ssl%3D1" 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%2Fi2.wp.com%2Fblogreact.com%2Fwp-content%2Fuploads%2F2020%2F10%2F1_htbUdWgFQ3a94PMEvBr_hQ.png%3Fresize%3D750%252C428%26ssl%3D1" alt="How to add less and svg support to Nextjs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have you ever face a situation where you want to use less and SVG images with nextjs and you don’t want to spend time making configuration with webpack. Honestly webpack configuration is not that straight forward. Still in 2020 webpack config feels too complicated to even experienced developers. In this article we will gonna add support for less and svg images to Nextjs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Less support
&lt;/h2&gt;

&lt;p&gt;Less is a dynamic preprocessor style sheet language that can be compiled into Cascading Style Sheets and run on the client side or server side. In other words less includes a lot of features along with normal css.&lt;/p&gt;

&lt;p&gt;To add the support of less to nextjs you need to install two packages  &lt;strong&gt;@zeit/next-less&lt;/strong&gt;  and  &lt;strong&gt;less&lt;/strong&gt;  from npm.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save less @zeit/next-less
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the package installation include a file named  &lt;strong&gt;next.config.js&lt;/strong&gt;  in root of your project.&lt;/p&gt;

&lt;p&gt;Add less config with just 2-3 lines.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const withLess = require('@zeit/next-less');

module.exports = withLess({
  /* config options here */
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that’s it now you app supports less. Just try adding a less file and import in your app.&lt;/p&gt;

&lt;h2&gt;
  
  
  SVG support
&lt;/h2&gt;

&lt;p&gt;Scalable Vector Graphics is an Extensible Markup Language-based vector image format for two-dimensional graphics with support for interactivity and animation. The SVG specification is an open standard developed by the World Wide Web Consortium since 1999.&lt;/p&gt;

&lt;p&gt;Adding svg support to frontend frameworks or library is always interesting. To add the support we will gonna need a package for that i.e  &lt;strong&gt;&lt;a href="https://www.npmjs.com/package/next-images" rel="noopener noreferrer"&gt;next-images&lt;/a&gt;&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save next-images
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the installation just add image config to  &lt;strong&gt;next.config.js&lt;/strong&gt;  file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const withImages = require('next-images');
module.exports = withImages();

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

&lt;/div&gt;



&lt;p&gt;That’s it. To use the svgs just add a file svg file or a jsx file.&lt;/p&gt;

&lt;p&gt;To set the images in background always use  &lt;strong&gt;.svg&lt;/strong&gt;  format and to render the svg images use &lt;strong&gt;.jsx&lt;/strong&gt;  to render as a 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 { BgLeafIcon } from '../images'; //mage.svg
...
  &amp;lt;div
      className="bg-image"
      style={{ backgroundImage: `url(${BgLeafIcon})` }}
    &amp;gt;

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

&lt;/div&gt;



&lt;p&gt;or you can use as a 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 { BgLeafIcon } from '../images'; //mage.jsx
...
&amp;lt;BgLeafIcon/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope this article will be helpful to you guys. Feel free to comment your valuable thoughts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blogreact.com/cookie-in-react/" rel="noopener noreferrer"&gt;How to use Cookie in React&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>html</category>
    </item>
    <item>
      <title>How to make wiggly div in React</title>
      <dc:creator>Narender Saini</dc:creator>
      <pubDate>Sun, 11 Oct 2020 03:13:45 +0000</pubDate>
      <link>https://forem.com/narendersaini32/how-to-make-wiggly-div-in-react-2282</link>
      <guid>https://forem.com/narendersaini32/how-to-make-wiggly-div-in-react-2282</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lJhvvGva--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i2.wp.com/blogreact.com/wp-content/uploads/2020/09/wiv.js-1.gif%3Fresize%3D344%252C172%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lJhvvGva--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i2.wp.com/blogreact.com/wp-content/uploads/2020/09/wiv.js-1.gif%3Fresize%3D344%252C172%26ssl%3D1" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Making Wiggly div is most interesting and at the same time a complex thing. It will be good for cases for like some cool portfolio, a landing page with some important text etc. Its more like making a div more funny. In this article we will gonna learn how we can create a wiggly div in React.&lt;/p&gt;

&lt;h2&gt;
  
  
  react-wiv
&lt;/h2&gt;

&lt;p&gt;This package is a react version of wiv.js. It uses a library named wiv.js internally. It super simple and easy to create wiggly div using react-wiv. In just few lines of code we can accomplish our task without need to worry about the complexity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation and Usage
&lt;/h2&gt;

&lt;p&gt;Like any other npm package we can install it using npm command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save react-wiv
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once this package is installed. You need to import this package using below code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Wiv from 'react-wiv'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and we are good to use it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Wiv color="#00FF00" height={4} tightness={6} thickness={2} speed={0.55}&amp;gt;
        Blogreact
      &amp;lt;/Wiv&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We just provided few props like color, height, speed etc and got this output.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--w85B6GeJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i0.wp.com/blogreact.com/wp-content/uploads/2020/09/image-3.png%3Fresize%3D125%252C63%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--w85B6GeJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i0.wp.com/blogreact.com/wp-content/uploads/2020/09/image-3.png%3Fresize%3D125%252C63%26ssl%3D1" alt="output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Checkout the live demo using below link.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codesandbox.io/s/nostalgic-tereshkova-o4pw9?file=/src/App.js:156-260"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pzpI10jk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codesandbox.io/static/img/play-codesandbox.svg" alt="Edit o4pw9"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ndresselhaus.github.io/react-wiv/"&gt;More demos&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to comment your thoughts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blogreact.com/send-sms-using-bandwidth/"&gt;How to send SMS using Bandwidth in Node&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>css</category>
    </item>
    <item>
      <title>Generate pdf from dom with multiple pages and without cutting</title>
      <dc:creator>Narender Saini</dc:creator>
      <pubDate>Sat, 12 Sep 2020 02:48:05 +0000</pubDate>
      <link>https://forem.com/narendersaini32/generate-pdf-from-dom-with-multiple-pages-and-without-cutting-lc1</link>
      <guid>https://forem.com/narendersaini32/generate-pdf-from-dom-with-multiple-pages-and-without-cutting-lc1</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--d967nvmA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i0.wp.com/blogreact.com/wp-content/uploads/2020/09/banner-772x250-1.png%3Fresize%3D750%252C243%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--d967nvmA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i0.wp.com/blogreact.com/wp-content/uploads/2020/09/banner-772x250-1.png%3Fresize%3D750%252C243%26ssl%3D1" alt="Generate pdf from dom with multiple pages and without cutting "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the last article we learned about how we can generate pdf from dom elements but there was some bottleneck like that method was only adding one big page and sometime div are cut in half i.e some portion of the div were displaying in the next page. In this article we will gonna learn how we can generate pdf from dom with multiple pages and without cutting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dom to pdf
&lt;/h2&gt;

&lt;p&gt;We will gonna use a package name  &lt;a href="https://www.npmjs.com/package/dom-to-pdf"&gt;dom-to-pdf&lt;/a&gt;  in today article. This package basically convert html elements into canvas and svg. After that it converts canvas into the pdf.&lt;/p&gt;

&lt;p&gt;This package is more simple and easy to use as compare to last article. In the last article we were using the two different packages one package is converting the dom into an image and then other package was converting the image into the dom. But with dom-to-pdf we can do both the things with single package.&lt;/p&gt;

&lt;p&gt;The plus point of this package is it automatically manage the multiple pages format and at the same time it also manage that the content should not be cut while adding into the pdf. In other words no div will gonna be cut in parts while adding to the pdf instead of that it will gonna add whole div to next page which is very useful for most of the cases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation and Usage
&lt;/h2&gt;

&lt;p&gt;We can install this package from npm simply.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save dom-to-pdf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After the installation import this package one time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import domToPdf from 'dom-to-pdf';
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;domToPdf will gonna receive three arguments.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  First argument will be the dom element.&lt;/li&gt;
&lt;li&gt;  Second argument will be the option object.&lt;/li&gt;
&lt;li&gt;  Third will be a callback function.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const element = document.querySelector('.summary-report-container');

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





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const options = {
      filename: "test.pdf",
    };
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;domToPdf(element, options, () =&amp;gt; {
// callback function
    });
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The whole pdf generate function will be gonna look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  generatePdf = () =&amp;gt; {

    const element = document.querySelector('.summary-report-container');

    const options = {
      filename: "test.pdf",
    };

    return domToPdf(element, options, () =&amp;gt; {
      // callback function
    });
  }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It will gonna save the pdf automatically after generation. This way you can generate the pdf with multiple pages and without cutting the content.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blogreact.com/how-to-create-range-slider-with-bubble-in-react/"&gt;How to create range slider with bubble in React&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
    </item>
    <item>
      <title>How to create range slider with bubble in React</title>
      <dc:creator>Narender Saini</dc:creator>
      <pubDate>Sat, 05 Sep 2020 03:23:53 +0000</pubDate>
      <link>https://forem.com/narendersaini32/how-to-create-range-slider-with-bubble-in-react-2eep</link>
      <guid>https://forem.com/narendersaini32/how-to-create-range-slider-with-bubble-in-react-2eep</guid>
      <description>&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%2Fi1.wp.com%2Fblogreact.com%2Fwp-content%2Fuploads%2F2020%2F09%2FSlider-Range-Weight.gif%3Fresize%3D666%252C333%26ssl%3D1" 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%2Fi1.wp.com%2Fblogreact.com%2Fwp-content%2Fuploads%2F2020%2F09%2FSlider-Range-Weight.gif%3Fresize%3D666%252C333%26ssl%3D1" alt="How to create range slider with bubble in React"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s assume we have to implement a range slider with bubble. To achieve that maybe most of the developers gonna look for already created solutions/packages. But sometime we don’t get exact thing that we are looking for in that case we need to create that component from scratch. In this article we will gonna create our own range slider with bubble in React.&lt;/p&gt;

&lt;h2&gt;
  
  
  What exactly we gonna do ?
&lt;/h2&gt;

&lt;p&gt;We will gonna create one parent div with two child. The first child will be an range input and the second child will gonna be a div with input value. Which will gonna move according to the slider position.&lt;/p&gt;

&lt;p&gt;Native input with range type will gonna be a best choice because it handles a lot of stuff under the hood. But for value bubble we need to write our own code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Steps
&lt;/h2&gt;

&lt;p&gt;First of all create a parent div with position relative. Which we needed for the bubble position logic.&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 className="slider-parent"&amp;gt;

    &amp;lt;/div&amp;gt;


.slider-parent{
  position:relative;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now add the first child i.e input with type range.&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;input type="range" min="1" max="500" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add state as well for easy managment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [value,onChange]=useState(1);

&amp;lt;input 
type="range"
min="1" 
max="500"
value={value}
onChange={({ target: { value: radius } }) =&amp;gt; {
                    onChange(radius);
                  }}
      /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add our output bubble div which will gonna hold the value.&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 className="buble"&amp;gt; 
      {value}
      &amp;lt;/div&amp;gt;

.buble{
  position:absolute;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now it’s time to add the function for updating the position of our bubble.&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;{
      const ele = document.querySelector('.buble');
    if (ele) {
      ele.style.left = `${Number(value / 4)}px`;
    }
  })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In above function we are updating our bubble left value according to our input value.&lt;/p&gt;

&lt;p&gt;The next question will be why we are diving value by 4.&lt;/p&gt;

&lt;p&gt;Let’s assume current value of our input is 428. Now we will gonna adjust the left value manually. We can see at 96px our bubble is aligned. So we need to find a ration value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;currentValue = 428;
bubbleManualADjustValue = 96px;
ratio = currentValue/bubbleManualADjustValue;
ratio = 4;
// Now if we divide our value with ratio we can get our position for bubble.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will gonna get output like this.&lt;/p&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%2Fi0.wp.com%2Fblogreact.com%2Fwp-content%2Fuploads%2F2020%2F09%2Fimage-1.png%3Fresize%3D168%252C52%26ssl%3D1" 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%2Fi0.wp.com%2Fblogreact.com%2Fwp-content%2Fuploads%2F2020%2F09%2Fimage-1.png%3Fresize%3D168%252C52%26ssl%3D1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can write a reusable function for above case.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Full code&lt;/strong&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,{useState,useEffect} from "react";
import "./styles.css";

export default function App() {
  const [value,onChange]=useState(1);

  useEffect(()=&amp;gt;{
      const ele = document.querySelector('.buble');
    if (ele) {
      ele.style.left = `${Number(value / 4)}px`;
    }
  })

  return (
    &amp;lt;div className="slider-parent"&amp;gt;
      &amp;lt;input type="range" min="1" max="500" value={value}
         onChange={({ target: { value: radius } }) =&amp;gt; {
                    onChange(radius);
                  }}
      /&amp;gt;
      &amp;lt;div className="buble"&amp;gt; 
      {value}
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.App {
  font-family: sans-serif;
  text-align: center;
}
.slider-parent{
  position:relative;
}

.buble{
  position:absolute;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://codesandbox.io/s/dazzling-galileo-01g0g?file=/src/App.js" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodesandbox.io%2Fstatic%2Fimg%2Fplay-codesandbox.svg" alt="Edit 01g0g"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to check code on codesandbox and give your valuable comments. I hope you have learned something new.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blogreact.com/webix/" rel="noopener noreferrer"&gt;Speed up web development using Webix&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
    </item>
    <item>
      <title>What’s new in React v17.0 ?</title>
      <dc:creator>Narender Saini</dc:creator>
      <pubDate>Sat, 29 Aug 2020 03:23:45 +0000</pubDate>
      <link>https://forem.com/narendersaini32/what-s-new-in-react-v17-0-53cc</link>
      <guid>https://forem.com/narendersaini32/what-s-new-in-react-v17-0-53cc</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yeHHdcBX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i2.wp.com/blogreact.com/wp-content/uploads/2020/08/maxresdefault.jpg%3Fresize%3D750%252C422%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yeHHdcBX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i2.wp.com/blogreact.com/wp-content/uploads/2020/08/maxresdefault.jpg%3Fresize%3D750%252C422%26ssl%3D1" alt="What's new in React v17.0 ?"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Most of the React developers know that few days ago React released there new version. It’s more then 2 years since the last update in React. In this article we will gonna talk about new features came in the React v17.0.&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s new ?
&lt;/h2&gt;

&lt;p&gt;In React v17.0 there is no new features. It’s hard to believe but that’s true. Instead of adding new features they resolved a big issue with React i.e upgrading. In the past whenever there is new version of React released it’s too much difficult to upgrade. For example  &lt;strong&gt;legacy context&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Deprecating the legacy context API, are impossible to do in an automated way. In this case React had two options they can end support for legacy context or they can continue the support. These both options are not that much good. The solution to above problem is came in v17.0.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gradual Upgrades
&lt;/h2&gt;

&lt;p&gt;In the past developers just need to upgrade there whole app to a new version or they can stick to there old version. There was no win win situation for developers. But now with the gradual upgrade we can use two versions of React in same page.&lt;/p&gt;

&lt;p&gt;In simple terms with the release of v17 you can run one part of your app with React old version and another part with latest version at the same time.&lt;/p&gt;

&lt;p&gt;The gradual upgrade will only gonna beneficial in special cases where upgrading whole app to a new version is not an option like an old codebase with less maintenance. Otherwise upgrading to latest version is still the best way to use React.&lt;/p&gt;

&lt;h2&gt;
  
  
  Event Delegation updated
&lt;/h2&gt;

&lt;p&gt;Previously React used to add the event listener like onClick events to document node which become the bottleneck for future updates. But now instead of attaching event to document node it will gonna attach them to root element of your app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Af4h7ktI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i2.wp.com/blogreact.com/wp-content/uploads/2020/08/react_17_delegation.png%3Fresize%3D750%252C580%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Af4h7ktI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i2.wp.com/blogreact.com/wp-content/uploads/2020/08/react_17_delegation.png%3Fresize%3D750%252C580%26ssl%3D1" alt="Event Delegation updated"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks to this change, it is now safer to embed a React tree managed by one version inside a tree managed by a different React version. Note that for this to work, both of the versions would need to be 17 or higher, which is why upgrading to React 17 is important.&lt;/p&gt;

&lt;p&gt;React &lt;code&gt;onFocus&lt;/code&gt; and &lt;code&gt;onBlur&lt;/code&gt; events have switched to using the native &lt;code&gt;focusin&lt;/code&gt; and &lt;code&gt;focusout&lt;/code&gt; events under the hood, which more closely match React’s existing behavior and sometimes provide extra information.&lt;/p&gt;

&lt;p&gt;Checkout the demo for  &lt;a href="https://github.com/reactjs/react-gradual-upgrade-demo/"&gt;gradual upgrade&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blogreact.com/glide-with-react/"&gt;How to use Glide with React&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>html</category>
    </item>
    <item>
      <title>How to use Glide with React</title>
      <dc:creator>Narender Saini</dc:creator>
      <pubDate>Sat, 22 Aug 2020 03:10:53 +0000</pubDate>
      <link>https://forem.com/narendersaini32/how-to-use-glide-with-react-2kp1</link>
      <guid>https://forem.com/narendersaini32/how-to-use-glide-with-react-2kp1</guid>
      <description>&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%2Fi2.wp.com%2Fblogreact.com%2Fwp-content%2Fuploads%2F2020%2F08%2Fglidejs-cover.jpg%3Fresize%3D750%252C392%26ssl%3D1" 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%2Fi2.wp.com%2Fblogreact.com%2Fwp-content%2Fuploads%2F2020%2F08%2Fglidejs-cover.jpg%3Fresize%3D750%252C392%26ssl%3D1" alt="How to use Glide  with React"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Adding a slider or carousel is one of the interesting thing but at the same its complex as well mainly the part where you need to manage the responsiveness. Sliders uses various methods like css transform to hide and show the current slide in the view port. In this article we will gonna look at how to use Glide with React.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Glide ?
&lt;/h2&gt;

&lt;p&gt;Glide is a package which is developed using the ES6. It’s a dependency free package. It is super light weight and flexible. The size of this package is around  &lt;strong&gt;7KB&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It is developed using the JavaScript without using any external dependency. Thanks to developers this package is developed using the modular approach i.e if you need only selected functionality from this package you can do that and you can drop more weight in production builds.&lt;/p&gt;

&lt;p&gt;It supports both Rollup and webpack. If you need to add themes and custom styling you can do that using css and scss.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;The best way to install glide is using the npm. Which result in trouble free integration with webpack and rollup.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install @glidejs/glide
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;Let’s import Glide using there package.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Glide from '@glidejs/glide'

new Glide('.glide').mount()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Need a few selected modules? Import and mount only needed components. In pair with a bundler’s tree-shaking it’s a great way to reduce the total weight your code!&lt;/p&gt;

&lt;p&gt;If you need Breakpoints and controls you can also import them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Glide, { Controls, Breakpoints } from '@glidejs/glide/dist/glide.modular.esm'

new Glide('.glide').mount({ Controls, Breakpoints })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;Let’s make an dummy example to test the glide.&lt;/p&gt;

&lt;p&gt;First of all we need to render our html part.&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="glide"&amp;gt;
        &amp;lt;div class="glide__arrows" data-glide-el="controls"&amp;gt;
          &amp;lt;button class="glide__arrow glide__arrow--left" data-glide-dir="&amp;lt;"&amp;gt;
            Prev
          &amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="glide__track" data-glide-el="track"&amp;gt;
          &amp;lt;ul class="glide__slides"&amp;gt;
            &amp;lt;li class="glide__slide"&amp;gt;0&amp;lt;/li&amp;gt;
            &amp;lt;li class="glide__slide"&amp;gt;1&amp;lt;/li&amp;gt;
            &amp;lt;li class="glide__slide"&amp;gt;2&amp;lt;/li&amp;gt;
          &amp;lt;/ul&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="glide__arrows" data-glide-el="controls"&amp;gt;
          &amp;lt;button class="glide__arrow glide__arrow--right" data-glide-dir="&amp;gt;"&amp;gt;
            Next
          &amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Glide will understand our slide structure using the className. So, you can use same className like glide, glide_arrow, glide_slide etc.&lt;/p&gt;

&lt;p&gt;Now import some stylesheets from glide for getting default UI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Required Core Stylesheet
import "@glidejs/glide/src/assets/sass/glide.core";

// Optional Theme Stylesheet
import "@glidejs/glide/src/assets/sass/glide.theme";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;import package.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Glide from "@glidejs/glide";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we just need to pass the parent className and few options.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
new Glide(".glide", {
  peek: 50,
  perView: 2,
  type: "carousel"
}).mount();

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

&lt;/div&gt;



&lt;p&gt;You will be able to see output similar to this.&lt;/p&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%2Fi1.wp.com%2Fblogreact.com%2Fwp-content%2Fuploads%2F2020%2F08%2Fimage-10.png%3Fresize%3D750%252C229%26ssl%3D1" 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%2Fi1.wp.com%2Fblogreact.com%2Fwp-content%2Fuploads%2F2020%2F08%2Fimage-10.png%3Fresize%3D750%252C229%26ssl%3D1" alt="How to use Glide  with React"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codesandbox.io/s/kind-haze-nrgm9?file=/src/index.js" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodesandbox.io%2Fstatic%2Fimg%2Fplay-codesandbox.svg" alt="Edit nrgm9"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Checkout the whole demo on Codesandbox.&lt;/p&gt;

&lt;p&gt;I hope you have learned how to use glide with React. Feel free to write down your comments.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blogreact.com/swiper/" rel="noopener noreferrer"&gt;How to use Swiper with React Apps&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
    </item>
    <item>
      <title>How to add Animated typing to your React App
</title>
      <dc:creator>Narender Saini</dc:creator>
      <pubDate>Sat, 15 Aug 2020 03:44:42 +0000</pubDate>
      <link>https://forem.com/narendersaini32/how-to-add-animated-typing-to-your-react-app-3bgl</link>
      <guid>https://forem.com/narendersaini32/how-to-add-animated-typing-to-your-react-app-3bgl</guid>
      <description>&lt;p&gt;&lt;a href="https://camo.githubusercontent.com/4737e3d76d0b124e49bce863013e08f0b8eb664d/68747470733a2f2f63646e2e7261776769742e636f6d2f6c75697376696e69636975733136372f6974797065642f6d61737465722f696d672f6974797065646a732e676966" class="article-body-image-wrapper"&gt;&lt;img src="https://camo.githubusercontent.com/4737e3d76d0b124e49bce863013e08f0b8eb664d/68747470733a2f2f63646e2e7261776769742e636f6d2f6c75697376696e69636975733136372f6974797065642f6d61737465722f696d672f6974797065646a732e676966" alt="How to add Animated typing to your React App"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So many of us seen websites which show typing text on there landing page. Most of the time we don’t really know which library they are using to perform that typing animation. In this article you will gonna learn how to add animated typing to your React App.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is ITyped ?
&lt;/h2&gt;

&lt;p&gt;ITyped is a simple library which is used to create animated typing for web apps. This library is super simple to use. The most interesting thing is that this library  &lt;strong&gt;doesn’t use any dependency&lt;/strong&gt; and its size is also  &lt;strong&gt;2KB&lt;/strong&gt;. It also not uses any JQuery internally.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation &amp;amp; Usage
&lt;/h2&gt;

&lt;p&gt;This article is for React app so we will gonna use React code for example. First of all let’s start with installing ityped. You can install it from yarn and npm.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install ityped
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add ityped
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Let’s import init function from ityped.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { init } from 'ityped'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This init function accept two parameter. First parameter is the element ref and second parameter is options of object type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const myElement = document.querySelector('#myElement')
      init(myElement, { showCursor: false, strings: ['Use with React.js!', 'Yeah!' ] })
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Full example will gonna look like this.&lt;br&gt;
&lt;/p&gt;

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

  export default class Hello extends Component {
    componentDidMount(){
      const myElement = document.querySelector('#myElement')
      init(myElement, { showCursor: false, strings: ['Use with React.js!', 'Yeah!' ] })
    }
    render(){
      return &amp;lt;div id="myElement"&amp;gt;&amp;lt;/div&amp;gt;
    }
  }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It uses various cool options for customization.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; init("#element", {

    /**
     * @param {Array} strings An array with the strings that will be animated 
     */
     strings: ['Put your strings here...', 'and Enjoy!']

    /**
     * @param {Number} typeSpeed Type speed in milliseconds
     */
     typeSpeed:  100,

    /**
     * @param {Number} backSpeed Type back speed in milliseconds
     */
     backSpeed:  50,

    /**
     * @param {Number} startDelay Time before typing starts
     */
     startDelay: 500,

    /**
     * @param {Number} backDelay Time before backspacing
     */
     backDelay:  500,

    /**
     * @param {Bollean} loop The animation loop
     */
     loop:       false,

    /**
     * @param {Bollean} showCursor Show the cursor element
     */
     showCursor: true,

    /**
     * @param {Bollean} placeholder Write the string in the placeholder content
     */
     placeholder: false,

    /**
     * @param {Bollean} disableBackTyping Disable back typing for the last string sentence 
     */
     disableBackTyping: false,

    /**
     * @property {String} cursorChar character for cursor
     */
     cursorChar: "|",


    // optional: The callback called (if `loop` is false) 
    // once the last string was typed
    /**
     * @property {Function} onFinished The callback called , if `loop` is false,
     * once the last string was typed
     */
    onFinished: function(){},
  }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://codesandbox.io/s/confident-tharp-icjyh?file=/src/App.js"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pzpI10jk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codesandbox.io/static/img/play-codesandbox.svg" alt="Edit icjyh"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to checkout the codesandbox demo.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blogreact.com/one-line-of-css/"&gt;How to write complex layouts in one line of Css&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>css</category>
      <category>html</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to write complex layouts in one line of Css</title>
      <dc:creator>Narender Saini</dc:creator>
      <pubDate>Sat, 08 Aug 2020 03:08:18 +0000</pubDate>
      <link>https://forem.com/narendersaini32/how-to-write-complex-layouts-in-one-line-of-css-1m1b</link>
      <guid>https://forem.com/narendersaini32/how-to-write-complex-layouts-in-one-line-of-css-1m1b</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I7HTTCk_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i0.wp.com/blogreact.com/wp-content/uploads/2020/08/melhore-o-seu-css-com-estes-5-principios.png%3Fw%3D750%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I7HTTCk_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i0.wp.com/blogreact.com/wp-content/uploads/2020/08/melhore-o-seu-css-com-estes-5-principios.png%3Fw%3D750%26ssl%3D1" alt="How to write complex layouts in one line of Css"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the modern era of frontend writing responsive styling became one of the essential skill for all developer. Some times to perform simple things developers write a lot of lines of code which become really difficult to read in future. In this article we will gonna learn how we can write complex layouts in one line of Css.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://1linelayouts.glitch.me/"&gt;Centering a child&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZYEC3kSc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i0.wp.com/blogreact.com/wp-content/uploads/2020/08/image-6.png%3Fw%3D750%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZYEC3kSc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i0.wp.com/blogreact.com/wp-content/uploads/2020/08/image-6.png%3Fw%3D750%26ssl%3D1" alt="Centering a child"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Centering content is one of the common things that we usually do in day to day life.&lt;/p&gt;

&lt;p&gt;Let’s assume we have two divs like this and we want to make child centered always.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="parent" &amp;gt;
  &amp;lt;div class="child" contenteditable&amp;gt;:)&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We can achieve this using the grid.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.parent {
    display: grid;
    place-items: center;
  }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;a href="https://1linelayouts.glitch.me/"&gt;Deconstructed Pancake&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JSgNaWIj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i1.wp.com/blogreact.com/wp-content/uploads/2020/08/image-7.png%3Fw%3D750%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JSgNaWIj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i1.wp.com/blogreact.com/wp-content/uploads/2020/08/image-7.png%3Fw%3D750%26ssl%3D1" alt="Deconstructed Pancake"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have a parent with 3 child and we want them to be responsive. They can take a static size or they can take full size according to available space.&lt;/p&gt;

&lt;p&gt;For this we will gonna use  &lt;code&gt;flex: &amp;lt;grow&amp;gt; &amp;lt;shrink&amp;gt; &amp;lt;baseWidth&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;div class="parent white"&amp;gt;
    &amp;lt;div class="box green"&amp;gt;1&amp;lt;/div&amp;gt;
    &amp;lt;div class="box green"&amp;gt;2&amp;lt;/div&amp;gt;
    &amp;lt;div class="box green"&amp;gt;3&amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For no stretching we can make grow 0;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flex: 0 1 150px;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iVmX9Zuc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i0.wp.com/blogreact.com/wp-content/uploads/2020/08/image-8.png%3Fw%3D750%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iVmX9Zuc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i0.wp.com/blogreact.com/wp-content/uploads/2020/08/image-8.png%3Fw%3D750%26ssl%3D1" alt="one line of Css"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For stretching we can make grow 1;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flex: 1 1 150px;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HnsQ7Gch--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i2.wp.com/blogreact.com/wp-content/uploads/2020/08/image-9.png%3Fw%3D750%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HnsQ7Gch--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i2.wp.com/blogreact.com/wp-content/uploads/2020/08/image-9.png%3Fw%3D750%26ssl%3D1" alt="one line of Css"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope you have learn how to write complex layouts in one line of Css.&lt;/p&gt;

&lt;p&gt;Checkout more complex layout  &lt;a href="https://1linelayouts.glitch.me/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blogreact.com/video-support-react/"&gt;How to add video support to React App&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>html</category>
      <category>css</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to use JSX in markdown documents</title>
      <dc:creator>Narender Saini</dc:creator>
      <pubDate>Sat, 01 Aug 2020 03:23:49 +0000</pubDate>
      <link>https://forem.com/narendersaini32/how-to-use-jsx-in-markdown-documents-2pn4</link>
      <guid>https://forem.com/narendersaini32/how-to-use-jsx-in-markdown-documents-2pn4</guid>
      <description>&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%2Fi0.wp.com%2Fblogreact.com%2Fwp-content%2Fuploads%2F2020%2F07%2FIntroductory-Guide-to-Markdown-for-Documentation-Writers-01.jpg%3Fw%3D750%26ssl%3D1" 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%2Fi0.wp.com%2Fblogreact.com%2Fwp-content%2Fuploads%2F2020%2F07%2FIntroductory-Guide-to-Markdown-for-Documentation-Writers-01.jpg%3Fw%3D750%26ssl%3D1" alt="How to use JSX in markdown documents"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have you ever wondered what if there is a way to write JSX in markdown documents. That will make writing code faster like never before. MDX is an authorable format that lets you seamlessly use JSX in your markdown documents. In this article we will gonna learn how to use JSX in markdown documents.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is MDX ?
&lt;/h2&gt;

&lt;p&gt;MDX is an authorable format that lets you seamlessly use JSX in your markdown documents. You can import components, like interactive charts or notifications, and export metadata. This makes writing long-form content with components a blast.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For example&lt;/strong&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 { Chart } from '../components/chart'

# Here’s a chart

The chart is rendered inside our MDX document.

&amp;lt;Chart /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;MDX is markdown for the component era. It lets you write JSX embedded inside markdown. That’s a great combination because it allows you to use markdown’s often terse syntax (such as # heading) for the little things and JSX for more advanced components.&lt;/p&gt;

&lt;h2&gt;
  
  
  Features of MDX
&lt;/h2&gt;

&lt;p&gt;It offers a lot of features but most important features are given below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Blending JSX and markdown makes it powerful.&lt;/li&gt;
&lt;li&gt;  You can use existing components inside your MDX.&lt;/li&gt;
&lt;li&gt;  We can import MDX files as components.&lt;/li&gt;
&lt;li&gt;  Decide which component is rendered for each markdown element (&lt;code&gt;{ h1: MyHeading }&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;  All compilation occurs at build time this makes its super fast.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;You can initialize your project using below command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init mdx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can read how to setup MDX with Webpack, Parcel, Create React App, Next.js and Gastby from  &lt;a href="https://mdxjs.com/getting-started" rel="noopener noreferrer"&gt;official&lt;/a&gt;  documents.&lt;/p&gt;

&lt;h2&gt;
  
  
  Comparison
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Hello, world!&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Hello, world!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both syntax will gonna show same output.&lt;/p&gt;

&lt;p&gt;Traditionally, Markdown is used to generate HTML. Many developers like writing markup in Markdown as it often looks more like what’s intended and it is typically terser.&lt;/p&gt;

&lt;p&gt;Instead of the following HTML:&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;blockquote&amp;gt;
  &amp;lt;p&amp;gt;A blockquote with &amp;lt;em&amp;gt;some&amp;lt;/em&amp;gt; emphasis.&amp;lt;/p&amp;gt;
&amp;lt;/blockquote&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can write.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; A blockquote with _some_ emphasis.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://mdxjs.com/#try-it" rel="noopener noreferrer"&gt;Demo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope you have learned about how we can use markdown with JSX using MDX.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blogreact.com/create-an-array-of-n-size/" rel="noopener noreferrer"&gt;Tip 2: Create an array of n size without lodash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>html</category>
      <category>css</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Fast a new UI library from Microsoft</title>
      <dc:creator>Narender Saini</dc:creator>
      <pubDate>Sat, 25 Jul 2020 03:06:46 +0000</pubDate>
      <link>https://forem.com/narendersaini32/fast-a-new-ui-library-from-microsoft-g79</link>
      <guid>https://forem.com/narendersaini32/fast-a-new-ui-library-from-microsoft-g79</guid>
      <description>&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%2Fi0.wp.com%2Fblogreact.com%2Fwp-content%2Fuploads%2F2020%2F07%2F68747470733a2f2f7374617469632e666173742e64657369676e2f6173736574732f666173745f62616e6e65725f6769746875625f3931342e706e67.png%3Fresize%3D750%252C402%26ssl%3D1" 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%2Fi0.wp.com%2Fblogreact.com%2Fwp-content%2Fuploads%2F2020%2F07%2F68747470733a2f2f7374617469632e666173742e64657369676e2f6173736574732f666173745f62616e6e65725f6769746875625f3931342e706e67.png%3Fresize%3D750%252C402%26ssl%3D1" alt="Fast a new UI library from Microsoft"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Choosing the correct UI library for a project is always most confusing thing for developers. We already have a lot of options like Material UI, Ant Design, Fluent Design, etc. Recently Microsoft has lanuched one more UI library called  &lt;strong&gt;Fast&lt;/strong&gt;. In this article we will gonna see how Microsoft Fast is different from other UI library.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Fast ?
&lt;/h2&gt;

&lt;p&gt;Microsoft’s Fast mainly focuses on the web components. It have a lot of pre-built web components. You can choose between two &lt;em&gt;adaptive&lt;/em&gt; design systems: Fluent Design and FAST Frame. It can be easily integrated with any frontend framework.&lt;/p&gt;

&lt;p&gt;FAST is a collection of JavaScript packages centered around web standards, designed to help you efficiently tackle some of the most common challenges in website and application design and development.&lt;/p&gt;

&lt;h4&gt;
  
  
  Installation
&lt;/h4&gt;

&lt;p&gt;Like any other package you can install it from yarn and npm. The &lt;code&gt;fast-components&lt;/code&gt; and &lt;code&gt;fast-components-msft&lt;/code&gt; libraries contain Web Components built on top of our standard component and design system foundation. &lt;code&gt;fast-components&lt;/code&gt; express the FAST design language while &lt;code&gt;fast-components-msft&lt;/code&gt; expresses Microsoft’s Fluent design language.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save @microsoft/fast-components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add @microsoft/fast-components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Usage
&lt;/h4&gt;

&lt;p&gt;To use Fast UI you need to wrap your app with a parent web component wrapper like this.&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;!-- ... --&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;fast-design-system-provider use-defaults&amp;gt;
    &amp;lt;/fast-design-system-provider&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;!-- ... --&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that you are ready to use any web component in your app.&lt;/p&gt;

&lt;p&gt;For example to use a button we can write.&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;fast-design-system-provider use-defaults&amp;gt;
    &amp;lt;fast-button&amp;gt;Submit&amp;lt;/fast-button&amp;gt;
&amp;lt;/fast-design-system-provider&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The out put will gonna look like this.&lt;/p&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%2Fi0.wp.com%2Fblogreact.com%2Fwp-content%2Fuploads%2F2020%2F07%2Fimage-3.png%3Fw%3D750%26ssl%3D1" 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%2Fi0.wp.com%2Fblogreact.com%2Fwp-content%2Fuploads%2F2020%2F07%2Fimage-3.png%3Fw%3D750%26ssl%3D1" alt="Fast a new UI library from Microsoft submit button"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Same we have a lot of web components like progress, text-fields, tabs, slider, switch, radio, menu, dialog, cards, checkbox etc etc. You can see full components list  &lt;a href="https://fast.design/docs/components/accordion" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blogreact.com/the-best-reactjs-ui-frameworks-library-in-2020/" rel="noopener noreferrer"&gt;The best Reactjs UI frameworks/library in 2020&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>design</category>
      <category>uiweekly</category>
    </item>
    <item>
      <title>How to write regex in natural language</title>
      <dc:creator>Narender Saini</dc:creator>
      <pubDate>Sat, 18 Jul 2020 03:13:35 +0000</pubDate>
      <link>https://forem.com/narendersaini32/how-to-write-regex-in-natural-language-158j</link>
      <guid>https://forem.com/narendersaini32/how-to-write-regex-in-natural-language-158j</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_O5jpp9F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i1.wp.com/blogreact.com/wp-content/uploads/2020/07/logo.png%3Fresize%3D750%252C161%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_O5jpp9F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i1.wp.com/blogreact.com/wp-content/uploads/2020/07/logo.png%3Fresize%3D750%252C161%26ssl%3D1" alt="How to write regex in natural language"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Everyone knows regex is most powerful feature of JavaScript but at the same time it can give hard time to even experienced developers. Reading your regex after few months sometime become too difficult. In today article we will gonna learn how we can write regex in natural language.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://github.com/francisrstokes/super-expressive"&gt;Super expressive&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Two days ago a new game changing library came into reality. This is a JavaScript library that allows you to build regular expressions in almost natural language – with no extra dependencies, and a lightweight code footprint (less than 3kb with minification + gzip!).&lt;/p&gt;

&lt;p&gt;On first place why we need a new library for regex. The answer is simple even the regex is so powerful but writing syntax of regex is too complicated. Most of the time we again need to read the docs of regex to create a new regex.&lt;/p&gt;

&lt;p&gt;This library solves the issue of complex syntax. It uses the normal natural language words to create a regex.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Like any other npm package you can install this library using npm or yarn.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i super-expressive --save
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Usage&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To use this library first of all you need to import this library.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const SuperExpressive = require('super-expressive');
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Find Mutiple hello in a string.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SuperExpressive()
  .allowMultipleMatches
  .string('hello')
  .toRegex();
// -&amp;gt;
/hello/g
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Find CaseInsenstive Hello.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SuperExpressive()
  .caseInsensitive
  .string('HELLO')
  .toRegex();
// -&amp;gt;
/HELLO/i
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Captures the value of a 16-bit hexadecmal number like &lt;code&gt;0xC0D3&lt;/code&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const SuperExpressive = require('super-expressive');

const myRegex = SuperExpressive()
  .startOfInput
  .optional.string('0x')
  .capture
    .exactly(4).anyOf
      .range('A', 'F')
      .range('a', 'f')
      .range('0', '9')
    .end()
  .end()
  .endOfInput
  .toRegex();

// Produces the following regular expression:
/^(?:0x)?([A-Fa-f0-9]{4})$/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Similarly you can create any regex in natural language using this library. I hope you have learned how to write regex in natural language.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/francisrstokes/super-expressive"&gt;Full docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blogreact.com/intersection-observer-api/"&gt;How to check an element is in viewport using Intersection Observer API&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>html</category>
      <category>css</category>
    </item>
    <item>
      <title>How to check an element is in viewport</title>
      <dc:creator>Narender Saini</dc:creator>
      <pubDate>Sat, 11 Jul 2020 03:12:46 +0000</pubDate>
      <link>https://forem.com/narendersaini32/how-to-check-an-element-is-in-viewport-4bcl</link>
      <guid>https://forem.com/narendersaini32/how-to-check-an-element-is-in-viewport-4bcl</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m_CBc7FD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i2.wp.com/blogreact.com/wp-content/uploads/2020/07/vw.png%3Fresize%3D750%252C465%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m_CBc7FD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i2.wp.com/blogreact.com/wp-content/uploads/2020/07/vw.png%3Fresize%3D750%252C465%26ssl%3D1" alt="How to check an element is in viewport"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, maybe you already have seen the case where developer need to check an element (div) is currently visible to user or not. For solving this problem there is a lot of npm packages available but what if we don’t want to use them. In this article we will gonna learn how to check an element is in viewport.&lt;/p&gt;

&lt;p&gt;If you want to use a npm package then  &lt;a href="https://blogreact.com/how-to-use-react-visibility-sensor/"&gt;this&lt;/a&gt;  will be a good one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;Let’s assume we have several elements on our page and we want to perform an operation only if a particular element is visible. To handle this problem we will gonna use our custom util function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;We will gonna create a custom util function which will gonna receive a element and then it will gonna check is it currently visible or not.&lt;/p&gt;

&lt;p&gt;Let’s write a util function isVisible and it will gonna receive only one argument i.e element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const isVisible = (el) =&amp;gt; {

};

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



&lt;p&gt;Then we will gonna get the position of that element using  &lt;strong&gt;getBoundingClientRect&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const rect = el.getBoundingClientRect();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we will gonna find window height and width.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const vWidth = window.innerWidth || document.documentElement.clientWidth;
  const vHeight = window.innerHeight || document.documentElement.clientHeight;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We will gonna write a one more function which basically gonna receive x and y point and gonna return element using  &lt;strong&gt;&lt;a href="https://webplatform.github.io/docs/dom/Document/elementFromPoint/"&gt;elementFromPoint&lt;/a&gt;&lt;/strong&gt;  function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const efp = function (x, y) { return document.elementFromPoint(x, y); };
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then we will gonna check our element is inside or not of window.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  // Return false if it's not in the viewport
  if (rect.right &amp;lt; 0 || rect.bottom &amp;lt; 0
            || rect.left &amp;gt; vWidth || rect.top &amp;gt; vHeight) { return false; }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Check is any corner is visible.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Return true if any of its four corners are visible
  return (
    el.contains(efp(rect.left, rect.top))
      || el.contains(efp(rect.right, rect.top))
      || el.contains(efp(rect.right, rect.bottom))
      || el.contains(efp(rect.left, rect.bottom))
  );
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Full function will gonna look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const isVisible = (el) =&amp;gt; {
  const rect = el.getBoundingClientRect();
  const vWidth = window.innerWidth || document.documentElement.clientWidth;
  const vHeight = window.innerHeight || document.documentElement.clientHeight;
  const efp = function (x, y) { return document.elementFromPoint(x, y); };

  // Return false if it's not in the viewport
  if (rect.right &amp;lt; 0 || rect.bottom &amp;lt; 0
            || rect.left &amp;gt; vWidth || rect.top &amp;gt; vHeight) { return false; }

  // Return true if any of its four corners are visible
  return (
    el.contains(efp(rect.left, rect.top))
      || el.contains(efp(rect.right, rect.top))
      || el.contains(efp(rect.right, rect.bottom))
      || el.contains(efp(rect.left, rect.bottom))
  );
};

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



&lt;p&gt;&lt;strong&gt;Usage&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { isVisible } from '../utils';

.....
const ele = document.getElementById(id);
return isVisible(ele);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I hope you have learned how to check an element is in viewport.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
