<?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>DEV Community: Nitin Hepat</title>
    <description>The latest articles on DEV Community by Nitin Hepat (@hepatnitin).</description>
    <link>https://dev.to/hepatnitin</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%2F212165%2F9d0e95e1-4900-4311-b33c-436310bb5a03.jpg</url>
      <title>DEV Community: Nitin Hepat</title>
      <link>https://dev.to/hepatnitin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hepatnitin"/>
    <language>en</language>
    <item>
      <title>How To Combine PDF Files on a Mac: A Simple Guide for Busy Developers</title>
      <dc:creator>Nitin Hepat</dc:creator>
      <pubDate>Sun, 06 Oct 2024 19:04:25 +0000</pubDate>
      <link>https://dev.to/hepatnitin/how-to-combine-pdf-files-on-a-mac-a-simple-guide-for-busy-developers-4djo</link>
      <guid>https://dev.to/hepatnitin/how-to-combine-pdf-files-on-a-mac-a-simple-guide-for-busy-developers-4djo</guid>
      <description>&lt;h1&gt;
  
  
  How To Combine PDF Files on a Mac: A Simple Guide for Busy Developers
&lt;/h1&gt;

&lt;p&gt;Ever found yourself juggling multiple PDF files? Whether it's project documentation, client contracts, or technical manuals, managing several PDFs can quickly become overwhelming. The solution? Combine them into one single file. It's easier to manage, share, and looks way more professional.&lt;/p&gt;

&lt;p&gt;In this guide, I’m going to show you how to combine PDF files on a Mac using two different methods: &lt;a href="https://www.pdfboosters.ai" rel="noopener noreferrer"&gt;PDFBoosters.ai&lt;/a&gt;, a quick and secure online tool, and Preview, a built-in Mac app that’s surprisingly powerful. Let’s dive in.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Should You Combine PDF Files?
&lt;/h2&gt;

&lt;p&gt;You’ve probably already felt the pain of managing several PDF files for a single project or client. Combining them can save you time, make your files more organized, and create a professional presentation. Here’s why merging PDFs is a no-brainer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Better organization&lt;/strong&gt;: All relevant documents in one file—no more hunting through folders to find the right one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Easy sharing&lt;/strong&gt;: Send just one file instead of a bunch of attachments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Polished appearance&lt;/strong&gt;: It looks way more professional to have everything neatly packaged in a single PDF.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that you know why it’s worth doing, let's explore two ways to merge PDFs on your Mac.&lt;/p&gt;




&lt;h2&gt;
  
  
  Method 1: How to Combine PDF Files on a Mac Using PDFBoosters.ai
&lt;/h2&gt;

&lt;p&gt;If you’re like me, you appreciate a no-fuss, quick solution. That’s where &lt;a href="https://www.pdfboosters.ai" rel="noopener noreferrer"&gt;PDFBoosters.ai&lt;/a&gt; comes in. It’s an online tool that lets you merge PDF files effortlessly—without the need for installing any software.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step-by-Step Guide:
&lt;/h3&gt;

&lt;h3&gt;
  
  
  1. Go to PDFBoosters.ai’s Merge Tool
&lt;/h3&gt;

&lt;p&gt;First, head over to &lt;a href="https://www.pdfboosters.ai" rel="noopener noreferrer"&gt;PDFBoosters.ai&lt;/a&gt; and select the &lt;strong&gt;Merge PDF&lt;/strong&gt; tool from the homepage. No need to mess around with downloads or complicated setups—everything runs in your browser.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Upload Your PDFs
&lt;/h3&gt;

&lt;p&gt;Once you're on the Merge PDF page, you can upload your files by either dragging them into the tool or clicking the &lt;strong&gt;Choose Files&lt;/strong&gt; button. You can select multiple PDFs at once, or add them one by one if needed.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Add More PDFs
&lt;/h3&gt;

&lt;p&gt;Forgot to upload a file? No worries! PDFBoosters allows you to add more files even after you’ve already started. Just hit the &lt;strong&gt;Add Files&lt;/strong&gt; button and upload the additional documents.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Rearrange the Pages
&lt;/h3&gt;

&lt;p&gt;Now that all your files are uploaded, you can reorder them by simply dragging and dropping. This is useful when you want the pages to be arranged in a specific order.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Click “Save &amp;amp; Download”
&lt;/h3&gt;

&lt;p&gt;Once you’ve got everything in the right order, click &lt;strong&gt;Finish&lt;/strong&gt;. PDFBoosters.ai will merge your PDFs together in a matter of seconds—even for larger files.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Download Your Combined PDF
&lt;/h3&gt;

&lt;p&gt;After the process is complete, you’ll be able to download the newly merged PDF file. It’s as simple as that!&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Use PDFBoosters.ai?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No installations&lt;/strong&gt;: You don’t have to install anything, making it perfect for quick merges on the go.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fast and secure&lt;/strong&gt;: Your files are processed quickly and securely, without long-term storage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Easy to use&lt;/strong&gt;: With its simple drag-and-drop interface, merging PDFs has never been easier.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whether you’re at home, in a café, or on a client’s site, PDFBoosters.ai makes merging PDFs a breeze, especially when you need things done fast.&lt;/p&gt;




&lt;h2&gt;
  
  
  Method 2: How to Combine PDFs Using Preview on Your Mac
&lt;/h2&gt;

&lt;p&gt;If you prefer not to use online tools, or maybe you just want to use what’s already available on your Mac, Preview is another fantastic option. It’s a built-in app that can do way more than just view PDFs.&lt;/p&gt;

&lt;p&gt;Here’s how you can merge PDFs using Preview:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Open the PDFs in Preview
&lt;/h3&gt;

&lt;p&gt;Start by opening the first PDF you want to combine. Just right-click on the PDF file, select &lt;strong&gt;Open With&lt;/strong&gt;, and choose &lt;strong&gt;Preview&lt;/strong&gt;. Then, do the same for the second PDF, opening it in a separate Preview window.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Enable Thumbnail View
&lt;/h3&gt;

&lt;p&gt;To make things easier, go to the &lt;strong&gt;View&lt;/strong&gt; menu and select &lt;strong&gt;Thumbnails&lt;/strong&gt;. This will show a sidebar with all the pages of your PDF.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Drag and Drop Pages
&lt;/h3&gt;

&lt;p&gt;Now, open the second PDF and do the same—enable the thumbnail view. From here, simply drag the pages from the second PDF’s thumbnail sidebar and drop them into the first PDF’s thumbnail sidebar. You can reorder the pages if needed.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Save the Combined PDF
&lt;/h3&gt;

&lt;p&gt;Once you’ve got everything in the right order, go to &lt;strong&gt;File &amp;gt; Export as PDF&lt;/strong&gt; and save your newly combined document. Voila! You’ve merged your PDFs right on your Mac without any extra software.&lt;/p&gt;




&lt;h2&gt;
  
  
  Bonus: Automating PDF Merging with JavaScript
&lt;/h2&gt;

&lt;p&gt;For developers who want to automate the process or build it into their own apps, you can use JavaScript to merge PDFs programmatically. A popular library for this is &lt;code&gt;pdf-lib&lt;/code&gt;, which makes it super easy to combine multiple PDFs with just a few lines of code.&lt;/p&gt;

&lt;p&gt;Here’s a quick example:&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;PDFDocument&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;pdf-lib&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;fs&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;fs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;mergePDFs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;filePaths&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="nx"&gt;mergedPdf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;PDFDocument&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;for &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;filePath&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;filePaths&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="nx"&gt;pdfBytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;filePath&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;pdf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;PDFDocument&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pdfBytes&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;copiedPages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;mergedPdf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;copyPages&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pdf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pdf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getPageIndices&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
        &lt;span class="nx"&gt;copiedPages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;page&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;mergedPdf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&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="nx"&gt;pdfBytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;mergedPdf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;merged.pdf&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pdfBytes&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;mergePDFs&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;file1.pdf&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="s1"&gt;file2.pdf&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;This post first published on &lt;a href="https://www.pdfboosters.ai/blog/how-to-combine-pdf-files-on-a-mac" rel="noopener noreferrer"&gt;PDFBoosters.ai&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>pdf</category>
    </item>
    <item>
      <title>Implementing virtual scroll using react</title>
      <dc:creator>Nitin Hepat</dc:creator>
      <pubDate>Sat, 27 Jun 2020 14:09:59 +0000</pubDate>
      <link>https://dev.to/hepatnitin/implementing-virtual-scroll-using-react-2gaj</link>
      <guid>https://dev.to/hepatnitin/implementing-virtual-scroll-using-react-2gaj</guid>
      <description>&lt;p&gt;This post first published on&lt;br&gt;
