<?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: technikhil314</title>
    <description>The latest articles on DEV Community by technikhil314 (@technikhil314).</description>
    <link>https://dev.to/technikhil314</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%2F258868%2F0c648929-cdd6-4c19-a072-3efe271c9025.jpeg</url>
      <title>DEV Community: technikhil314</title>
      <link>https://dev.to/technikhil314</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/technikhil314"/>
    <language>en</language>
    <item>
      <title>How to run any project with one command?</title>
      <dc:creator>technikhil314</dc:creator>
      <pubDate>Thu, 21 Jul 2022 05:06:32 +0000</pubDate>
      <link>https://dev.to/technikhil314/how-to-run-any-project-with-one-command-3pk1</link>
      <guid>https://dev.to/technikhil314/how-to-run-any-project-with-one-command-3pk1</guid>
      <description>&lt;p&gt;Often times I like to try out new things in web development and nodejs world. But there is one problem with it.&lt;/p&gt;

&lt;p&gt;I have tried out to create a new projects using &lt;a href="https://create-react-app.dev/"&gt;create-react-app&lt;/a&gt;, &lt;a href="https://nextjs.org/docs/api-reference/create-next-app"&gt;create-next-app&lt;/a&gt; or any backend app using &lt;a href="https://expressjs.com/"&gt;express&lt;/a&gt; or &lt;a href="https://hapi.dev/"&gt;hapi&lt;/a&gt;, or any monorepo using &lt;a href="https://lerna.js.org/"&gt;lerna&lt;/a&gt;, &lt;a href="https://turborepo.org/"&gt;turbo&lt;/a&gt; or &lt;a href="https://nx.dev/"&gt;nx&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;But the command to start development environment or build the project changes from one to another. &lt;/p&gt;

&lt;p&gt;viz.&lt;br&gt;
&lt;code&gt;create-react-app&lt;/code&gt; starts development environment with &lt;code&gt;npm start&lt;/code&gt;&lt;br&gt;
&lt;code&gt;create-next-app&lt;/code&gt; starts development environment with &lt;code&gt;npm run dev&lt;/code&gt;&lt;br&gt;
and so on.&lt;/p&gt;

&lt;p&gt;and  there is no one command to rule them all.&lt;br&gt;
But don't worry there is one solution to it.&lt;/p&gt;

&lt;p&gt;You need to have &lt;a href="https://github.com/ohmyzsh/ohmyzsh/wiki/Installing-ZSH"&gt;zsh&lt;/a&gt;, &lt;a href="https://github.com/ohmyzsh/ohmyzsh#basic-installation"&gt;oh-my-zsh&lt;/a&gt; installed on your system to take advantage of the solution&lt;/p&gt;

&lt;p&gt;Here is how you can do it&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Enable &lt;code&gt;dotenv&lt;/code&gt; plugin in &lt;code&gt;zsh&lt;/code&gt;. Edit your &lt;code&gt;~/.zshrc&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;plugins&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;dotenv&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Now this plugin will always automatically source your &lt;code&gt;.env&lt;/code&gt; file everytime you cd into your project directory that contains a &lt;code&gt;.env&lt;/code&gt; file&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Create and add following content a &lt;code&gt;.env&lt;/code&gt; to &lt;code&gt;create-react-app&lt;/code&gt; project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;ns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"npm start"&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;nb&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"npm run build"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Create and add following content a &lt;code&gt;.env&lt;/code&gt; to &lt;code&gt;create-next-app&lt;/code&gt; project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;ns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"npm run dev"&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;nb&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"npm run build"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: For java spring boot project you can add following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;ns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"mvn org.springframework.boot:spring-boot-maven-plugin:run"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now when you &lt;code&gt;cd&lt;/code&gt; into &lt;code&gt;create-react-app&lt;/code&gt; project then all you need to run &lt;code&gt;ns&lt;/code&gt; to start project&lt;br&gt;
also when you &lt;code&gt;cd&lt;/code&gt; into &lt;code&gt;create-next-app&lt;/code&gt; project then as well you need to run &lt;code&gt;ns&lt;/code&gt; to start the project&lt;/p&gt;