&lt;a class="wp-block-button__link has-text-color has-very-light-gray-color" href="https://www.techboxweb.com/implementing-virtual-scroll-using-react/"&gt;TechBoxWeb&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the era of web application, You might need to deal with a huge amount of data and that data need to be rendered on DOM.&lt;/p&gt;

&lt;p&gt;In web application, DOM is a very sensitive matter you need to deal with it very carefully because else your application will be laggy or slow.&lt;/p&gt;

&lt;p&gt;For eg. you have data of 100,000 rows. Its huge amount of data and rendering total data, It's going to be a very expensive operation&lt;/p&gt;

&lt;p&gt;So, here virtual scroll concept comes for rescue. &lt;/p&gt;

&lt;p&gt;Virtual scroll means we will just renders the data which is visible in viewport and other will render as user scroll and comes into the viewport and data which is not in viewport will get remove from DOM.&lt;/p&gt;

&lt;p&gt;without wasting time let's implement virtual scroll using react&lt;/p&gt;

&lt;p&gt;Find Github and Demo here&lt;/p&gt;

&lt;p&gt;&lt;a class="wp-block-button__link has-text-color has-very-light-gray-color" href="https://github.com/nitinhepat/virtual-scroll-with-react" rel="noreferrer noopener"&gt;Github Repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a class="wp-block-button__link has-text-color has-very-light-gray-color" href="https://virtualscroll-7b282.web.app/" rel="noreferrer noopener"&gt;Demo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Contents:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What we will going to do?&lt;/li&gt;
&lt;li&gt;Setting up a react project&lt;/li&gt;
&lt;li&gt;creating virtual scroll component&lt;/li&gt;
&lt;li&gt;performance optimization&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;What we will going to do&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7h7TFcA9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.techboxweb.com/wp-content/uploads/2020/06/Total-elements-1024x576.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7h7TFcA9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.techboxweb.com/wp-content/uploads/2020/06/Total-elements-1024x576.png" alt="Virtual scroll using react" class="wp-image-752"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see in the above diagram, only rows into the viewport section is visible to the end-user, so we will going to rendered that elements into the DOM with some buffered rows as you can see into the diagram, Because If user scroll we can show already rendered elements until we calculate the visible rows to be shown&lt;/p&gt;

&lt;p&gt;we will be having scroll event onto the viewport, as user scroll we will run scroll function and we will calculate next visible rows to be shown&lt;/p&gt;

&lt;h2&gt;Setting up a react project&lt;/h2&gt;

&lt;p&gt;you can create initial setup for react using below command&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;npx create-react-app reacct-virtual-scroll&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;create-react-app is a react utility which helps you to setup react project, want to know more in detail then please go through this &lt;a href="https://reactjs.org/docs/create-a-new-react-app.html" rel="noreferrer noopener"&gt;post&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Creating a virtual scroll component&lt;/h2&gt;

&lt;p&gt;virtual scroll component is responsible for showing only data which is visible into the viewport and and adding and removing element from the dom when we scroll&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;import React, { useRef, useState, useEffect } from 'react';