&lt;p&gt;Thats it its just one time configuration you have to do in your project and you are done. No more remembering project specific commands. Cheers. Enjoy. &lt;/p&gt;

</description>
      <category>shell</category>
      <category>developers</category>
      <category>zsh</category>
      <category>tip</category>
    </item>
    <item>
      <title>Debounce and throttle simplified</title>
      <dc:creator>technikhil314</dc:creator>
      <pubDate>Fri, 18 Feb 2022 05:32:16 +0000</pubDate>
      <link>https://dev.to/technikhil314/debounce-and-throttle-simplified-4ek6</link>
      <guid>https://dev.to/technikhil314/debounce-and-throttle-simplified-4ek6</guid>
      <description>&lt;p&gt;I was trying to create my own implementation of debounce and throttle. Yes just for fun.&lt;br&gt;
and I came up with very simplified implementation that anyone can follow just by taking a look at the code.&lt;/p&gt;

&lt;p&gt;You can play with the &lt;a href="https://debounce-throttle.surge.sh/"&gt;demo here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you like it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Throttle
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;throttle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fun&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;timeduration&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;shouldCall&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;shouldCall&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;shouldCall&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;fun&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;shouldCall&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;timeduration&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Debounce
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;debounce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fun&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;timeduration&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;lastTimeoutId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;lastTimeoutId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;lastTimeoutId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;lastTimeoutId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;fun&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;timeduration&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to use it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;showValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&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;throttleInput&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;throttle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;showValue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&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;debouncedInput&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;debounce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;showValue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>The unused destructuring in Javascript</title>
      <dc:creator>technikhil314</dc:creator>
      <pubDate>Thu, 17 Jun 2021 06:22:41 +0000</pubDate>
      <link>https://dev.to/technikhil314/the-unused-destructuring-in-javascript-1iln</link>
      <guid>https://dev.to/technikhil314/the-unused-destructuring-in-javascript-1iln</guid>
      <description>&lt;p&gt;I was just going through MDN and ECMA specs and trying out some cool little time saving tricks with destructuring in javascript.&lt;/p&gt;