const VirtualScroll = (props) =&amp;gt; {
  const totalHeight = +props.rowHeight * +props.totalElements + 'px';
  const [scrollTop, setScrollTop] = useState(0);

  useEffect(() =&amp;gt; {
    scrollEle.current.addEventListener("scroll", scroll);

    return () =&amp;gt; {
    }
  })
  const scrollEle = useRef();
  let startNodeele = Math.max(0, Math.floor(scrollTop / +props.rowHeight));

  let visibleItems = props.items.slice(startNodeele, startNodeele + props.visibleItemsLength);
  let transformValue = `translateY(${startNodeele * +props.rowHeight}px)`;
  console.log('rendering', Math.random());

  const scroll = () =&amp;gt; {
    setScrollTop(scrollEle.current.scrollTop)

  }
  const scrollContainerStyle = {
    height: props.height,
    overflowY: "scroll"
  }
  const totalHeightStyle = { height: totalHeight };
  const mainContainerStyle = { transform: transformValue }
  return (
    &amp;lt;div className="scrollContainer" ref={scrollEle} style={scrollContainerStyle}&amp;gt;
      &amp;lt;div style={totalHeightStyle}&amp;gt;
        &amp;lt;div className="main-container" style={mainContainerStyle}&amp;gt;
          {visibleItems}
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}


export default React.memo(VirtualScroll);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;let's understand the code&lt;/p&gt;

&lt;p&gt;You guys need to understand one thing here, we have did some math to calculate which elements can be visible in viewport and which element can be removed.&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt; const scrollContainerStyle = {
    height: props.height,
    overflowY: "scroll"
  }
  const totalHeightStyle = { height: totalHeight };
  const mainContainerStyle = { transform: transformValue }
  return (
    &amp;lt;div className="scrollContainer" ref={scrollEle} style={scrollContainerStyle}&amp;gt;
      &amp;lt;div style={totalHeightStyle}&amp;gt;
        &amp;lt;div className="main-container" style={mainContainerStyle}&amp;gt;
          {visibleItems}
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  )&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt; As you can see in above code, we have three parent div then inside that we are rendering items&lt;/p&gt;

&lt;p&gt;First parent div, is where we going to add scroll event listner and overflowY with scroll &lt;/p&gt;

&lt;p&gt;Second div, Its height is (individual element height * total elements). For eg, If we have 100,000 rows and each row height is 70px then  total element height will be (100000 * 70)px&lt;/p&gt;

&lt;p&gt;The third div,  we are going to show a limited number of row for eg. 50 rows at a time, then obviously all elements will position to the  start of the  div and scroll will be at current scroll position, technically we achieve to show only a few rows but we need to position rows correctly so whenever we scroll then it would be visible to the end-user, so that's why we added transform: translateY() property, it will position the third div vertically and the value for this is starting position of the visible row&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;let startNodeele = Math.max(0,Math.floor(scrollTop / +props.rowHeight));&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In the above code, we did some math to calculate the startNodeele , scrollTop is nothing but current scroll position and we are dividing it with individual rowHeight&lt;/p&gt;

&lt;p&gt;If you are react geek, I think above code is well explanatory to understand&lt;/p&gt;

&lt;h2&gt;Using Virtual scroll Component&lt;/h2&gt;

&lt;p&gt;App.js&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;import React, { useState } from 'react';
import './App.css';
import VirtualScroll from './components/virtualScroll/VirtualScroll';

const totalEle = 100000;
const gridHeightStyle = {
height:'70px'
}
const grids = new Array(totalEle).fill(null).map((data, index) =&amp;gt; {
  return (&amp;lt;div style={gridHeightStyle} key={index} className="grid"&amp;gt;
    &amp;lt;h3&amp;gt;Lorem Ipsum is simply dummy text of the printing {index}&amp;lt;/h3&amp;gt;
  &amp;lt;/div&amp;gt;)
})


function App() {
 
  return (
    &amp;lt;VirtualScroll
    height="300px"
    totalElements = {totalEle}
    rowHeight={70}
    items={grids}
    visibleItemsLength={50}

    &amp;gt;
    &amp;lt;/VirtualScroll&amp;gt;
  
  );
}

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

&lt;p&gt;As you can see, In the above code we have created an array of 100000 elements, and passed that to VirtualScroll component and also we need some more input like to height of the scroll div, individual row height, visibleItemlength, for making this component more reusable&lt;/p&gt;

&lt;h2&gt;Performance optimization&lt;/h2&gt;

&lt;p&gt;There are some specific area we need to take care of&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;we should have minimal operation in scroll function&lt;/li&gt;
&lt;li&gt;You can also add throttling into the scroll function like when user stops scrolling then only calculate visible items&lt;/li&gt;
&lt;li&gt;React component rendering should be minimal, as you can see in the example we are re-rendering component only when scrollTop is changing&lt;/li&gt;
&lt;/ul&gt;



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

&lt;p&gt;Here we developed virtual scrolling using react with some mathematical calculation. Might be you have some other approach to do virtual scroll, But I suggest implement some functionality by yourself instead of using the npm package. It helps you to grow and understand the concept&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Dark/light website theming with CSS variables</title>
      <dc:creator>Nitin Hepat</dc:creator>
      <pubDate>Sat, 06 Jun 2020 06:15:02 +0000</pubDate>
      <link>https://dev.to/hepatnitin/dark-light-website-theming-with-css-variables-48ii</link>
      <guid>https://dev.to/hepatnitin/dark-light-website-theming-with-css-variables-48ii</guid>
      <description>&lt;p&gt;Nowadays, while developing a website or web application, You need to take care of the theming of the website. You need to think about how easily theming can be manageable with minimum CSS.&lt;/p&gt;

&lt;p&gt;So, for your help, we have &lt;a rel="noreferrer noopener" href="https://www.techboxweb.com/thoughts-on-css-variables/"&gt;CSS variables&lt;/a&gt;. CSS variables are custom properties, which can be defined once and reused a number of time&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;body {
--main-color: black;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;in above example we defined --main-color as a custom variable which can be used anywhere&lt;/p&gt;

&lt;p&gt;like below&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;.container {
background-color: var(--main-color)
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: CSS variables should be defined at global level to use inside child elements and for more info please go through &lt;a rel="noreferrer noopener" href="https://www.techboxweb.com/thoughts-on-css-variables/"&gt;this post&lt;/a&gt;&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%2Ftechboxweb.com%2Fwp-content%2Fuploads%2F2020%2F05%2Fcss-variables.gif" 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%2Ftechboxweb.com%2Fwp-content%2Fuploads%2F2020%2F05%2Fcss-variables.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;we will be building day and night mode theme switcher application using CSS variables and vanilla javascript&lt;/p&gt;

&lt;p&gt;If you want to access code you can check out github repository and also see demo live&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/nitinhepat/theme-switcher" rel="noreferrer noopener"&gt;&lt;strong&gt;&lt;span&gt;Github repo&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://js-ae6qcz.stackblitz.io/" rel="noreferrer noopener"&gt;&lt;strong&gt;&lt;span&gt;Demo&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;lt;!-- /wp:button --&amp;gt;&lt;/p&gt;

&lt;p&gt;Let's get started&lt;/p&gt;

&lt;h2&gt;Creating a theme.css file&lt;/h2&gt;

&lt;p&gt;Always remember theming css should not mixed with other css, so keep it seperately&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
body {
    margin: 0;
    padding: 0;
}

.dark {
    --bgColor: #161625;
    --color: white;
    --headerBg: #161625;
}

.light {
    --bgColor: white;
    --color: black;
    --headerBg: #E8E8E8;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;we have created a simple configuration for dark theme and light theme where we defined background color, font color, and header background.&lt;/p&gt;

&lt;p&gt;we have created a basic application where we just changing the color scheme for header, body background, and font color. For advanced you can manage the number of things.&lt;/p&gt;

&lt;h2&gt;Creating A User Interface&lt;/h2&gt;

&lt;p&gt;HTML file&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;link rel="stylesheet" href="./theme.css" /&amp;gt;
    &amp;lt;link rel="stylesheet" href="./style.css" /&amp;gt;
    &amp;lt;link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous"&amp;gt;
  
&amp;lt;/head&amp;gt;

&amp;lt;body id="body-container" class="light"&amp;gt;
    &amp;lt;header&amp;gt;
        &amp;lt;nav class="header-container"&amp;gt;
            &amp;lt;div class="logo-section"&amp;gt;
                &amp;lt;span class="logo"&amp;gt;Logo&amp;lt;/span&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;nav class="menu-section"&amp;gt;
                &amp;lt;ul class="header"&amp;gt;
                   
                    &amp;lt;li&amp;gt;
                        &amp;lt;i class="fa fa-home" aria-hidden="true"&amp;gt;&amp;lt;/i&amp;gt;
                        home
                    &amp;lt;/li&amp;gt;
                    &amp;lt;li&amp;gt;
                        &amp;lt;i class="fa fa-user" aria-hidden="true"&amp;gt;&amp;lt;/i&amp;gt;
                        about us
                    &amp;lt;/li&amp;gt;
                    &amp;lt;li&amp;gt;
                        &amp;lt;i class="fa fa-id-card"&amp;gt;&amp;lt;/i&amp;gt;
                        contact us
                    &amp;lt;/li&amp;gt;
                    &amp;lt;li&amp;gt;
                        &amp;lt;i id="theme-action" class="fa fa-moon-o" aria-hidden="true"&amp;gt;&amp;lt;/i&amp;gt;&amp;lt;/li&amp;gt;
                &amp;lt;/ul&amp;gt;
            &amp;lt;/nav&amp;gt;
        &amp;lt;/nav&amp;gt;
    &amp;lt;/header&amp;gt;
    &amp;lt;main class="main-container"&amp;gt;
        &amp;lt;div class="grid"&amp;gt;
            &amp;lt;div class="img-section"&amp;gt;
                &amp;lt;img src="assets/1.jpg" /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;h3&amp;gt;Lorem Ipsum is simply dummy text of the printing &amp;lt;/h3&amp;gt;
           
             
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="grid"&amp;gt;
            &amp;lt;div class="img-section"&amp;gt;
                &amp;lt;img src="assets/2.jpg" /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;h3&amp;gt;Lorem Ipsum is simply dummy text of the printing &amp;lt;/h3&amp;gt;
           
             
        &amp;lt;/div&amp;gt;&amp;lt;div class="grid"&amp;gt;
            &amp;lt;div class="img-section"&amp;gt;
                &amp;lt;img src="assets/3.jpg" /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;h3&amp;gt;Lorem Ipsum is simply dummy text of the printing &amp;lt;/h3&amp;gt;
           
             
        &amp;lt;/div&amp;gt;&amp;lt;div class="grid"&amp;gt;
            &amp;lt;div class="img-section"&amp;gt;
                &amp;lt;img src="assets/4.jpg" /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;h3&amp;gt;Lorem Ipsum is simply dummy text of the printing &amp;lt;/h3&amp;gt;
           
             
        &amp;lt;/div&amp;gt;&amp;lt;div class="grid"&amp;gt;
            &amp;lt;div class="img-section"&amp;gt;
                &amp;lt;img src="assets/5.jpg" /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;h3&amp;gt;Lorem Ipsum is simply dummy text of the printing &amp;lt;/h3&amp;gt;
           
             
        &amp;lt;/div&amp;gt;&amp;lt;div class="grid"&amp;gt;
            &amp;lt;div class="img-section"&amp;gt;
                &amp;lt;img src="assets/5.jpg" /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;h3&amp;gt;Lorem Ipsum is simply dummy text of the printing &amp;lt;/h3&amp;gt;
           
             
        &amp;lt;/div&amp;gt;&amp;lt;div class="grid"&amp;gt;
            &amp;lt;div class="img-section"&amp;gt;
                &amp;lt;img src="assets/3.jpg" /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;h3&amp;gt;Lorem Ipsum is simply dummy text of the printing &amp;lt;/h3&amp;gt;
           
             
        &amp;lt;/div&amp;gt;&amp;lt;div class="grid"&amp;gt;
            &amp;lt;div class="img-section"&amp;gt;
                &amp;lt;img src="assets/4.jpg" /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;h3&amp;gt;Lorem Ipsum is simply dummy text of the printing &amp;lt;/h3&amp;gt;
           
             
        &amp;lt;/div&amp;gt;
    &amp;lt;/main&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;script src="app.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;we have created a simple layout where we have header menus and some grids in the main body. In the header we have a theme toggle button which will be used for switching between light and dark theme.&lt;/p&gt;

&lt;p&gt;we have enabled light theme by default as you can see in HTML above  we have added light class in body &lt;/p&gt;



&lt;h2&gt;Designing a web page&lt;/h2&gt;

&lt;p&gt;let's write css for designing a webpage&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
.header li {
    display: inline-block;
    list-style: none;
    padding: 0 10px;
    font-weight: bold;
    font-size: larger;
    cursor: pointer;
    
}
body {
    background-color: var(--bgColor);
    transition: ease-in 1s;
}
.header-container {
    display: flex;
    background-color: var(--headerBg);
    color: var(--color);
    height: 56px;
    transition: ease-in 1s;
}
.logo-section .logo {
    font-weight: bold;
    font-size: x-large;
    margin-left: 10px;
}
.header-contaieer .menu-section {
    display: flex;
    justify-content: flex-end;
    align-items: center;
}
.header-container .logo-section, .header-container .menu-section {
    display: flex;
    align-items: center;
    flex-basis: 50%;
}
.main-container {
    display: flex;
    width:80%;
    margin: 0 auto;
    justify-content: space-between;
    flex-wrap: wrap;
}
.main-container .grid{
    flex-basis: 300px;
    height: 300px;
    box-sizing: border-box;
    border: 1px solid #888;
    border-radius: 5px;
    padding: 5px;
    margin: 10px;
    color: var(--color);
}

.grid .img-section img {
    width: 100%;
    height: 200px;
}



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

&lt;p&gt;As you can see we have used &lt;a rel="noreferrer noopener" href="https://techboxweb.com/detail-beginner-guide-for-css-flexbox-with-examples/"&gt;flexbox layout &lt;/a&gt;for designing a webpage and uses a CSS variable to the point so while switching between themes we don't need to care about the CSS part.&lt;/p&gt;

&lt;p&gt;let's write Business logic for handling switching functionality between themes&lt;/p&gt;

&lt;h2&gt;Business logic&lt;/h2&gt;



&lt;pre&gt;&lt;code&gt;const bodyContainer = document.body;
const themeAction = document.getElementById('theme-action');

const currentTheme = localStorage.getItem('theme');

if(currentTheme &amp;amp;&amp;amp; currentTheme == 'dark'){
        bodyContainer.classList.replace('light','dark');
        localStorage.setItem('theme','dark');
        themeAction.classList.replace('fa-moon-o','fa-sun-o');

}

themeAction.onclick = () =&amp;gt;{
    if(bodyContainer.classList.contains('light')){
        bodyContainer.classList.replace('light','dark');
        localStorage.setItem('theme','dark');
        themeAction.classList.replace('fa-moon-o','fa-sun-o');

    } else if(bodyContainer.classList.contains('dark')){
        bodyContainer.classList.replace('dark','light');
        localStorage.setItem('theme','light');
        themeAction.classList.replace('fa-sun-o','fa-moon-o');
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As you can see, we have used local storage to maintain user preference because whenever the user comes back he should be on the same theme.&lt;/p&gt;

&lt;p&gt;we have sun/moon icon at the top which is used for toggling between light and dark theme and we added click event on these icons and toggled the theme. In Click event we are setting user preference into the theme and changing to the light or dark theme as per user preferences.&lt;/p&gt;

&lt;p&gt;And whenever the user comes the first time, we check is the user already set his preference or not then taken action appropriately. If the user preferred theme is light then no need to do any operation initial level because by default theme is light. &lt;/p&gt;

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

&lt;p&gt;CSS variables are very useful when want to change things dynamically.Which can not be possible with preprocessors like sass, less&lt;/p&gt;

</description>
      <category>css</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Top 5 ways to display two div side by side using CSS</title>
      <dc:creator>Nitin Hepat</dc:creator>
      <pubDate>Wed, 29 Apr 2020 11:03:49 +0000</pubDate>
      <link>https://dev.to/hepatnitin/top-5-ways-to-display-two-div-side-by-side-using-css-5gp</link>
      <guid>https://dev.to/hepatnitin/top-5-ways-to-display-two-div-side-by-side-using-css-5gp</guid>
      <description>&lt;p&gt;In HTML, there are two types of element inline and block element.Inline elements can place element next to each other but they don't support height and width property by default and block elements support width and height property by default but we can't place block elements like two div side by side&lt;/p&gt;

&lt;p&gt; So, here we can see How we can make it work&lt;/p&gt;

&lt;p&gt;we will see how div can place next to each other in 5 different ways&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;display: inline-block (tradional way)&lt;/li&gt;
&lt;li&gt;css flexbox method&lt;/li&gt;
&lt;li&gt;css grid method&lt;/li&gt;
&lt;li&gt;display: table method&lt;/li&gt;
&lt;li&gt;float property&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Using display: inline-block&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;display: inline-block&lt;/strong&gt; property helps to place block element beside each other &lt;/p&gt;

&lt;p&gt;But, we need to add extra width property to the block element because block element by default takes 100% width&lt;/p&gt;

&lt;p&gt;eg.&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;div class="element"&amp;gt;
  &amp;lt;/div&amp;gt;
  &amp;lt;div class="element"&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;// css &lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;.element {
  display: inline-block;
  width: 100px;
  height: 100px;
  background: #ce8888;
  
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and output will be&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bM3kx4i7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/image-4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bM3kx4i7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/image-4.png" alt="" class="wp-image-457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;please check example &lt;a href="https://codepen.io/nitinhepat/pen/yLYMroe" rel="noreferrer noopener"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Using flexbox&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://techboxweb.com/detail-beginner-guide-for-css-flexbox-with-examples/"&gt;&lt;strong&gt;flexbox &lt;/strong&gt;&lt;/a&gt;is a modern way of designing the layout of webpage and flexbox is not a single property its complete module it has a number of feature&lt;/p&gt;

&lt;p&gt;let's see how we can align divs next to each other using flexbox&lt;/p&gt;

&lt;p&gt;//html file&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;link rel="stylesheet" href="index.css" /&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
  &amp;lt;div class="container"&amp;gt;
    &amp;lt;div class="item"&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="item"&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;

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

&lt;p&gt;// css file&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;.container {
  display: flex;
}

.item {
  background: #ce8888;
  flex-basis: 100px;
  height: 100px;
  margin: 5px;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;//output &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sFoXhC-7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/image-5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sFoXhC-7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/image-5.png" alt="" class="wp-image-458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;display: flex&lt;/strong&gt; property given to container which makes child element in flex context and aligns divs next to each other&lt;/p&gt;

&lt;p&gt;In the above example, You can see we have used flex-basis property which is used to give min-width for the item. To understand flexbox in detail please &lt;a rel="noreferrer noopener" href="https://techboxweb.com/detail-beginner-guide-for-css-flexbox-with-examples/"&gt;check this out&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;please find demo &lt;a rel="noreferrer noopener" href="https://codepen.io/nitinhepat/pen/qBOrwwK"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Using css grid&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://css-tricks.com/snippets/css/complete-guide-grid/" rel="noreferrer noopener"&gt;&lt;strong&gt;CSS grid&lt;/strong&gt;&lt;/a&gt; is another great approach to design web page and it's complete module which comes with number of feature&lt;/p&gt;

&lt;p&gt;Let's see how we can display divs side by side using css grid&lt;/p&gt;

&lt;p&gt;//html&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Grid Example&amp;lt;/title&amp;gt;
    &amp;lt;style&amp;gt;
    &amp;lt;/style&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div class="container"&amp;gt;
      &amp;lt;div class="item"&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div class="item"&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;//css file&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt; .container {
        display: grid;
        grid-template-columns: 100px 100px; 
        grid-template-rows: 100px;
        grid-column-gap: 5px;
      }
      
      .item {
      background: #ce8888;
 
       
      }&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and output will be&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r4IyC3af--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/image-9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r4IyC3af--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/image-9.png" alt="" class="wp-image-470"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;property &lt;strong&gt;display: grid&lt;/strong&gt; turns on the grid layout structure&lt;/p&gt;

&lt;p&gt;In CSS file, &lt;strong&gt;grid-template-columns property helps to divide the &lt;/strong&gt;page into number of columns, we have given 100px two times then it will create two columns&lt;/p&gt;

&lt;p&gt;It's very big module, I think you should &lt;a rel="noreferrer noopener" href="https://css-tricks.com/snippets/css/complete-guide-grid/"&gt;check it out&lt;/a&gt; first in detail then only go for using it.&lt;/p&gt;

&lt;p&gt;Find demo &lt;a href="https://codepen.io/nitinhepat/pen/YzyVMxY" rel="noreferrer noopener"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Using display table&lt;/h2&gt;

&lt;p&gt;display: table property is an alternative for &amp;lt;table&amp;gt; tag&lt;/p&gt;

&lt;p&gt;let's see how we can achieve dispaying div side by side using &lt;strong&gt;display: table&lt;/strong&gt; property&lt;/p&gt;

&lt;p&gt;//html file&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;link rel="stylesheet" href="index.css" /&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
  &amp;lt;div class="container"&amp;gt;
    &amp;lt;div class="table-row"&amp;gt;
     &amp;lt;div class="table-cell"&amp;gt;
      
      &amp;lt;/div&amp;gt;
      &amp;lt;div class="table-cell"&amp;gt;
       
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;

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

&lt;p&gt;//css file&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;.container {
  display: table;
  width: 20%;
}

.table-row {
 
  display: table-row;
  height: 100px;
}
.table-cell {
  border: 1px solid;
  background: #ce8888;
  display: table-cell;
  padding: 2px;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and output will be&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PTslggnx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/image-6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PTslggnx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/image-6.png" alt="" class="wp-image-460"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;please find demo &lt;a rel="noreferrer noopener" href="https://codepen.io/nitinhepat/pen/JjYNbGB"&gt;here&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;you can code above display: table example using html &lt;strong&gt;table &lt;/strong&gt;tag also like below&lt;/p&gt;

&lt;p&gt;//html file&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;link rel="stylesheet" href="index.css" /&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
  &amp;lt;table class="container"&amp;gt;
    &amp;lt;tr class="table-row"&amp;gt;
     &amp;lt;td class="table-cell"&amp;gt;
      
      &amp;lt;/td&amp;gt;
      &amp;lt;td class="table-cell"&amp;gt;
       
      &amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
  &amp;lt;/table&amp;gt;
  &amp;lt;/body&amp;gt;

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

&lt;p&gt;//css file&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;.container {
  display: table;
  width: 20%;
}

.table-row {
 
  display: table-row;
  height: 100px;
}
.table-cell {
  border: 1px solid;
  background: #ce8888;
  display: table-cell;
  padding: 2px;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and output will be&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Cq6J8U7D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/image-8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Cq6J8U7D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/image-8.png" alt="" class="wp-image-463"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Using float property&lt;/h2&gt;

&lt;p&gt;The &lt;a rel="noreferrer noopener" href="https://developer.mozilla.org/en-US/docs/Web/CSS/float"&gt;&lt;strong&gt;&lt;code&gt;float&lt;/code&gt;&lt;/strong&gt; &lt;/a&gt;CSS property places an element on the left or right side of its container, allowing text and inline elements to wrap around it. The element is removed from the normal flow of the page, though still remaining a part of the flow&lt;/p&gt;

&lt;p&gt;let's see how we can display div side by side using float&lt;/p&gt;

&lt;p&gt;//html file&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;

&amp;lt;head&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
  &amp;lt;div class="element"&amp;gt;
  &amp;lt;/div&amp;gt;
  &amp;lt;div class="element"&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;

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

&lt;p&gt;//css file&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;.element {
  float: left;
  width: 100px;
  height: 100px;
  background: #ce8888;
  margin: 5px
  
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and output will be&lt;/p&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IBmpmCa1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/image-7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IBmpmCa1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/image-7.png" alt="" class="wp-image-461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please find demo &lt;a href="https://codepen.io/nitinhepat/pen/ZEbKaRZ" rel="noreferrer noopener"&gt;here&lt;/a&gt;&lt;/p&gt;



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

&lt;p&gt;There are number of ways to align divs next to each other but the question is which one is better&lt;/p&gt;

&lt;p&gt;It's totally depend upon requirement&lt;/p&gt;

&lt;p&gt;flexbox and CSS grid are modern ways of doing layout for webpage and it's a complete module and comes with a number of features.I recommend flexbox or CSS grid if  need to layout the whole page&lt;/p&gt;

&lt;p&gt;If you have minimal requirement then display: inline-block is perfect option.&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
    </item>
    <item>
      <title>Detail Beginner Guide for CSS Flexbox with examples</title>
      <dc:creator>Nitin Hepat</dc:creator>
      <pubDate>Sat, 25 Apr 2020 09:32:24 +0000</pubDate>
      <link>https://dev.to/hepatnitin/detail-beginner-guide-for-css-flexbox-with-examples-5339</link>
      <guid>https://dev.to/hepatnitin/detail-beginner-guide-for-css-flexbox-with-examples-5339</guid>
      <description>&lt;p&gt;Flexbox is not a single property its complete module which comes with the number of features and here we have a complete guide for CSS flex&lt;/p&gt;

&lt;p&gt;Before going into detail I just want to answer why we should use flexbox layout instead of traditional way of doing layout webpage using display properties, float properties, positional properties&lt;/p&gt;

&lt;h3&gt;Advantages of using flexbox&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Flexbox Equally distribute height and width for the item, even though items are added dynamically, Don't need to care about CSS properties &lt;/li&gt;
&lt;li&gt;easily reverse the structure of  items&lt;/li&gt;
&lt;li&gt;easily grow and shrink the width of the item as per dynamic width of the container&lt;/li&gt;
&lt;li&gt;easily control the direction of the elements like vertical or horizontal on the basis of a single property&lt;/li&gt;
&lt;li&gt;change the order of any element&lt;/li&gt;
&lt;li&gt;96% of the browser having support for flexbox &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Layout for flexbox&lt;/h2&gt;

&lt;p&gt;we should know how flexbox works, please refer below diagram&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GFV5R7KB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/Architecture-of-flexbox.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GFV5R7KB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/Architecture-of-flexbox.png" alt="Layout of flexbox" class="wp-image-386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;flexbox is divided into two axis main axis and cross axis. &lt;/p&gt;

&lt;p&gt;In normal layout when we are using display inline or inline block. it goes from left to right only&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;main-axis: &lt;/strong&gt; This is the default axis where items laid out by default. it's not necessarily horizontal always, it can be vertical also depending upon flex-direction&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Main start/ Main-end: &lt;/strong&gt; Items will be placed from main-start  to main-end&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Main size: &lt;/strong&gt; width or height of the container depending upon flex direction&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cross-axis: &lt;/strong&gt;Cross axis is perpendicular to the main axis. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cross-start/Cross-end: &lt;/strong&gt;Items will be laid out started from cross-start to cross-end&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cross-size: &lt;/strong&gt;The width or height of a flex item, whichever is in the cross dimension, is the item's cross size. The cross size property is whichever of ‘width’ or ‘height’ that is in the cross dimension.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before starting with the flexbox properties we should understand which properties meant for flex container and flex items&lt;/p&gt;

&lt;h3&gt;Flexbox container properties&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;display&lt;/li&gt;
&lt;li&gt;flex-direction&lt;/li&gt;
&lt;li&gt;flex-wrap&lt;/li&gt;
&lt;li&gt;justify-contents&lt;/li&gt;
&lt;li&gt;align-items&lt;/li&gt;
&lt;li&gt;align-contents&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Flexbox item properties      &lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;order&lt;/li&gt;
&lt;li&gt;flex-grow&lt;/li&gt;
&lt;li&gt;flex-shrink&lt;/li&gt;
&lt;li&gt;flex-basis&lt;/li&gt;
&lt;li&gt;flex&lt;/li&gt;
&lt;li&gt;align-self&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&amp;lt;!-- /wp:column --&amp;gt;&lt;/p&gt;

&lt;h2&gt;Flexbox container properties&lt;/h2&gt;

&lt;h3&gt;display&lt;/h3&gt;

&lt;p&gt;As we know display property have number of value like inline, block, inline-block etc. But if we are giving value as flex then we are turning on flexbox context&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;.container {
  display: flex
}&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;flex-direction&lt;/h2&gt;

&lt;p&gt;flex-direction decides that how items will be laid out on main-axis horizontally or vertically&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;flex-direction: row|row-reverse|column|column-reverse|initial|inherit;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rF_pJAPw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/flex-direction-row.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rF_pJAPw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/flex-direction-row.png" alt="flex-direction" class="wp-image-394"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s5HbaC-U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/flex-direction_column.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s5HbaC-U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/flex-direction_column.png" alt="flex-direction-column" class="wp-image-396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Above are the possible values for flex-direction property&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;row: &lt;/strong&gt; row is by default value for flex-direction where item will be placed from left to right&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;row-reverse:&lt;/strong&gt; items will be placed from right to left&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;column: &lt;/strong&gt;Items will be placed vertically top to  bottom&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;column-reverse: &lt;/strong&gt;Items will be placed bottom to top&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;initial:&lt;/strong&gt; It set's value to the default&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;inherit: &lt;/strong&gt; inherit value from the parent&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;flex-wrap:&lt;/h3&gt;

&lt;p&gt;flex-wrap controls the behaviour that item will move into the next line if container width is less than total item width.&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;flex-wrap: nowrap | wrap | wrap-reverse;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Default  value: &lt;/strong&gt;nowrap&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EJVlaLbf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/flex-wrap.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EJVlaLbf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/flex-wrap.png" alt="flex-wrap" class="wp-image-398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;no-wrap&lt;/strong&gt;: fit into the one line by adjusting width of the item &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;wrap:&lt;/strong&gt; item will be laid down to next line from top to bottom&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;wrap-reverse: &lt;/strong&gt;item will be laid down to next line from bottom to top&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;flex-flow&lt;/h3&gt;

&lt;p&gt;flex flow is shorthand for flex-direction and flex-wrap&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;flex-flow: &amp;lt;flex-direction&amp;gt; | &amp;lt;flex-wrap&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Default value: &lt;/strong&gt;row no-wrap&lt;/p&gt;

&lt;p&gt;let's see some examples&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---Z-o3UWD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/flex-flow_-row-no-wrap-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---Z-o3UWD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/flex-flow_-row-no-wrap-1.png" alt="flex-flow" class="wp-image-404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Above we saw an example of flex-flow where flex-direction is row.You can do same for flex-direction column just consider above thing  vertically&lt;/p&gt;

&lt;h3&gt;justify-content&lt;/h3&gt;

&lt;p&gt;justify-conent is used align items on the main-axis.Its container propery so it will align all child items to the particular position like to the center , start or end or giving space between them.&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;justify-content: flex-start|flex-end|center|space-between|space-around|initial|inherit;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Default value: &lt;/strong&gt;flex-start&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Dm-bYTiV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/justify-content.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Dm-bYTiV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/justify-content.png" alt="justify-content" class="wp-image-406"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;ul&gt;&lt;li&gt;
&lt;strong&gt;flex-start&lt;/strong&gt; - Align items to the start of the container depending upon flex-direction&lt;/li&gt;&lt;/ul&gt;





&lt;p&gt;                 for eg.  &lt;/p&gt;





&lt;pre class="wp-block-code"&gt;&lt;code&gt;.container {
  flex-direction: row-reverse
  justify-content: flex-start;
}&lt;/code&gt;&lt;/pre&gt;





&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Hdf0Leu7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/image.png" alt="" class="wp-image-408"&gt;





&lt;p&gt;As you can see above flex-start started from right side not from writing mode direction&lt;/p&gt;





&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;center&lt;/strong&gt;:  Align items to the center&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;flex-end&lt;/strong&gt;: Align items to the end of the container as per flex-direction&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;space-around&lt;/strong&gt;: Gives space around the items by adjusting width&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;space-between&lt;/strong&gt;: gives space between the items not at the start and end of the container&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;space-evenly&lt;/strong&gt;: gives equal amount of space around the item&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;start&lt;/strong&gt;: Align items to the start of the container as per writing mode direction&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;end&lt;/strong&gt;: Align items to the end of the container as per writing mode direction&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;align-items&lt;/h3&gt;

&lt;p&gt;align items property is used to align items in respective of cross axis like we have justify content for main-axis&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;align-items: stretch|center|flex-start|flex-end|baseline|initial|inherit;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Default value: &lt;/strong&gt;stretch&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GUxyCWjW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/align-tems.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GUxyCWjW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/align-tems.png" alt="align items" class="wp-image-410"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;stretch&lt;/strong&gt;:  occupies full height of the container if height to the items not given externally&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;flex-start&lt;/strong&gt;: align items to the start of the container in consideration with cross axis&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;center&lt;/strong&gt;: align items to the center in consideration with cross axis&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;flex-end&lt;/strong&gt;: align items to the end in consideration with cross axis&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;baseline&lt;/strong&gt;: align items as per baseline of the item content in consideration with cross axis&lt;/li&gt;
&lt;/ul&gt;



&lt;h3&gt;align-content&lt;/h3&gt;

&lt;p&gt;align-content is used to align rows not items in respective of cross-axis&lt;/p&gt;

&lt;p&gt;I know you guys will get confuse what is differnece between align-items and align content&lt;/p&gt;

&lt;p&gt;let' s see an example by comparing align-items and align-content&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IMX8Jhxo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/align-items_-center.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IMX8Jhxo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/align-items_-center.png" alt="align-content" class="wp-image-443"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see above align-items: center  actually align items to center in respective of cross-axis and align-content align rows to the center in respective of cross-axis&lt;/p&gt;

&lt;p&gt;we have taken example with two rows because align-content have no effect single line&lt;/p&gt;



&lt;h2&gt;Flex item properties&lt;/h2&gt;

&lt;h3&gt;order&lt;/h3&gt;

&lt;p&gt;Using &lt;strong&gt;order &lt;/strong&gt;property it’s possible to re-arrange the natural order of container items.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Default value: 0&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xcm7rAzD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/order-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xcm7rAzD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/order-1.png" alt="order" class="wp-image-421"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see in above diragram , &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First diagram &lt;/strong&gt; shows default behaviour where all item have order value 0&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Second diagram&lt;/strong&gt;  item 1(highlited one) moves to last because its order value is greater than remaining 3&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;third diagram &lt;/strong&gt;item 3 moves to first position because it has order value -1 which smaller than other three items&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Fourth diagram &lt;/strong&gt; item 1 and item 3 moves to last because their order value is greater than others&lt;/p&gt;

&lt;h3&gt;flex-grow&lt;/h3&gt;

&lt;p&gt;flex-grow is allow  item to grow as container size greater than the total items size&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Default value: &lt;/strong&gt;0&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ayHS6Xa8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/flex-grow_0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ayHS6Xa8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/flex-grow_0.png" alt="flex-grow" class="wp-image-414"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In above example&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First diagram &lt;/strong&gt;shows default behaviour where items not accomadating remaining space takes only width provided to the item&lt;/p&gt;

&lt;p&gt;In&lt;strong&gt; Second diagram, &lt;/strong&gt; you can see we made flex-grow: 1 to all items it means all item divided remaining space in equal ratio. It will behave same if we give value as 2 to all item because we are giving ratio value&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;third diagram,  &lt;/strong&gt;item 2(highlighted one) takes twice as much as space as compared to other items because it has value 2 and its double of other items value &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: negative values are not allowed&lt;/p&gt;



&lt;h3&gt;flex-shrink&lt;/h3&gt;

&lt;p&gt;flex-shrik property allow item to shrink as container size decreases&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Default value: 0&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If all items in the container have value as 1 then all the items will shrink in equal ratio&lt;/p&gt;

&lt;p&gt;And all item have value as 1 except one item which have value 2 then this item will shrink as twice as other items&lt;/p&gt;

&lt;p&gt;for eg.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pX3bfblP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/flex-shrink_-1-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pX3bfblP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/flex-shrink_-1-1.png" alt="flex-shrink" class="wp-image-417"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see above given flex-shrink : 2 to the third element shrink twice as much as other elements.&lt;/p&gt;

&lt;p&gt;Negative values are not allowed&lt;/p&gt;

&lt;h3&gt;flex-basis&lt;/h3&gt;

&lt;p&gt;flex-basis is nothing but the min-width for the container items in flexbox context&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Default value: &lt;/strong&gt;Auto&lt;/p&gt;

&lt;p&gt;For eg. If we haven't provided flex-basis property then its by default auto then flexbox items will take width which is equal to content width&lt;/p&gt;

&lt;p&gt;flex basis always given in unit it can be %, px, em etc.&lt;/p&gt;





&lt;h3&gt;flex&lt;/h3&gt;

&lt;p&gt;flex is shorthand for flex-grow, flex-shrink and flex-basis&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Default value:&lt;/strong&gt; 0 1 auto&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;flex-grow: &amp;lt;flex-grow&amp;gt; &amp;lt;flex-shrink&amp;gt; &amp;lt;flex-basis&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;there are number of possibilities for flex values&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;/* One value, If unitless number then its flex-grow */
flex: 1;

/* One value, width/height: flex-basis */
flex: 10em;
flex: 30%;
flex: min-content;

/* Two values: flex-grow | flex-basis */
flex: 1 30px;

/* Two values: flex-grow | flex-shrink */
flex: 2 2;

/* Three values: flex-grow | flex-shrink | flex-basis */
flex: 2 2 10%;&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;align-self&lt;/h3&gt;

&lt;p&gt;align-self is for aligning individual item in respective of cross-axis and it will override value set by align items&lt;/p&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KXOKxuvM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/align-self_-center.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KXOKxuvM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/align-self_-center.png" alt="align-self" class="wp-image-419"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see In above example we have given &lt;strong&gt;align-self: center &lt;/strong&gt;to the item 2 and then only that item position has changed.&lt;/p&gt;



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

&lt;p&gt;we have learned a lot lets take an practical example&lt;/p&gt;

&lt;h3&gt;Centering element vertically and horizantally&lt;/h3&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;//html
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;link rel="stylesheet" href="index.css" /&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;section&amp;gt;
    &amp;lt;div class="container"&amp;gt;
        
        &amp;lt;div class="item"&amp;gt;
            
          &amp;lt;/div&amp;gt;
       
         
      &amp;lt;/div&amp;gt;
&amp;lt;/section&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;//css
.container {
    display: flex;
    width: 47%;
    height: 300px;
    border: 2px solid;
    padding: 5px;
}

.container .item {
    flex-basis: 100px;
    height: 96px;
    border: 2px solid;
    justify-content: center;
    color: white;
    align-items: center;
    background-color: cadetblue;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and output will be&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bpGshtzW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/image-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bpGshtzW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/image-2.png" alt="" class="wp-image-445"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Creating a Navbar &lt;/h3&gt;

&lt;p&gt;navbar.html&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;link rel="stylesheet" href="index.css" /&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;section class="main-container"&amp;gt;
        &amp;lt;div class="logo-container container"&amp;gt;
            &amp;lt;strong&amp;gt;Logo&amp;lt;/strong&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;ul class="menu-container container"&amp;gt;
            
            &amp;lt;li class="menu"&amp;gt;
                &amp;lt;strong&amp;gt;
                    Home
                &amp;lt;/strong&amp;gt;
            &amp;lt;/li&amp;gt;
            &amp;lt;li class="menu"&amp;gt;
                &amp;lt;strong&amp;gt;
                    Contact Us
                &amp;lt;/strong&amp;gt;
            &amp;lt;/li&amp;gt;
            &amp;lt;li class="menu"&amp;gt; 
                &amp;lt;strong&amp;gt;
                    About Us
                &amp;lt;/strong&amp;gt;
            &amp;lt;/li&amp;gt;

        &amp;lt;/div&amp;gt;
    &amp;lt;/section&amp;gt;
&amp;lt;/body&amp;gt;

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

&lt;p&gt;and css file&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;.main-container {
    display: flex;
    background: #ce8888;
}
.container {
    flex-basis: 50%;
}
.logo-container {
    justify-content: flex-start;
    align-items: center;
    display: flex;
    color: white;
    padding: 10px;
    font-size: x-large;
     
}
.menu-container {
    display: flex;
    height: 60px;
    justify-content: flex-end;
    align-items: center;
    padding: 0;
    width: 50%;
    margin: 0;
}

.menu-container .menu {
  
    padding: 4px 10px;
    border-radius: 5px;
    color: bisque;
    display: flex;
    justify-content: center;
    align-items: center;
    align-items: center;
    cursor: pointer;
}

.menu-container .menu:active ,.menu-container .menu:hover{
    background: repeating-linear-gradient(45deg, #824e4e, transparent 100px)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and output will be&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_osWC1Au--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/image-3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_osWC1Au--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/04/image-3.png" alt="" class="wp-image-446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can check &lt;a href="https://codepen.io/nitinhepat/pen/BaoWzOO" rel="noreferrer noopener"&gt;demo here&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;CSS flexbox has very good feature to do layout for the webpage. If you guys understand Please share it and you feel free to ask question in Comments&lt;/p&gt;

&lt;p&gt;follow me on &lt;a rel="noreferrer noopener" href="https://twitter.com/HepatNitin"&gt;twitter&lt;/a&gt; for updates on latest projects&lt;/p&gt;

</description>
      <category>css</category>
      <category>javascript</category>
      <category>html</category>
    </item>
    <item>
      <title>How To Remove Duplicates In Array Using Javascript ES6</title>
      <dc:creator>Nitin Hepat</dc:creator>
      <pubDate>Fri, 10 Apr 2020 16:49:17 +0000</pubDate>
      <link>https://dev.to/hepatnitin/how-to-remove-duplicates-in-array-using-javascript-es6-mnl</link>
      <guid>https://dev.to/hepatnitin/how-to-remove-duplicates-in-array-using-javascript-es6-mnl</guid>
      <description>&lt;p&gt;In javascript programming there are number of ways to remove duplicates from array, But which is best and short it's hard to decide&lt;/p&gt;

&lt;p&gt;Let's discuss how to remove duplicates from array of primitives(like array of string, array of numbers) and array of non-primitives(like array of objects)&lt;/p&gt;

&lt;h2&gt;Using indexOf method &lt;/h2&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;const dataArr = ['1','5','6','1','3','5','90','334'];

const resultArr = dataArr.filter((data,index)=&amp;gt;{
  return dataArr.indexOf(data) === index;
})

console.log(resultArr); //["1", "5", "6", "3", "90", "334"]&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As we know, That filter method is used for filtering method from the array as per the given condition&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;dataArr.indexOf(data) === index&lt;/strong&gt; , indexOf method always return first occurance &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Data Array&lt;/td&gt;
&lt;td&gt;position&lt;/td&gt;
&lt;td&gt;indexOf&lt;/td&gt;
&lt;td&gt;result&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt; 90&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;334&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The above table is the tabular structure of filter method where on the basis of the condition it filters element. As you can see indexOf always return the position of the first occurrence of an element, so when duplicate element comes then indexOf not returns the position of a current element it returns the position of the first occurrence of element.&lt;/p&gt;

&lt;h2&gt;Using Set&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set"&gt;Set  &lt;/a&gt;is an Object introduced in ES6, Used for storing collection of unique values&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;const dataArr = ['1','5','6','1','3','5','90','334','90'];

//creates  Set object from array of unique element
const dataArrWithSet = new Set(dataArr);


//we can create Set object to array also using spread operator
const resultArr = [...dataArrWithSet];

console.log(resultArr); &lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Above method is my favorite, which require minimum line of code&lt;/p&gt;

&lt;h2&gt;Using reduce&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce"&gt;reduce &lt;/a&gt;is a method of Array prototype which have reducer function which executes on each element and results in a single output value&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;const dataArr = ['1','5','6','1','3','5','90','334','90'];


const resultArr = dataArr.reduce((acc,item)=&amp;gt;{
      if(!acc.includes(item)){
        acc.push(item);
      }
    return acc;
},[])

console.log(resultArr);//["1", "5", "6", "3", "90", "334"]&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In the above eg. acc is an accumulator which is initialized with an empty array and whatever reducer function returning result stored into the accumulator. But, before storing elements into the accumulator we are checking that element is already present or not, If the element not present in the accumulator then we are pushing elements into the accumulator. So, there are no chances of pushing duplicate elements into an accumulator. So at the final result, we will get a collection of unique elements&lt;/p&gt;

&lt;h2&gt;Using forEach method&lt;/h2&gt;

&lt;p&gt;forEach is a method of Array prototype which used to iterate over elements of the array&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;const dataArr = ['1','5','6','1','3','5','90','334','90'];

const uniqueArr = [];
dataArr.forEach((item)=&amp;gt;{
    //pushes only unique element
      if(!uniqueArr.includes(item)){
        uniqueArr.push(item);
      }
   
})

console.log(uniqueArr); //["1", "5", "6", "3", "90", "334"]&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In the above eg. In uniqueArr we only pushing item when the item is not already there.So, at last, we will get a collection of unique elements&lt;/p&gt;



&lt;h2&gt;Removing duplicates from Array of objects&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://techboxweb.com/how-to-remove-duplicates-in-array-using-javascript-es6"&gt;For full post click here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>es6</category>
    </item>
    <item>
      <title>Performance optimization with react PureComponent and React memo</title>
      <dc:creator>Nitin Hepat</dc:creator>
      <pubDate>Wed, 18 Mar 2020 10:26:09 +0000</pubDate>
      <link>https://dev.to/hepatnitin/performance-optimization-with-react-purecomponent-and-react-memo-3ch8</link>
      <guid>https://dev.to/hepatnitin/performance-optimization-with-react-purecomponent-and-react-memo-3ch8</guid>
      <description>&lt;p&gt;Before digging into the PureCompoment thoroughly let's understand the difference between React component and PureComponent&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: Considering you have basic knowledge of react.&lt;/p&gt;

&lt;p&gt;In React Component, If you want to optimize performance then we have to implement shouldComponentUpdate lifecycle method where we can add condition check to see is props or state has been different from previous ones or not If it changed then only we will return true in shouldComponentUpdate method which will force to call render method otherwise render will get called every time props or state changed.&lt;/p&gt;

&lt;h2&gt;What PureComponent makes different from Component?&lt;/h2&gt;

&lt;p&gt;If you are extending the PureComponent class then you don't need to take care of shouldComponentUpdate lifecycle method. PureComponent itself takes care by shallow checking states and props. If it finds states and props are different from the previous state and props then only it calls render method else not.&lt;/p&gt;

&lt;h2&gt;What does shallow check mean?&lt;/h2&gt;

&lt;p&gt; Shallow compare does check for equality. When comparing primitive values (numbers, strings) it compares their values. When comparing nonprimitive like objects or arrays, it does not compare their's attributes - only their references are compared &lt;/p&gt;

&lt;p&gt;For eg., If you have an array and you are pushing element to an existing array then PureComponent does not trigger render method because as per PureComponent there is no change happened because reference is still the same&lt;/p&gt;

&lt;p&gt;Let's go by example&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;import React, { PureComponent } from 'react';
import { render } from 'react-dom';
import Hello from './Hello';
import './style.css';

class App extends PureComponent {
  constructor() {
    super();
    this.state = {
      personArr: [
        {
          name: "abc",
          age: "22 years",
          gender: "male"
        },
        {
          name: "pqr",
          age: "23 years",
          gender: "female"
        },
        {
          name: "mno",
          age: "24 years",
          gender: "male"
        }
      ]
    };
  }
  addPerson() {
    var persons = this.state.personArr;
    persons.push({
      name: "xyz",
      age: "32 years",
      gender: "male"
    });
    this.setState({
      perosnArr: persons
    });
  }

render() {
    const persons = this.state.personArr.map((person, index) =&amp;gt; {
      return (
        &amp;lt;section&amp;gt;
          &amp;lt;div&amp;gt;
            &amp;lt;label&amp;gt;Name:&amp;lt;/label&amp;gt; {person.name}
          &amp;lt;/div&amp;gt;
          &amp;lt;div&amp;gt;
            &amp;lt;label&amp;gt;Age:&amp;lt;/label&amp;gt;
            {person.age}
          &amp;lt;/div&amp;gt;
          &amp;lt;div&amp;gt;
            &amp;lt;label&amp;gt;Gender:&amp;lt;/label&amp;gt;
            {person.gender}
          &amp;lt;/div&amp;gt;
        &amp;lt;/section&amp;gt;
      );
    });
    return (
      &amp;lt;div className="App"&amp;gt;
        &amp;lt;button onClick={() =&amp;gt; this.addPerson()}&amp;gt;Add person&amp;lt;/button&amp;gt;
        {persons}
      &amp;lt;/div&amp;gt;
    );
  }
}

render(&amp;lt;App /&amp;gt;, document.getElementById('root'));
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As you can see in the above code we are rendering a person's array and also we have added person button which pushing person object to an existing array.&lt;/p&gt;

&lt;p&gt;so, Here PureComponent not let render method run because here an array is a non-primitive type so reference has been checked.&lt;/p&gt;

&lt;p&gt;Here I think you might be thinking why PureComponent only checks the reference, not internal attributes because if react implements this logic then it's going to be a very expensive operation performance-wise.&lt;/p&gt;

&lt;p&gt; Still, you want to run the render method after pushing element to an array then you should not mutate existing array, even react suggest should not mutate existing element.&lt;/p&gt;

&lt;p&gt;For eg.&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;addPerson(){
  const perosnArr = this.state.personArr;
  perosnArr.push({
    name: "xyz",
    age: "32 years",
    gender: "male"
  })
  this.setState({
    perosnArr: {...personArr}
  })

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

&lt;p&gt;As you can see above I am not mutating existing array, I have created a new array using spread operator now the reference is different for old and new array so now render method will trigger.&lt;/p&gt;

&lt;p&gt;Please check the example &lt;a href="https://stackblitz.com/edit/react-dij6dw"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Improve performance in functional components using React.memo()&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://techboxweb.com/performance-optimization-with-react-purecomponent-and-react-memo/"&gt;For Full post click here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
    </item>
    <item>
      <title>Building a Javascript single page application without framework</title>
      <dc:creator>Nitin Hepat</dc:creator>
      <pubDate>Thu, 05 Mar 2020 17:10:28 +0000</pubDate>
      <link>https://dev.to/hepatnitin/building-a-javascript-single-page-application-without-framework-23n3</link>
      <guid>https://dev.to/hepatnitin/building-a-javascript-single-page-application-without-framework-23n3</guid>
      <description>&lt;p&gt;Hello guys here we come with new tutorial for how to create single page application without framework.&lt;/p&gt;

&lt;p&gt;Good developer always keen to understand how the single page application works internally because nowadays we are busy in learning frameworks but we don't think how it works internally because we don't want to but as a good programmer you should know in and out for a thing which you are learning.&lt;/p&gt;

&lt;p&gt;First of all,&lt;/p&gt;

&lt;h2&gt;What is single page application?&lt;/h2&gt;

&lt;p&gt;Single page application is terminology in which you load the multiple pages dynamically without reloading an application, Like we have angular framework specifically made for single page application&lt;/p&gt;

&lt;p&gt;Let's get started&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: We will be following the ES6 standard for coding. It means code which we are writing will not run directly on the browser, as of now browsers are not supporting most of the ES6 standard functionality directly but don't worry we will add an appropriate compiler which will convert our code in browser understandable language.&lt;/p&gt;

&lt;p&gt;so finally let's start&lt;/p&gt;

&lt;h2&gt;Creating a single page application&lt;/h2&gt;

&lt;p&gt; We will implement Single page application with location hash approach and using webpack for bundling and compiling purpose&lt;/p&gt;

&lt;h3&gt;Setting up a project&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Run 'npm init' command for creating package.json&lt;/li&gt;
&lt;li&gt;Install webpack dependencies like below&lt;ol&gt;&lt;li&gt;npm install webpack webpack-cli -D&lt;/li&gt;&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;after that let's create folder structure&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--t07KrStx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/03/image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--t07KrStx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://techboxweb.com/wp-content/uploads/2020/03/image.png" alt="" class="wp-image-239" width="345" height="316"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see above we have created folder structure in that we have components folder in which we will keep our javascript files&lt;/p&gt;

&lt;p&gt;libs folder is for the keeping our library files(might include routing js files which will be developed by us for single page application purpose)&lt;/p&gt;

&lt;p&gt;views folder will contain HTML files which will be needed to load on routing&lt;/p&gt;

&lt;p&gt;index.html and index.js are entry points for our application&lt;/p&gt;

&lt;p&gt;webpack.config.js is for writing webpack configuration&lt;/p&gt;

&lt;h2&gt;Index.html&lt;/h2&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;a href="#detail"&amp;gt;Details&amp;lt;/a&amp;gt;
    &amp;lt;a href="#landing"&amp;gt;Landing&amp;lt;/a&amp;gt;
    &amp;lt;section id="app"&amp;gt;
    &amp;lt;/section&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As you can see above, In index.html we have taken two href tag in which we have routing for detail and landing links, so here the moto is to load view associated with this links&lt;/p&gt;

&lt;p&gt;section with id 'app' is taken for loading routes dynamically under this.&lt;/p&gt;

&lt;p&gt;Now, let's create routing files&lt;/p&gt;

&lt;h3&gt;Route.js&lt;/h3&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;export class Routes {
    constructor(viewObj, isDefaultRoute) {
        this.viewObj = viewObj;
        this.isDefaultRoute = isDefaultRoute;
    }
    isActiveRoute(hashPath) {
        return hashPath.replace('#', '') === this.viewObj.path
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In the above code, we have properties which will require for individual routes&lt;/p&gt;

&lt;p&gt;like viewObj will contain path and URL properties like below&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;{
 path: 'path',
 templateUrl : 'path/to/html'
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;isDefaultRoute will decide which one to be loaded by default if any path doen't match with loacation hash&lt;/p&gt;

&lt;p&gt;isActiveRoute function will let you know the currently active route&lt;/p&gt;

&lt;p&gt; Now let's create Router.js which will take care functionality of routing&lt;/p&gt;

&lt;h3&gt;Router.js&lt;/h3&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;export class Router {
    constructor(routes, routeElement) {
        this.routes = routes;
        this.routeElement = document.getElementById(routeElement);
        this.initialize();
        this.hashChanged();
    }
    getPathAndRouteMapping() {
        const routeMapping = {};
        for (let objKey in this.routes) {
            routeMapping[this.routes[objKey].viewObj.path] = this.routes[objKey].viewObj.url;
        }
        return routeMapping;
    }
    initialize() {
        window.addEventListener('hashchange', (e) =&amp;gt; {
            this.hashChanged()
        })
    }
    hashChanged() {
        const locationHash = window.location.hash;
        for (let i = 0; i &amp;lt; this.routes.length; i++) {
            const route = this.routes[i];
            if (route.isActiveRoute(locationHash.substr(1))) {
                this.navigate(route.viewObj.path)
            }
        }
    }
    navigate(path) {
        const pathRouteMapping = this.getPathAndRouteMapping();
        const url = pathRouteMapping[path];
        const xhttp = new XMLHttpRequest();
        let scope = this;
        xhttp.onreadystatechange = function() {
            if (this.readyState === 4 &amp;amp;&amp;amp; this.status === 200) {
                scope.routeElement.innerHTML = this.responseText;
            }
        };
        xhttp.open('GET', url, true);
        xhttp.send();
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It is the main class where we have the main magic of the code&lt;/p&gt;

&lt;p&gt;Here 4 functions and one constructor&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constructor&lt;/strong&gt;: constructor accepting 2 parameters in which 1st one is routing configuration which of &lt;strong&gt;Routes &lt;/strong&gt;class type and another one is a root element where our view will be loaded dynamically&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;initialize&lt;/strong&gt; function is for attaching hashchange event listener which will be fired when location hash changes&lt;/p&gt;

&lt;p&gt; hashChange function calls every time when hashchange event fires and in that we match with correct route and load that URL&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;navigate&lt;/strong&gt; function takes care of loading HTML with the help of ajax request&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;getPathAndRouteMapping&lt;/strong&gt; function is used for persisting a mapping of path and URL.&lt;/p&gt;



&lt;p&gt;Please check &lt;a href="https://github.com/nitinhepat/spa-without-framework"&gt;this &lt;/a&gt;code repository for whole code&lt;/p&gt;

&lt;p&gt;In above example we just covered basics of routing we can make it advance. Before going forward at least you guys start with this.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>es6</category>
      <category>framework</category>
    </item>
  </channel>
</rss>