&lt;h3&gt;
  
  
  Destructuring array based on index
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;first&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;forth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;rest&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;first&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 10&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;forth&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 40&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// {1: 20, 2: 30, 4: 50}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Ignore some values from array at a particular position
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Using dynamic key in destructuring
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;ab&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="p"&gt;{[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="nx"&gt;aVal&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ab&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;aVal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;You can even use function call, string template etc in the dynamic key&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getDynamicKey&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;ab&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="p"&gt;{[&lt;/span&gt;&lt;span class="nx"&gt;getDynamicKey&lt;/span&gt;&lt;span class="p"&gt;()]:&lt;/span&gt; &lt;span class="nx"&gt;aVal&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ab&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;aVal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Importance of destructuring in react hooks</title>
      <dc:creator>technikhil314</dc:creator>
      <pubDate>Mon, 03 May 2021 13:00:50 +0000</pubDate>
      <link>https://dev.to/technikhil314/importance-of-destructuring-in-react-hooks-3kbi</link>
      <guid>https://dev.to/technikhil314/importance-of-destructuring-in-react-hooks-3kbi</guid>
      <description>&lt;p&gt;Have you realized that we are using destructuring every where with react hooks. Take a look at this simple example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [counter, setCounter] = useState(0);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are using destructuring here, to get statevalue and state updater function. But why does it have to be this way always.&lt;/p&gt;

&lt;p&gt;well here is my take on explaining why destructuring is important. Take a look at this sandbox. Its a simple counter component that updates every second. &lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/n28hz"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If you check the logs on the console. They will be something 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;counter updated new value is 0 
setCounter  updated 
counter updated new value is 1 
counter updated new value is 2 
counter updated new value is 3 
counter updated new value is 4 
counter updated new value is 5 
.
.
.
.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now suppose we don't use destructuring for useState hook and accept it as array in which &lt;code&gt;state[0]&lt;/code&gt; is our counter value and &lt;code&gt;state[1]&lt;/code&gt; is counter updater function. Check the sandbox&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/ectty"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;and check the logs on console too&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;counter updated new value is 0 
setCounter  updated 
counter updated new value is 1 
setCounter  updated 
counter updated new value is 2 
setCounter  updated 
counter updated new value is 3 
setCounter  updated 
counter updated new value is 4 
setCounter  updated
.
.
.
.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What does this mean. It means following set of conclusions&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Any hook gets called during rerender too&lt;/li&gt;
&lt;li&gt;The return value of hook on each rerender is not referentially the same (except if you are returning primitive values from hook)&lt;/li&gt;
&lt;li&gt;Always destructure values from hook for sake of simplicity in the code.&lt;/li&gt;
&lt;li&gt;useEffect dependancy are shallow checked for equality. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I hope you like or understood what I am trying to explain here. If you have any suggestion please comment it down below. &lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Creating live coding videos right from your browser</title>
      <dc:creator>technikhil314</dc:creator>
      <pubDate>Thu, 22 Apr 2021 14:54:05 +0000</pubDate>
      <link>https://dev.to/technikhil314/creating-live-coding-videos-right-from-your-browser-1b44</link>
      <guid>https://dev.to/technikhil314/creating-live-coding-videos-right-from-your-browser-1b44</guid>
      <description>&lt;p&gt;For those who are lazy in reading my motivation behind creating this small tool &lt;a href="https://bit.ly/3sImsyU"&gt;just go here and try it out&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All this time I was thinking of starting my own youtube channel where I would be share my learnings frequently. &lt;/p&gt;

&lt;p&gt;But when I asked a few of my colleagues they told me to use OBS studio to create videos where I had to learn about how to setup OBS studio effectively for better audio quality, video quality. And I immediately got frustrated of trying out different settings.&lt;/p&gt;

&lt;p&gt;But then I thought of trying out to create a web based live coding video creator. To my surprise I created whole video recorder (screen and webcam both) just in browser. It leverages latest browser features like &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder"&gt;MediaRecorder&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Picture-in-Picture_API"&gt;Picture-in-Picture&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia"&gt;Media access&lt;/a&gt; and also uses modern machine learning libraries like &lt;a href="https://github.com/tensorflow/tfjs"&gt;tensforflow.js&lt;/a&gt; and &lt;a href="https://github.com/tensorflow/tfjs-models/tree/master/body-pix"&gt;bodypix model&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I have developed the application using &lt;a href="https://nextjs.org/"&gt;next.js&lt;/a&gt; and &lt;a href="https://tailwindcss.com/"&gt;tailwind.css&lt;/a&gt; and have deployed to vercel. &lt;a href="https://bit.ly/3sImsyU"&gt;You can try it here&lt;/a&gt;. The code is available to contribute and play around &lt;a href="https://github.com/technikhil314/next-webrtc"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devlive</category>
      <category>webdev</category>
      <category>opensource</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Uses of CSS conic gradients</title>
      <dc:creator>technikhil314</dc:creator>
      <pubDate>Wed, 14 Oct 2020 15:31:49 +0000</pubDate>
      <link>https://dev.to/technikhil314/no-svg-progress-ring-49do</link>
      <guid>https://dev.to/technikhil314/no-svg-progress-ring-49do</guid>
      <description>&lt;p&gt;With &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/conic-gradient"&gt;conic gradient&lt;/a&gt; landing up in firefox 83. It will now have good support. Removing dependancy on SVG for some simple usecases progress ring is one of them.&lt;/p&gt;

&lt;p&gt;Here is how I have achieved it with &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/conic-gradient"&gt;conic gradient&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties"&gt;custom css properties&lt;/a&gt; and eight lines of javascript.&lt;/p&gt;

&lt;p&gt;Check it out here &lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/nikhil-001mehta/embed/abZdzey?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
 &lt;/p&gt;

&lt;h2&gt;
  
  
  What more can we achieve with conic gradients:
&lt;/h2&gt;

&lt;p&gt;You can create pie charts like this&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/nikhil-001mehta/embed/dyXGGJV?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
 &lt;/p&gt;

&lt;p&gt;or some awesome checkerboard background patterns like this&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/nikhil-001mehta/embed/LYZGGBz?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
 &lt;/p&gt;

&lt;p&gt;or something like this&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/nikhil-001mehta/embed/dyXGGEm?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
 &lt;/p&gt;

&lt;p&gt;or some fancy borders like these&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/nikhil-001mehta/embed/GRqooYX?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
 &lt;/p&gt;

&lt;p&gt;or a hue color wheel&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/nikhil-001mehta/embed/jOrWWQN?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
 &lt;/p&gt;

&lt;p&gt;References:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;There is nice article already by &lt;a href="https://twitter.com/jeremenichelli"&gt;Jeremias Menichelli
&lt;/a&gt; about creating progress rings using svg &lt;a href="https://css-tricks.com/building-progress-ring-quickly/"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Use of CSS custom properties inspired from &lt;a href="https://www.youtube.com/watch?v=kZOJCVvyF-4"&gt;this talk&lt;/a&gt; by &lt;a href="https://twitter.com/LeaVerou"&gt;Lea Verou&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>css</category>
      <category>ux</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Adding badges to your open source project in 2 seconds</title>
      <dc:creator>technikhil314</dc:creator>
      <pubDate>Mon, 05 Oct 2020 11:04:06 +0000</pubDate>
      <link>https://dev.to/technikhil314/adding-badges-to-your-open-source-project-in-2-seconds-358p</link>
      <guid>https://dev.to/technikhil314/adding-badges-to-your-open-source-project-in-2-seconds-358p</guid>
      <description>&lt;p&gt;Are you a open sourcer or maintainer for open source project?? Have you automated adding badges to your repo?? Let me know how you do it.&lt;/p&gt;

&lt;p&gt;Adding badges to your readme file is such a pathetic and robotic feel job. I have seen people doing following&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Everytime go to shields.io or badgen.net&lt;/li&gt;
&lt;li&gt;Search for your badge by name e.g. travis&lt;/li&gt;
&lt;li&gt;Copy the url paste to your readme&lt;/li&gt;
&lt;li&gt;and format it to add links to proper destination etc etc&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;damn it took 45 seconds for me to type the process and may be 15 seconds for you to read all the steps. Imagine how much time it will take to add 10 badges.&lt;/p&gt;

&lt;p&gt;I thought there must be some tool out there to do this but I did not find one (Please comment if you know of any such tool)&lt;/p&gt;

&lt;p&gt;But I decided to created one such tool which will&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;See for all files through your current working directory&lt;/li&gt;
&lt;li&gt;and add badges accordingly&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Here is the demo of it running
&lt;/h2&gt;


&lt;div class="ltag_asciinema"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  How can you use it
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;npm i -g git-auto-badger&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;add a placeholder in your readme to tell where to add badges check &lt;a href="https://github.com/technikhil314/auto-badger"&gt;the repo&lt;/a&gt; for more info&lt;/li&gt;
&lt;li&gt;run &lt;code&gt;auto-badger&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Done. All the necessary badges for any OSS project are addeddto your markdown. Commit and push. Njoy.&lt;/p&gt;

&lt;p&gt;By necessary badges I mean following&lt;/p&gt;

&lt;p&gt;Build status, Code coverage, NPM package version, Dependancies monitor, all contributors count, star on github, fork on github&lt;/p&gt;

&lt;p&gt;visit &lt;a href="https://github.com/technikhil314/auto-badger"&gt;https://github.com/technikhil314/auto-badger&lt;/a&gt; for more details. Feel free to give feedback or leave comment. &lt;/p&gt;

</description>
      <category>opensource</category>
      <category>github</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Making forms by getting most out of HTML and CSS</title>
      <dc:creator>technikhil314</dc:creator>
      <pubDate>Wed, 23 Sep 2020 14:03:01 +0000</pubDate>
      <link>https://dev.to/technikhil314/making-forms-by-getting-most-out-of-html-and-css-4k19</link>
      <guid>https://dev.to/technikhil314/making-forms-by-getting-most-out-of-html-and-css-4k19</guid>
      <description>&lt;p&gt;With &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:placeholder-shown"&gt;placeholder-shown&lt;/a&gt; now supporting as much as 95% browsers &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--f-lZQfLh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://caniuse.bitsofco.de/static/v1/css-placeholder-shown-1600858837621.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--f-lZQfLh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://caniuse.bitsofco.de/static/v1/css-placeholder-shown-1600858837621.png" alt="caniuse-placeholder-shown-support-chart"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I thought I can use it in production but before that I wanted to be sure of it and to check whether I can really use it in production.&lt;/p&gt;

&lt;p&gt;My target was&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;to not use any javascript for simple form validation like required, min length, max length, min value, max value etc.&lt;/li&gt;
&lt;li&gt;And see how many capabilities can I add to html form. &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  I was able to achieve following
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Show error feedback when the input is invalid while user is typing in it&lt;/li&gt;
&lt;li&gt;Show error message below the input explaining what is the error&lt;/li&gt;
&lt;li&gt;Not showing any error message if input is blank or user had not interacted with it.&lt;/li&gt;
&lt;li&gt;Show success feedback when input becomes valid while user is typing in it.&lt;/li&gt;
&lt;li&gt;Keeping the accesibility of HTML form intact so that keyboard tab index, screen readers and other assistive tools will work fine with it.&lt;/li&gt;
&lt;li&gt;Mark label associated with required input fields with asterisk * (I have leveraged flex for this)&lt;/li&gt;
&lt;li&gt;Disable form submit button when form is invalid&lt;/li&gt;
&lt;li&gt;Show optional fields as valid even when user has not interacted with them&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Everything said above is done with just HTML and CSS. &lt;/p&gt;

&lt;p&gt;Please check it here if you are interested to know how &lt;iframe height="600" src="https://codepen.io/nikhil-001mehta/embed/BaKvPqG?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Limitations:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:placeholder-shown"&gt;placeholder-shown&lt;/a&gt; as the name suggests can be used only with those input types that allow showing placeholders. 
Viz. input[type="text"], input[type="number"], input[type="search"], input[type="email"], input[type="url"], input[type="tel"], input[type="number"] and textarea are the only interactive form elements that support placeholders&lt;/li&gt;
&lt;li&gt;For others form elements you need to use either &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:blank"&gt;blank&lt;/a&gt; which has absolutely 0% browser support as of now
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_fzbbLkV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://caniuse.bitsofco.de/static/v1/mdn-css__selectors__blank-1600865327412.png" alt=":blank css selector"&gt;
&lt;/li&gt;
&lt;li&gt;or use &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:indeterminate"&gt;indeterminate pseudo class&lt;/a&gt; for which you need to add little bit of javascript. but has a good browser support &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IOCNSw3X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://caniuse.bitsofco.de/static/v1/mdn-css__selectors__indeterminate-1600867581935.png" alt="css selectors indeterminate"&gt; but unfortunately it can be used with only radio, checkbox input types
check the JS section of this codepen &lt;iframe height="600" src="https://codepen.io/nikhil-001mehta/embed/BaKvPqG?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/li&gt;
&lt;li&gt;For select box you need to have a non blank default selected option as it also does not support placeholder.&lt;/li&gt;
&lt;li&gt;You can not do complex validation like confirm password with this for obvious reasons. &lt;/li&gt;
&lt;/ol&gt;

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

&lt;ol&gt;
&lt;li&gt;I felt we can use this in production cause anyways we tend to use custom date pickers for our custom design and custom multiselect boxes which can be used as single select boxes too. This adds a complexity to handle date pickers on touch devices seperately though. &lt;/li&gt;
&lt;li&gt;Once we have &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:blank"&gt;blank&lt;/a&gt; selector this can be the go to thing&lt;/li&gt;
&lt;li&gt;This can be a very good for simple form validations which can be fulfilled by just using HTML5 form controls.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Thanks for reading it till here. And Thats all. :)&lt;/p&gt;

&lt;p&gt;Feel free to comment or feedback or correct me if I am wrong somewhere by leaving a message below.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>html</category>
      <category>a11y</category>
    </item>
    <item>
      <title>An infinite/circular carousel with css flex and little JS</title>
      <dc:creator>technikhil314</dc:creator>
      <pubDate>Mon, 03 Aug 2020 15:43:27 +0000</pubDate>
      <link>https://dev.to/technikhil314/an-infinite-circular-with-css-flex-and-little-js-2a44</link>
      <guid>https://dev.to/technikhil314/an-infinite-circular-with-css-flex-and-little-js-2a44</guid>
      <description>&lt;p&gt;Lately I have been playing a lot with css (and finally yes I get to do what I love) I was actually thinking of several applications of flex order property. Last usecase I found helps to solve a small accessibility issue in signup/NDA forms head &lt;a href="https://dev.to/technikhil314/a-use-case-of-accessibility-solved-with-flex-46fh"&gt;here to see what it was&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;This one tries to create a bare minimum infinite/circular carousel with as less as 70 lines of code all included HTML,CSS,JS&lt;/p&gt;

&lt;h3&gt;
  
  
  What do I mean by circular/infinite carousel?
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Its a carousel that has n number of slides and it keeps scrolling to right side (for LTR languages) and (n+1)th chilid is again 1st child. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  So lets start
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;I will be using css flex, flex order, scroll-snap and little bit of plain JS to make our carousel autoscroll. &lt;/li&gt;
&lt;li&gt;This is going to be a bare minimum carousel&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Lets take a look at basic HTML and css for our carousel
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="carouselWrapper"&amp;gt;                
    &amp;lt;div class="carouselContainer"&amp;gt;
        &amp;lt;div class="carouselItem"&amp;gt;
            &amp;lt;img height="100px" width="100%" src="//via.placeholder.com/1000x100/FFFF00/000000/?text=Carousel+Item+21"
                alt="" /&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="carouselItem"&amp;gt;
            &amp;lt;img height="100px" width="100%" src="//via.placeholder.com/1000x100/FF0000/FFFFFF/?text=Carousel+Item+22"
                alt="" /&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="carouselItem"&amp;gt;
            &amp;lt;img height="100px" width="100%" src="//via.placeholder.com/1000x100/00FF00/000000?text=Carousel+Item+23"
                alt="" /&amp;gt;
        &amp;lt;/div&amp;gt;  
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and here is the css&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.carouselWrapper {
  position: relative;
}

.carouselContainer {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
}
.carouselContainer .carouselItem {
  flex-grow: 0;
  flex-shrink: 0;
  max-width: 100%;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check the codepen&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/nikhil-001mehta/embed/NWxEBVz?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can get rid of that horizontal scroll bar using following css and add scroll snap to it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.carouselContainer {
  display: flex;
  flex-wrap: nowrap;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  overflow-x: auto;
  scrollbar-width: 0;
  scrollbar-color: transparent transparent;
}
.carouselContainer::-webkit-scrollbar {
  display: none;
}
.carouselContainer .carouselItem {
    flex-grow: 0;
    flex-shrink: 0;
    max-width: 100%;
    // we are telling browser to align each item centrally to 
    // screen as it scrolls into viewport
    scroll-snap-align: center;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have added following property &lt;code&gt;scroll-snap-type: x mandatory;&lt;/code&gt; to &lt;code&gt;carouselContainer&lt;/code&gt; class&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;here We are telling browser to apply scroll snap on &lt;br&gt;
  horizontal axis and make it manadatory to scroll one item &lt;br&gt;
  fully to snap behaviour to kick in. &lt;br&gt;
  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-snap-type"&gt;check more details here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We are also adding &lt;code&gt;scroll-snap-align: center;&lt;/code&gt; property to &lt;code&gt;carouselItem&lt;/code&gt; class&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;we are telling browser to align each item centrally to &lt;br&gt;
screen as it scrolls into viewport&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/nikhil-001mehta/embed/gOrYRgx?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Now lets add little bit of javascript&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let index = 0;
const speed = 5;
const numberOfSlides = 3;
const carouselContainer = document.querySelector(".carouselContainer");
const carouselItemWidth = carouselContainer.scrollWidth / numberOfSlides;
setInterval(() =&amp;gt; {
  carouselContainer.scrollBy(carouselItemWidth, 0);
  timeoutId = setTimeout(() =&amp;gt; {
    index = index % numberOfSlides;
    let childToMove = carouselContainer.querySelectorAll(`.carouselItem`)[
      index
    ];
    // The line below move the item to end of carousel by 
    // manipulating its flex order
    childToMove.style.order =
      childToMove.style.order &amp;amp;&amp;amp; childToMove.style.order === 0
        ? 1
        : +childToMove.style.order + 1;
    index++;
    clearTimeout(timeoutId);
  }, 1000);
}, speed * 1000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And woohoo our carousel is running &lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/nikhil-001mehta/embed/ExKYXba?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Let me know your thoughts on this. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>carousel</category>
      <category>css</category>
      <category>flex</category>
    </item>
    <item>
      <title>A practical use case of web accessibility solved with CSS flexbox</title>
      <dc:creator>technikhil314</dc:creator>
      <pubDate>Sat, 27 Jun 2020 15:21:57 +0000</pubDate>
      <link>https://dev.to/technikhil314/a-use-case-of-accessibility-solved-with-flex-46fh</link>
      <guid>https://dev.to/technikhil314/a-use-case-of-accessibility-solved-with-flex-46fh</guid>
      <description>&lt;p&gt;Some time back I was working on a talk about accessibility. And I was working with my colleague &lt;a href="https://twitter.com/5wapneel"&gt;Swapneel&lt;/a&gt; at &lt;a href="https://twitter.com/thoughtworksIN"&gt;Thoughtworks&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;It was a simple use case that combines user experience and accessibilty (using form via keyboard)&lt;/p&gt;

&lt;h2&gt;
  
  
  Brief about the use case
&lt;/h2&gt;

&lt;p&gt;Many of us sign up/sign in at least once a week and I personally am habitual of filling in the HTML form just by using keyboard only. And almost every sign up prompts you for accepting their terms and condition. &lt;br&gt;
And in almost every case it looks like this&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/nikhil-001mehta/embed/RwrZyXz?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;So if you try to fill navigate and fill the form with just keyboard (using tab key to navigate between inputs/buttons/checkboxes)&lt;/p&gt;

&lt;p&gt;Following gif shows how the tabindex is working on each tab press.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2qq02BHT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xarwch61vqdtho2o3pwb.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2qq02BHT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xarwch61vqdtho2o3pwb.gif" alt="HTML form keyboard accessibility issue"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Do you see any problem in this tab indexing?&lt;/p&gt;

&lt;p&gt;will you accept TnC without reading it? (now dont say I do although Some times I too do it) logically/ideally one will accept Tnc only after reading it. That means the link for Terms and conditions should get focused before the checkbox.&lt;/p&gt;

&lt;p&gt;So this is a accessibility problem right?&lt;br&gt;
So how can we solve it now?&lt;/p&gt;
&lt;h2&gt;
  
  
  Possible solutions
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Move checkbox after the &lt;code&gt;I accept the terms and 
conditions&lt;/code&gt; text But then that breaks the reading flow
on LTR languages&lt;/li&gt;
&lt;li&gt;Add javascript to manage tabindex and focuses based on 
which input is focused right now some thing which I did 
&lt;a href="https://codepen.io/nikhil-001mehta/pen/PoZKaBW"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Is there a simple solution? Yes indeed &lt;a href="https://css-tricks.com/snippets/css/a-guide-to-flexbox/"&gt;flex&lt;/a&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/order"&gt;order&lt;/a&gt; 
property comes to our rescue. but How?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Lets look at HTML first&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;form class="row" action="https://www.example.com" method="POST"&amp;gt;
  &amp;lt;div class="col-12"&amp;gt;
    &amp;lt;div class="col-12 form-group"&amp;gt;
      &amp;lt;label for="exampleInputEmail1"&amp;gt;Email address&amp;lt;/label&amp;gt;
      &amp;lt;input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email"&amp;gt;
      &amp;lt;small id="emailHelp" class="form-text text-muted"&amp;gt;We'll never share your email with anyone else.&amp;lt;/small&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="col-12 form-group"&amp;gt;
      &amp;lt;label for="exampleInputPassword1"&amp;gt;Password&amp;lt;/label&amp;gt;
      &amp;lt;input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password"&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="col-12 form-group form-check tncWrapper"&amp;gt;
      &amp;lt;input type="checkbox" id="tncCheckBox" id="exampleCheck1"&amp;gt;
      &amp;lt;label class="form-check-label" for="exampleCheck1"&amp;gt;I accept the &amp;lt;a id="tncLink" href="https://www.example.com"&amp;gt;terms and conditions&amp;lt;/a&amp;gt;&amp;lt;/label&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="col-12"&amp;gt;
      &amp;lt;button type="submit" class="btn btn-primary"&amp;gt;Submit&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we will move the checkbox after the &lt;code&gt;I accept the terms and conditions&lt;/code&gt; text, add some css and ta dah!! the magic of flex begins.&lt;/p&gt;

&lt;p&gt;we will need to add some css in order to make keep the order of elements same on UI but different in code so the the only change we do in HTML is like below&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="col-12 form-group form-check tncWrapper"&amp;gt;
      &amp;lt;label class="form-check-label" for="exampleCheck1"&amp;gt;I accept the &amp;lt;a id="tncLink" href="https://www.example.com"&amp;gt;terms and conditions&amp;lt;/a&amp;gt;&amp;lt;/label&amp;gt;
      &amp;lt;input type="checkbox" id="tncCheckBox" id="exampleCheck1"&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;add following css&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.tncWrapper {
  display: flex;
}

#tncCheckBox {
  order: -1;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this we are asking the browser to render the checkbox before the &lt;code&gt;I accept the terms and conditions&lt;/code&gt; text. But in HTML the checkbox appears after the text. And since screenreader/keyboard respect HTML and not what is being displayed/rendered in viewport we are done?&lt;br&gt;
Check it out here&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--msiPBzcH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kg6qwt9rmcsqzydx1wls.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--msiPBzcH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kg6qwt9rmcsqzydx1wls.gif" alt="HTML form Keyboard accessibility with help of flex"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Try it here &lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/nikhil-001mehta/embed/abdyKxg?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  So how did it work?
&lt;/h2&gt;

&lt;p&gt;Since the all accessibility tools like screenreader/keyboard respect the HTML i.e DOM order and not the view port/render order, Focus first moves to the link and then to checkbox which is coded in HTML. But for users its shown as other way around just from experience point of view. &lt;/p&gt;

&lt;p&gt;Please comment down below if you have any suggestions/queries.&lt;/p&gt;

</description>
      <category>css</category>
      <category>a11y</category>
      <category>webdev</category>
      <category>ux</category>
    </item>
  </channel>
</rss>
