<?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: Anand Amrit Raj</title>
    <description>The latest articles on DEV Community by Anand Amrit Raj (@anamritraj).</description>
    <link>https://dev.to/anamritraj</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%2F86943%2F14e3e148-9ee4-422f-bb08-6ffae9c413e3.jpg</url>
      <title>DEV Community: Anand Amrit Raj</title>
      <link>https://dev.to/anamritraj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anamritraj"/>
    <language>en</language>
    <item>
      <title>Learning Vim in Quarantine - Part 2</title>
      <dc:creator>Anand Amrit Raj</dc:creator>
      <pubDate>Mon, 03 Aug 2020 19:03:15 +0000</pubDate>
      <link>https://dev.to/anamritraj/learning-vim-in-quarantine-part-2-3en7</link>
      <guid>https://dev.to/anamritraj/learning-vim-in-quarantine-part-2-3en7</guid>
      <description>&lt;p&gt;Starting to use Vim was probably one of the best decisions of my life. It made me realise, how much time and effort I have wasted moving my hand back and forth between keyboard and mouse. Don't get me wrong, mouse is a really useful device and I don't plan on getting rid of it. But when it comes to coding it's just more natural to use a keyboard.&lt;/p&gt;

&lt;p&gt;It took me some time to understand that Vim is actually making me efficient. Once you pass the whole "What keys I should press to get to that line?", "Why are there 3 modes!!", "I hate Vim so much!" and "Arrrgghhhhhh!!", believe me, after writing the first part, there was a time when I was frustrated with Vim so much that I did not use it for a whole week (&lt;em&gt;We were on a break, and I might have used VSCode&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;It made me realize the mistake I was making, I was trying to learn all of Vim at once. Like all of it! I wanted to be a master at Vim. It made me recall of a time from the Gym.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you want to bench 80 Kgs on your first day of the Gym, you are going to fail. Miserably.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Just like benching 80 Kgs, you don't learn all of the Vim on the first day. You cannot. You start with 10 Kgs, and gradually improve yourself to 80 Kilograms. (For those who are wondering, I still can't lift more than 50 Kgs 😅).&lt;/p&gt;

&lt;p&gt;Anyways, the point here is that if you want to learn Vim, start with the basic key movements. I know its really tempting to learn all the tricks and install all sorts of plugins to do the thing you want to do in 2 key-strokes, but that's not going to help in the long run. At least it did not help me. I realized that if I try to learn all 100+ combinations at once, I am not learning anything at all. You need to learn the basic movements first (start with 10 or so) and then gradually add more keys to your Vim arsenal. First, try to get it done using brute force.&lt;/p&gt;

&lt;h2&gt;
  
  
  Something which helped me
&lt;/h2&gt;

&lt;p&gt;In your early days, if you are going to directly use Vim in your projects where you need to do a lot of thinking (like you are figuring out an algorithm or debugging a nasty bug from last 3 days), I would recommend not use Vim use at all (at least during the first few weeks). It will only make you more frustrated. Initially, I only used Vim for writing documentations, and blog posts like these. There's not a lot of mode switching and you are more or less in your comfort zone.&lt;/p&gt;

&lt;p&gt;Also, I changed my Vim color theme to match my VSCode theme (which tricked my  little brain to think I was still in VSCode).&lt;/p&gt;

&lt;p&gt;If you want you can also install one of those VIM-mode plugins in your favourite editor and get started there. It personally felt a little weird to me, but I would recommend you to try.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with these keys
&lt;/h2&gt;

&lt;p&gt;To start with, I would recommend with these ~10 keys to help you understand the movement and basic editing. Spend a week or 2 focussing on just these keys until you feel comfortable with them.&lt;/p&gt;

&lt;p&gt;Also remember, this is going to be the hardest part of your Vim journey.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;j&lt;/code&gt; and &lt;code&gt;k&lt;/code&gt; to move up and down&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;h&lt;/code&gt; and &lt;code&gt;l&lt;/code&gt; to move left and right&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;w&lt;/code&gt; to move forward by a word&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;b&lt;/code&gt; to move backward by a word&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What should be your aim here? When can you say that you are good at using these keys?&lt;/p&gt;

&lt;p&gt;The point when you can say that you have mastered these keys would be when you don't have to think about what keys to press when you want to "move 5 words forward" or "go 4 lines down". It should naturally come to you without thinking. We can then say that you are ready for the next keys!&lt;/p&gt;

&lt;p&gt;These are a couple of keys to help you with the basic editing. You can learn them in parallel with the keys above.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;yy&lt;/code&gt; Yank (Copy) a line&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;p&lt;/code&gt; paste the line you just yanked, a line below your current line (It will paste whatever is in your &lt;em&gt;register&lt;/em&gt; (think of it as your clipboard))&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;dd&lt;/code&gt; delete the line that you just pasted (it will also move it to the &lt;em&gt;register&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;u&lt;/code&gt; will undo your last command&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These are some very basic commands (and easy to learn) but very powerful. Take some time to master these.&lt;/p&gt;

&lt;p&gt;Let's move to our final set of keys!&lt;/p&gt;

&lt;p&gt;Many a times you might need to delete a block of text all at once. You can do &lt;code&gt;dd dd dd dd&lt;/code&gt; to delete multiple lines (4 in this case), but you can also do this&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Press &lt;code&gt;Shift + v&lt;/code&gt; this will put you in "Visual Line mode" and now you can use the  &lt;code&gt;j&lt;/code&gt; and &lt;code&gt;k&lt;/code&gt; keys to start highlighting lines and then press &lt;code&gt;d&lt;/code&gt; to delete all the highlighted part at once!&lt;/li&gt;
&lt;li&gt;There's one more "Visual mode". If you just press &lt;code&gt;v&lt;/code&gt; it will put you in visual mode but only highlight your current character. From there you can perform your usual movements using &lt;code&gt;w&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt;, &lt;code&gt;h&lt;/code&gt;, &lt;code&gt;j&lt;/code&gt; , &lt;code&gt;k&lt;/code&gt; and &lt;code&gt;l&lt;/code&gt;  keys to highlight the parts you want to delete with &lt;code&gt;d&lt;/code&gt;.  (Or you can use &lt;code&gt;y&lt;/code&gt; to yank that part and paste somewhere else using &lt;code&gt;p&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mastering  &lt;code&gt;h&lt;/code&gt;, &lt;code&gt;j&lt;/code&gt; , &lt;code&gt;k&lt;/code&gt; and &lt;code&gt;l&lt;/code&gt;  is coming handy now 😉&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing text
&lt;/h2&gt;

&lt;p&gt;Now probably at sometime in your coding, you would want to write your own stuff and not just copy paste from other files (I hate when this happens).&lt;/p&gt;

&lt;p&gt;For those times we have the "Insert mode". Pressing &lt;code&gt;i&lt;/code&gt; would put you into the insert mode and you can then write all the text you want just like any regular text editor.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting out of the insert mode
&lt;/h2&gt;

&lt;p&gt;There are a couple of ways I found which take you out of the insert mode:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Escape key&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Ctrl + c&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Ctrl + [&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I am yet to understand why there are 3 ways, but I mostly use the Escape key and &lt;code&gt;Ctrl + c&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Check the mode you are in
&lt;/h2&gt;

&lt;p&gt;In the bottom left of your code window you should see an indicator about which mode you are in&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;INSERT&lt;/code&gt; for Insert Mode&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;VISUAL&lt;/code&gt; for Visual Mode&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;VISUAL-LINE&lt;/code&gt; for Visual line Mode&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;NORMAL&lt;/code&gt;  means you are in the default mode which I like to call movement mode&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Saving the file
&lt;/h2&gt;

&lt;p&gt;Now that you have made edits, you would want to save those changes. Use &lt;code&gt;:w&lt;/code&gt; to save the file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quitting Vim
&lt;/h2&gt;

&lt;p&gt;I will update this section when I learn how to quit Vim 😂&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kp5YLMtD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tnss9q8ov1argp5gvzd3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kp5YLMtD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tnss9q8ov1argp5gvzd3.jpg" alt="exit vim tweet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can use &lt;code&gt;:q&lt;/code&gt; to exit Vim when you are in the &lt;code&gt;NORMAL&lt;/code&gt; mode. This will fail if you have made changes to the file.&lt;/p&gt;

&lt;p&gt;If you have made edits and don't want to save the edits, use &lt;code&gt;:q!&lt;/code&gt; to quit without saving.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;I would recommend to spend around a week or two with just these commands till the point where you press these keys without thinking about them. (Just like you press &lt;code&gt;Cmd + c&lt;/code&gt; and &lt;code&gt;Cmd + v&lt;/code&gt; to copy and paste). Then once you are comfortable, incorporate a few more keys (or combinations) in your editing. Just keep them less than 4-5 keys/commands at a time.&lt;/p&gt;

&lt;p&gt;Here's a quick Vim cheatsheet if you need one. Its not pretty but gets the job done: &lt;a href="https://www.fprintf.net/vimCheatSheet.html"&gt;https://www.fprintf.net/vimCheatSheet.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will write part 3 of this series based on my personal experience once I am done with the current set of keys. Hope this is helpful!&lt;/p&gt;

</description>
      <category>vim</category>
      <category>beginners</category>
      <category>productivity</category>
      <category>tools</category>
    </item>
    <item>
      <title>Learning Vim in Quarantine - Part 1</title>
      <dc:creator>Anand Amrit Raj</dc:creator>
      <pubDate>Sat, 16 May 2020 07:58:08 +0000</pubDate>
      <link>https://dev.to/anamritraj/learning-vim-in-quarantine-part-1-2ofk</link>
      <guid>https://dev.to/anamritraj/learning-vim-in-quarantine-part-1-2ofk</guid>
      <description>&lt;p&gt;Wow, it has been a long time since I wrote anything on this blog. To be honest the last year was a bit too much. And surprisingly this year is no better.&lt;/p&gt;

&lt;p&gt;Anyways, just like everyone, I am using this quarantine to skill up and make good use of it. I am picking up things I always wanted to do and one of those things was learning Vim.&lt;br&gt;
I have seen a lot of tutorials with people using Vim which mostly confused me. Like why would you want to write in a command line tool. WITHOUT A MOUSE??? Are you kidding me. How are you even going to navigate around? That doesn't even make sense! &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is not a tutorial, rather my story of deciding to use Vim as my primary text editing tool. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Problems with IDEs
&lt;/h2&gt;

&lt;p&gt;Well, turns out, if you start spending 10+ hours writing code everyday, you realise that using a mouse is actually slower. Like really slow. Hear me out. If you use VSCode/Any other editor it has some basic issues which become annoying. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You constantly have to switch your right hand between the keyboard and mouse. That takes around 0.75 seconds for me (This includes the time to position my hand properly on the mouse, move the mouse around and 0.5s more when I switch back my hand to keyboard).&lt;/li&gt;
&lt;li&gt;You have to point your mouse to tiny icons on the screen, which at 4.30AM in the morning is just too much to ask of me.&lt;/li&gt;
&lt;li&gt;On a good day, loading up IntelliJ easily takes 10 seconds out of my life. And then starts the indexing process which takes forever!&lt;/li&gt;
&lt;li&gt;I spend a good amount of my time being SSHed into remote servers. Normally I would have at least 3 SSH sessions open into different servers. While it mostly involves checking logs, there are cases when I have to edit config files on remote servers and &lt;code&gt;nano&lt;/code&gt; is not present. But Vim is always on each one of the servers. So yeah it makes sense to invest time in Vim.&lt;/li&gt;
&lt;li&gt;Other editors are just not as cool as Vim. This is probably the biggest drawback. I like the minimal look of Vim(by default, even line numbers are not shown!)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  But why Vim?
&lt;/h2&gt;

&lt;p&gt;But what makes Vim so good that I want to learn it? Well I am still to experience the benefits myself as I have literally just started. But here are some good things I heard about it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is fast. It is always going to be faster than your normal IDEs since it has a lot less UI to process.&lt;/li&gt;
&lt;li&gt;It is highly customizable. There are plugins for almost anything you can think of. Anything you can do in any other IDE, you can do it in Vim too and probably faster. &lt;/li&gt;
&lt;li&gt;Since Vim is on almost all the servers, you can literally use the same Vim setup on any machine you SSH into by just downloading your &lt;code&gt;.vimrc&lt;/code&gt; file and BOOM! you feel right at home.&lt;/li&gt;
&lt;li&gt;You forget about your mouse. Since I started using it I have realised how fast I am without a mouse/trackpad. &lt;/li&gt;
&lt;li&gt;Also, if you are staring up with Vim, DO NOT USE THE ARROW KEYS. I read this in a lot of posts. Well it is true. Hear me out. Time to switch to your arrow keys is easily &lt;code&gt;0.25s&lt;/code&gt; and if you are not a touch typer (I am not) you are even slower when you come back to the home rows because you have to position your hands back to where they were. But if you use &lt;code&gt;h&lt;/code&gt;, &lt;code&gt;j&lt;/code&gt;, &lt;code&gt;k&lt;/code&gt; and &lt;code&gt;l&lt;/code&gt; to navigate around, it really becomes easy to just keep your hands at one place and enjoy typing!&lt;/li&gt;
&lt;li&gt;There are things called motions, tags and macros which make our life much easier. This is not a post about them since I am yet to use any of them, but yeah they are a big part of the Vim experience. Maybe we can talk about them in the next part.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  I am sold, let's start!
&lt;/h2&gt;

&lt;p&gt;Glad you are sold. Start by installing Vim (It should already be installed on most linux based OS) you can find tons of tutorials by just Googling &lt;code&gt;Install Vim on X operating system&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Okay, now that we have Vim installed, the first thing I did was complete the &lt;code&gt;vimtutor&lt;/code&gt; file. It is a text file which gives you an idea about using Vim by actually asking you to editing the file while you are reading it. Felt like an episode of Bandersnatch to me. It is okay if you have to read it more than one to get the hang of commands.&lt;/p&gt;

&lt;p&gt;Most of the commands are pretty intuitive, you want to quit? &lt;code&gt;:q&lt;/code&gt;, you want to save(write)? &lt;code&gt;:w&lt;/code&gt; Want to move a word forward? just press &lt;code&gt;w&lt;/code&gt;. &lt;code&gt;i&lt;/code&gt; puts you in insert mode. &lt;code&gt;ciw&lt;/code&gt; changes inside word, &lt;del&gt;&lt;code&gt;d&lt;/code&gt; deletes the character you are at&lt;/del&gt; (Thanks to Amin NAIRI in comments for pointing it out, &lt;code&gt;d&lt;/code&gt; actually waits for a motion before deleting anything. Like &lt;code&gt;diw&lt;/code&gt; for delete inner word, this will delete a word when your caret is on any letter of the word). You actually don't have to memorise the commands, after sometime, they just flow naturally, like you are speaking... in Vim's language.&lt;/p&gt;

&lt;p&gt;Okay, so one more thing. There is a thing called &lt;code&gt;.vimrc&lt;/code&gt; I talked about, that is the configuration file for Vim. Which means any modifications/plugins you add to &lt;code&gt;.vimrc&lt;/code&gt;configurations can and will be persisted across different Vim sessions. One benefit is that these can be persisted across different machines as well. Just push your &lt;code&gt;.vimrc&lt;/code&gt; file to Github/any server from where you can download later. On the new server just download your &lt;code&gt;.vimrc&lt;/code&gt; file, and you are in your familiar setup on the new machine as well, with all the syntax highlighting and all your plugins.&lt;/p&gt;

&lt;h2&gt;
  
  
  What all plugins to Install??
&lt;/h2&gt;

&lt;p&gt;There are a lot of Vim plugins and a lot more &lt;code&gt;.vimrc&lt;/code&gt; files available on the web. &lt;strong&gt;A quick search on Github returns around 19,519 repository results&lt;/strong&gt;. This is just mind-blowing and you will never be able to go through all those &lt;code&gt;.vimrc&lt;/code&gt; files. &lt;/p&gt;

&lt;p&gt;The approach I am taking on is to create my own &lt;code&gt;.vimrc&lt;/code&gt; file from scratch by adding plugins and settings on need basis rather than blindly copying/using someone else's &lt;code&gt;.vimrc&lt;/code&gt; file. I am still looking at other people's vimrc's and adding bits and pieces here and there but only after understanding what it does and is it actually adding any value to my flow.&lt;/p&gt;

&lt;p&gt;The ones I have added for now are &lt;a href="https://github.com/VundleVim/Vundle.vim"&gt;Vundler&lt;/a&gt;, &lt;a href="https://github.com/preservim/nerdtree"&gt;NerdTree&lt;/a&gt; and Enable Line Numbers! :D&lt;/p&gt;

&lt;p&gt;Anyways for those interested, I am adding my &lt;code&gt;.vimrc&lt;/code&gt; on Github hoping it would motivate someone to use Vim in 2020 and beyond (If we make it past 2020).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/anamritraj/vimrc"&gt;My super slim vim configuration&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vim</category>
      <category>beginners</category>
      <category>productivity</category>
      <category>tools</category>
    </item>
    <item>
      <title>Photos+:  A chrome extension to download photos from Google Photos in the best possible quality.</title>
      <dc:creator>Anand Amrit Raj</dc:creator>
      <pubDate>Tue, 30 Apr 2019 05:01:42 +0000</pubDate>
      <link>https://dev.to/anamritraj/photos-a-chrome-extension-to-download-photos-from-google-photos-in-the-best-possible-quality-4fgc</link>
      <guid>https://dev.to/anamritraj/photos-a-chrome-extension-to-download-photos-from-google-photos-in-the-best-possible-quality-4fgc</guid>
      <description>&lt;p&gt;If you are an Android user, chances are that you are using Google Photos to backup your photos. Google Photos is a great application and provides high quality unlimited free storage for your photos and has a lot of other neat features such as face recognition and great sharing options!&lt;/p&gt;

&lt;p&gt;Recently, I have been spending a lot of time in Google Photos remembering past memories with a friend. I tried downloading some of the photos and realized that the quality of the photos was not that great.&lt;/p&gt;

&lt;p&gt;I played around with the URL and changed some parameters to see if that changes the quality. To my surprise changing the parameters worked and I was able to download photos in much better quality than the default "Download" button provided.&lt;/p&gt;

&lt;p&gt;So I made a chrome extension which adds a new button on each photo which will download the photos from &lt;a href="https://photos.google.com" rel="noopener noreferrer"&gt;https://photos.google.com&lt;/a&gt; in the best quality possible!&lt;/p&gt;

&lt;p&gt;If you like it please consider dropping a ⭐. It would mean a lot to me!&lt;/p&gt;

&lt;p&gt;Needless to say, PRs and suggestions are most welcome. ❤️❤️&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/anamritraj" rel="noopener noreferrer"&gt;
        anamritraj
      &lt;/a&gt; / &lt;a href="https://github.com/anamritraj/google-photos-plus" rel="noopener noreferrer"&gt;
        google-photos-plus
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A chrome extension that allows you to download photos from Google Photos in better quality than the default download option.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Google Photos Plus &lt;a href="https://chrome.google.com/webstore/detail/photos+/iaiacmkllonoabnoaniipnieojefgblh?hl=en-GB&amp;amp;gl=IN" rel="nofollow noopener noreferrer"&gt;(Add to chrome)&lt;/a&gt;
&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;A chrome extension that allows you to download photos from &lt;a href="https://photos.google.com" rel="nofollow noopener noreferrer"&gt;Google Photos&lt;/a&gt; in better quality than the default download option.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Why this exists?&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;If you are an android user, chances are you are using Google Photos app to backup your photos to cloud. Google Photos is a great application and provides high qualtiy unlimited free storage for your photos
I was going through the web version (&lt;a href="https://photos.google.com" rel="nofollow noopener noreferrer"&gt;https://photos.google.com&lt;/a&gt;) and realized that even though they store our photos in slightly better quality, when you click download they don't serve the highest quality possible for a photo.&lt;/p&gt;
&lt;p&gt;This extension adds a new button on each photo which allows us to download the photo in best possible quality as shown below.&lt;/p&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/11889942/56460127-653c5e00-63bb-11e9-9cae-d8fa365f27f7.png"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fuser-images.githubusercontent.com%2F11889942%2F56460127-653c5e00-63bb-11e9-9cae-d8fa365f27f7.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;How to use?&lt;/h2&gt;

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Clone this repository or download as a zip file.&lt;/li&gt;
&lt;li&gt;If you download as a zip, unzip it.&lt;/li&gt;
&lt;li&gt;Open Google Chrome.&lt;/li&gt;
&lt;li&gt;Go to…&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/anamritraj/google-photos-plus" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


</description>
      <category>githunt</category>
      <category>showdev</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How #100DaysOfFitness changed me?</title>
      <dc:creator>Anand Amrit Raj</dc:creator>
      <pubDate>Tue, 26 Mar 2019 00:00:00 +0000</pubDate>
      <link>https://dev.to/anamritraj/how-100daysoffitness-changed-me-224o</link>
      <guid>https://dev.to/anamritraj/how-100daysoffitness-changed-me-224o</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Disclaimer: The person in the cover image is not me! &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I have successfully completed the #100DaysOfFitness challenge and it feels so great! It is a big deal for me since I suck at self-motivation when it comes to physical exercise. Making myself publically accountable for the workout was a great way to get me up from the chair and go to the gym.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Start
&lt;/h2&gt;

&lt;p&gt;It all started one day when after 2 months of gap I went to the gym again. You see, this was not the first time I tried to add exercise into my life. For the past 1 year, I was in an on-and-off relationship with the gym 😅. I always found excuses to skip the gym.&lt;/p&gt;

&lt;p&gt;Then, I read somewhere about the &lt;a href="http://100daysofx.com/" rel="noopener noreferrer"&gt;#100DaysOfX&lt;/a&gt; challenge. I thought let’s give it a try, this seems like a great way to challenge myself! And hence I started.&lt;/p&gt;

&lt;p&gt;I used Twitter to post my progress and hold myself accountable. I started on the 12th of November 2018. &lt;a href="https://twitter.com/anamritraj" rel="noopener noreferrer"&gt;You can follow the journey here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="/static/442a35c0836664c36886e40e5004c108/f9ad8/100days-day1-tweet.png"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fanamritraj.tech%2Fstatic%2F442a35c0836664c36886e40e5004c108%2Ffb8a0%2F100days-day1-tweet.png" alt="Day 1 tweet, 100DaysOfFitness"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Goal?
&lt;/h2&gt;

&lt;p&gt;My goal from this challenge was to make it a habit to workout for 30-45 mins/day, 5-6 times a week. The goal was not to lose weight or gain muscle (though I actively tracked it). Also, gaining some strength was a priority of me instead of just focussing on the cardio.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Plan?
&lt;/h2&gt;

&lt;p&gt;I chose to workout in evenings since I am not a morning person and it would be tough for me to get up early and go to the gym. I wanted this to be as smooth as possible. Also, for me, mornings are very calm and I would prefer to study or code rather than sweating in the gym.&lt;/p&gt;

&lt;p&gt;To track how many calories I was actually burning I got a Xiaomi fitness tracker (MI band 3). It did the job and counted calories almost accurately and worked pretty well for me. Also, it was cheap.&lt;/p&gt;

&lt;h3&gt;
  
  
  Removing the resistance
&lt;/h3&gt;

&lt;p&gt;I had a gym membership before (of six months, 😝). Guess how many days I went to the gym? Turns out, the process of getting into the gym clothes and then going to the gym, which was at around 15 mins walk from my apartment, was way too much to ask from me.&lt;/p&gt;

&lt;p&gt;To overcome this, I joined the gym in my society. There were no trainers and less equipment in this gym but I realized the trainers in the professional gym hardly had time for me after my 2 weeks in the gym. As for the equipment, they were enough for me. Once I am in my gym clothes, it took me less than a minute to get to the gym. So no more excuses!&lt;/p&gt;

&lt;h3&gt;
  
  
  Uhh Diet??
&lt;/h3&gt;

&lt;p&gt;Again, this was not a part of my goal. I made absolutely no changes to my diet, though later I realized that I am automatically eating less junk now because now I know the calories I would need to burn to compensate for that.&lt;/p&gt;

&lt;h3&gt;
  
  
  Routine
&lt;/h3&gt;

&lt;p&gt;I wake up at ~7.30 AM (on a good day), drink my coffee while checking my emails and going through the phone. After that first coffee of the day and a great sleep, I feel energized to do something productive. So I would spend the next two hours working on a side project or solve questions on Leetcode/Codechef (depends on the mood).&lt;/p&gt;

&lt;p&gt;At around 11 AM I would get up and get ready for work. I get to work by 11.45 AM and would stay there till 5.30 PM. After that, I come back to my apartment and change into my Gym clothes and enjoy some YouTube/ Netflix along with coffee.&lt;/p&gt;

&lt;p&gt;I would work out from 6 to 7 PM. More on the workout later. From 7.30 PM to 9 PM I usually have meetings which I attend from home. For me, 7 PM is too early to have dinner so I chug on a protein shake which keeps me full until dinner.&lt;/p&gt;

&lt;p&gt;After which I usually study/work on a side project/Netflix till 12 AM and then go to bed.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Workout
&lt;/h2&gt;

&lt;p&gt;I knew I had to make it fun otherwise I would not be able to make it till 100 Days! And also, I (used to) hate running or walking or &lt;em&gt;moving&lt;/em&gt; 😂. So choosing a workout plan which was fun was very important for me.&lt;/p&gt;

&lt;p&gt;I stuck to a simple workout with more focus on the compound movements such as Deadlifts and Bench Press. This was my day-wise routine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Monday- Chest and Triceps&lt;/li&gt;
&lt;li&gt;Tuesday- Back&lt;/li&gt;
&lt;li&gt;Wednesday- Cardio and Abs&lt;/li&gt;
&lt;li&gt;Thursday- Biceps&lt;/li&gt;
&lt;li&gt;Friday- Shoulders&lt;/li&gt;
&lt;li&gt;Saturday- Legs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I watched some YouTube videos to customize each day’s workout based on the equipment I had. Then just followed it for 100 Days without changing much. My main focus was to progressively overload the weights for each of the workouts. Also, I made sure I was using the correct form since there was no trainer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Results
&lt;/h2&gt;

&lt;p&gt;This challenge changed me! Not only physically but mentally as well.&lt;/p&gt;

&lt;p&gt;👉 Some of the direct effects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I can now do 25 Pushups in one set😅. I know that’s not much, but when I started this number was 3. I was weak.&lt;/li&gt;
&lt;li&gt;The same goes for almost every other exercise. I managed to get at least 5-6 times better in terms of weight or the reps.&lt;/li&gt;
&lt;li&gt;I lost around 500 grams(lol) of body fat and converted it to muscles. My overall weight thus remained constant. Again this is not much but I am happy that I did not have to make any major changes to my diet.&lt;/li&gt;
&lt;li&gt;I feel stronger now 💪.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Apart from these, there were some indirect effects.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I don’t feel sleepy all the time.&lt;/li&gt;
&lt;li&gt;After the workout, I expected myself to be tired and exhausted. But to my surprise, after the first week, after workout hours were my most productive hours! My concentration was on a whole another level.&lt;/li&gt;
&lt;li&gt;I was eating healthy even though I did not plan for it. When I calculated how much I have to run for that KitKat I ate yesterday, I immediately stopped eating stuff I knew I wouldn’t be able to burn. I am lazy and would try to avoid extra workout at all costs.&lt;/li&gt;
&lt;li&gt;I am more confident now.&lt;/li&gt;
&lt;li&gt;I enjoy the workout and no longer see it as a thing I have to do every day. It has become a part of my life and it feels great.&lt;/li&gt;
&lt;li&gt;I managed to get a &lt;a href="https://www.codechef.com/users/anamritraj" rel="noopener noreferrer"&gt;4 star rating on codechef&lt;/a&gt;. (My highest yet!)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  My advice to someone who just started?
&lt;/h2&gt;

&lt;p&gt;Just keep going. No matter what, just keep pushing. You might miss 2 days in a row or 3 days in a row. But make sure you workout as soon as you get a chance. Even if you don’t have a lot of time, just go to the gym and do it for 20 mins. Initially what’s important is that you are consistent and are making efforts to push yourself.&lt;/p&gt;

&lt;p&gt;Don’t bother about the diet and doing all the complex exercises. Start with the basics, make it a habit and then improve over time. If you are not making progress then don’t lose hope.&lt;/p&gt;

&lt;p&gt;I still feel like if I would have trained with a professional trainer at a gym and followed a strict diet I would have seen better results. But then I know its not practical for me to follow the diet or the workout for more than a month (I gave it a try once, didn’t end well).&lt;/p&gt;

&lt;p&gt;Just do what works for you. Can’t do it in the evenings? Wake up half an hour earlier and hit the gym. Don’t have time for it in the morning and evening? Go at midnight. Can’t find a gym nearby? Go for a run. Just start.&lt;/p&gt;

&lt;p&gt;Hope this was helpful. I don’t want to bore you with my body measurements 😅.&lt;/p&gt;

&lt;p&gt;Here’s a photo of me after the challenge. I got up from the chair and took this photo for this article so please ignore the hair and my messy room 😝.&lt;/p&gt;

&lt;p&gt;&lt;a href="/static/aba2ed67cd9550bc63a123ea009c2af7/3f0b4/anand-after-100days.jpg"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fanamritraj.tech%2Fstatic%2Faba2ed67cd9550bc63a123ea009c2af7%2Ff8fb9%2Fanand-after-100days.jpg" alt="Anand after 100 Days"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>habbit</category>
      <category>productivity</category>
      <category>fitness</category>
      <category>100daysofx</category>
    </item>
    <item>
      <title>Let's create ReactJS from scratch- Part 2</title>
      <dc:creator>Anand Amrit Raj</dc:creator>
      <pubDate>Wed, 23 Jan 2019 00:00:00 +0000</pubDate>
      <link>https://dev.to/anamritraj/lets-create-reactjs-from-scratch--part-2-1pf0</link>
      <guid>https://dev.to/anamritraj/lets-create-reactjs-from-scratch--part-2-1pf0</guid>
      <description>

&lt;h2&gt;
  
  
  Recap
&lt;/h2&gt;

&lt;p&gt;In this series of posts, we are creating major react functionalities from scratch. So far we have covered the &lt;code&gt;render&lt;/code&gt; function. You can read more about it here: &lt;a href="https://dev.to/anamritraj/lets-create-reactjs-from-scratch--part-1-35do"&gt;Let’s create ReactJS from scratch- Part 1&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introducing JSX
&lt;/h2&gt;

&lt;p&gt;Okay, so we got till this point where we have created our own &lt;code&gt;render&lt;/code&gt; function which takes &lt;em&gt;MyReact&lt;/em&gt; elements as arguments and renders them to DOM. While this is cool to render a link inside a div, if you have to render anything more than that, say navigation, it becomes annoying to write our HTML tags as javascript objects.&lt;/p&gt;

&lt;p&gt;Let’s see an example,&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'div'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;children&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="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'ul'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;children&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="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'li'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
              &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;children&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="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'TEXT_ELEMENT'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                      &lt;span class="na"&gt;nodeValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'I want to use JSX'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="p"&gt;},&lt;/span&gt;
                  &lt;span class="p"&gt;},&lt;/span&gt;
                &lt;span class="p"&gt;],&lt;/span&gt;
              &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'li'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
              &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;children&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="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'TEXT_ELEMENT'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                      &lt;span class="na"&gt;nodeValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Its only second li and I'm annoyed!"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="p"&gt;},&lt;/span&gt;
                  &lt;span class="p"&gt;},&lt;/span&gt;
                &lt;span class="p"&gt;],&lt;/span&gt;
              &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="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;p&gt;The above lines will render this&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;I want to use JSX&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Its only second li and I'm annoyed!&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Introducing JSX&lt;/strong&gt;! JSX is just syntactic sugar. Using a JSX transpiler you can convert your HTML looking syntax into elements which can be understood by javascript and rendered correctly by the browser.&lt;/p&gt;

&lt;p&gt;As a JSX transpiler, you can use &lt;a href="https://github.com/babel/babel/"&gt;Babel&lt;/a&gt;. It has a great open-source community and easy to use CLI tool.&lt;/p&gt;

&lt;p&gt;If you are working with React you are most probably using it. But JSX is not actually tied to react it can be used without react and is not very tough to understand and use.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you want to learn more about JSX check out &lt;a href="https://jasonformat.com/wtf-is-jsx/"&gt;this article&lt;/a&gt;, &lt;a href="http://facebook.github.io/jsx/"&gt;Draft: JSX Specification&lt;/a&gt; and also &lt;a href="https://reactjs.org/docs/jsx-in-depth.html"&gt;JSX In Depth&lt;/a&gt; react documentation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So in case of the above example, you can write something like below,&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="cm"&gt;/** @jsx createElement */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;ul&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;I want to use JSX&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Its only second li and I'm annoyed!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;ul&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you are familiar with javascript you would be guessing if the above is a valid javascript: &lt;em&gt;its not&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The first line is a comment which babel understands, the name &lt;code&gt;createElement&lt;/code&gt; is the name of the function which babel is going to call for each tag it encounters. It is known as &lt;em&gt;pragma&lt;/em&gt; in &lt;a href="https://babeljs.io/docs/en/babel-plugin-transform-react-jsx#pragma"&gt;babel configuration&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Babel will transpile the JSX code into a bunch of function calls like this&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;someJsx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="s2"&gt;"div"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"class"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"nav"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s2"&gt;"ul"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"class"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"nav-links"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="s2"&gt;"li"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"Home"&lt;/span&gt;
    &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="s2"&gt;"li"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"Profile"&lt;/span&gt;
    &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="s2"&gt;"li"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"Logout"&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;p&gt;So all we need to do now is implement &lt;code&gt;createElement&lt;/code&gt; function. The first argument of the function is &lt;code&gt;type&lt;/code&gt; of the element. The second element is &lt;code&gt;props&lt;/code&gt; and the following elements are children. If you remember our implementation of the &lt;code&gt;render&lt;/code&gt; function from &lt;a href="https://dev.to/anamritraj/lets-create-reactjs-from-scratch--part-1-35do"&gt;here&lt;/a&gt;, you will remember that the render function takes the element in the form,&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'div'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;props&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="na"&gt;children&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;p&gt;So what we need to do in &lt;code&gt;createElement&lt;/code&gt; function is to move the third argument which contains the &lt;code&gt;children&lt;/code&gt; under the &lt;code&gt;props&lt;/code&gt; and return the resulting object which can be consumed by our &lt;code&gt;MyReact.render&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;If I am not making sense there, let’s create the &lt;code&gt;createElement&lt;/code&gt; function and let the code do the talking. Its similar to the &lt;code&gt;React.createElement&lt;/code&gt; function. Check out &lt;a href="https://reactjs.org/docs/jsx-in-depth.html"&gt;this page&lt;/a&gt; to learn more.&lt;/p&gt;

&lt;h2&gt;
  
  
  The createElement function
&lt;/h2&gt;

&lt;p&gt;I would just put it out there and explain the code.&lt;/p&gt;



&lt;div class="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;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;,&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;assign&lt;/span&gt;&lt;span class="p"&gt;({},&lt;/span&gt; &lt;span class="nx"&gt;config&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;hasChildren&lt;/span&gt; &lt;span class="o"&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;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

  &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;hasChildren&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;[].&lt;/span&gt;&lt;span class="nx"&gt;concat&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="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;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The three arguments are provided to the function by the transpiler (which is babel in our case). The third argument will contain all of the children of the current node. We are simply assigning the props to the &lt;code&gt;props&lt;/code&gt; object, children to &lt;code&gt;props.children&lt;/code&gt; object. Then return the object, this is something our &lt;code&gt;MyReact.render&lt;/code&gt; function can work with!&lt;/p&gt;

&lt;p&gt;Well, that was pretty simple. But our render function &lt;code&gt;MyReact.render&lt;/code&gt; expects the text elements to have a type of &lt;code&gt;TEXT_ELEMENT&lt;/code&gt; and also a &lt;code&gt;nodeValue&lt;/code&gt; prop. So let’s do that!&lt;/p&gt;



&lt;div class="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;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;,&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;assign&lt;/span&gt;&lt;span class="p"&gt;({},&lt;/span&gt; &lt;span class="nx"&gt;config&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;hasChildren&lt;/span&gt; &lt;span class="o"&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;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;allChildren&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;hasChildren&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;[].&lt;/span&gt;&lt;span class="nx"&gt;concat&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="p"&gt;[]&lt;/span&gt;
  &lt;span class="c1"&gt;// Filter all the children which are null,&lt;/span&gt;
  &lt;span class="c1"&gt;// we don't need to render them&lt;/span&gt;
  &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;allChildren&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;child&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;child&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;child&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="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;child&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;child&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;child&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;createTextElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;child&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
  &lt;span class="c1"&gt;// For text nodes, child above is a string&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;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// This function handles the creation of text nodes&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;createTextElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="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="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'TEXT_ELEMENT'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;nodeValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now our &lt;code&gt;createElement&lt;/code&gt; function is complete and ready to use. A couple of things before you try to use this to create a web app. Since we are using JSX which is not a part of standard javascript, we need to transpile this code before we can use this. I am going to use Babel for transpiling the code into something which the browser can understand.&lt;/p&gt;

&lt;p&gt;You can check out this &lt;a href="https://babeljs.io/repl#?babili=false&amp;amp;browsers=&amp;amp;build=&amp;amp;builtIns=false&amp;amp;spec=false&amp;amp;loose=false&amp;amp;code_lz=PQKhAIAECsGcA9wFkCeAlApgQwMYBcA6HAJ2zwwFEAbDAWwwDs9wRgAoHAewdmdU1zMAvOADmGPP2z4AFAEoA3B269wAFQoANNQH0KAGQpIKAOTXgRAIg3a9h42ctLlPZrRTU6jYeBltw4AA8ACYAlgBuAHz-AUEArlTRsbGBVKGRAJK0AA409EzgAvjgpAzBGMSBwGlJyUE1WbleBUXMXDnc3lU1Mcmp6Y153oXSzABmoQBGFd3pvSk1mLm4GOCcxKGioQxYVCOCs7V9NQDC3ACOcRXgeAAWqwDu61TBAISH81UJtVVhUWyKNhsKSCAilcrEGTuTz5PAAGnAwU4ODisII4jwMO8ACEUBlgjJLO4ALSkQTErDZbKWOSAthjOIMfChbhiCQg2RycAAbxiDKZeBZDBKjAhMgwQyYCOyWFKeC5vOSwGA4AA4hIbvdwNliJxsrBwFgyjcUNlVmNdbRwBLmsxOJNoBh8PMuK4eSazdLdfrwABfCzWyV4ZxKlUne44ADW4FCYxjzFCBqwNww8GYNthLpUCdgalTmKDAbwptWQjL4GsWl0BiMpjUTiBofAJzJ5EN4AYGAeiM4Voz3izbqRVpEr0TebTWKY8wCAH4eyi0SQyJQgzJi2a5DPwAAuBeo7xEVsYCd4EyccoyHV62AEBgXjAANV2VzpTYAYqEqORiOAxutrXCbx9ETchO2IA1tk1VZr31QdVETEDeEYa4RB2egLEiDssHoAheFlPBYAAdVCO5CW4GkQ1iZVwAAQWCYJAOA0CUIgm5OGgns-yDeYAHkHSdQhIwwFBYCvb1YC3OpwAICZvwqGREJY8CpLqWT1goXBbhkdDSywxVpPAV1VAwICmDUEsA10gg8E4fROAeCoTiwWAMHkPC4kmXgNgYUQZAAJkBQyuIILAGIoMy8CQsCFNM7wLM9bUJIAbV0gBdIK6l9N9YmMnNaLwPANkmOI2zQnC9PAMdYAKoqplK1YADJGuwjDXnLSwcFuL9glKBs-IE_ACGE0TxJvVTklkr8f0UmrCuKhqJtidTiE0rqdIqzCeW3AJh1Siq0oDWDYH2-g0qUaTsqogIaPDJ1o1jaDSENZ6jRQIzupeUoDU4OM7lWLYzMDW14LaT7ginQijokohwdKcAAB8EfAZLzsbaiVXBa47k4VyPp676RRRCCIgld6JggvAXXByHb3_VatPFPYhCwrHIQlBFh1pa7wBoiYdioKh3spM1jX-4HYXYziZTlCWB2SGXDxF0Vwx6mQuYuv10f5ZlWWXLByEh9cSwRV0JlEBECCt2VREk7bkjypKbwDfjHSGlzYE2BgZG5X1Te4c3MoCR3bhc1WvsYAMbdvGhfLucAsIABh5x3diocPesjkRQ9gDP4fnVGiG4HADZkK3QuIW2uT3VGeeO2GCazw1Bbzxhtym-TIS6nqtu7l4qvLBgEj2Zr8f79qRDGXZXKWgICFoSkZD7xiWZ2sfGO2fCmQwX7wFdwTwHnZfdyM49TyN5fZ_AHKAlIPA4mIYVuQ9DAvWd31Nd9bXGV14V9fIc-a5wgvgwAqeYd8H5P23BuDAe4bDVnsHWOE25jp7gMtJe85RnxUCuHuYBOCMDbi_skD-MRiEinvo_e2sQ2bIIdseSGZClBfyAA&amp;amp;debug=false&amp;amp;forceAllTransforms=false&amp;amp;shippedProposals=false&amp;amp;circleciRepo=&amp;amp;evaluate=false&amp;amp;fileSize=false&amp;amp;timeTravel=false&amp;amp;sourceType=module&amp;amp;lineWrap=true&amp;amp;presets=react&amp;amp;prettier=false&amp;amp;targets=&amp;amp;version=6.26.0&amp;amp;envVersion=1.6.2"&gt;REPL&lt;/a&gt; to see how babel converts the code into a bunch of &lt;code&gt;createElement&lt;/code&gt; calls.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you just want to see how this is used in a real-world application, I made a &lt;a href="https://codepen.io/anamritraj/pen/gZVKBy"&gt;&lt;strong&gt;codepen demo&lt;/strong&gt;&lt;/a&gt; to show the usage.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Making it work in the browser
&lt;/h2&gt;

&lt;p&gt;The above codepen demo works since we are using babel as a preprocessor and it includes a bunch of plugins with it. If you want to make it work in your local machine you would have to include a couple of packages to transpile your JSX into &lt;code&gt;createElement&lt;/code&gt; function calls.&lt;/p&gt;

&lt;p&gt;We’ll start of by adding a bunch of npm packages,&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i --save-dev @babel/cli @babel/core @babel/plugin-syntax-jsx @babel/plugin-transform-react-jsx @babel/preset-env
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@babel/core&lt;/code&gt; is the core babel package&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@babel/cli&lt;/code&gt; allows us to use babel as a CLI tool&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@babel/plugin-syntax-jsx&lt;/code&gt; helps babel to understand the JSX syntax as babel does not support it out of the box&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@babel/plugin-transform-react-jsx&lt;/code&gt; this is the main package which transpiles JSX into function calls. By default, this uses React.createElement as the pragma function. You can read more about it &lt;a href="https://babeljs.io/docs/en/babel-plugin-transform-react-jsx#pragma"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@babel/preset-env&lt;/code&gt; is responsible for allowing us to use the latest JavaScript without needing to micromanage syntax transforms (and optionally, browser polyfills) that are needed by the browser. This is just a collection of plugins.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now one final thing we need to do is add a &lt;code&gt;.babelrc&lt;/code&gt; file which is just to tell babel which presets and plugins (which we installed above) to use. Let’s define one.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "presets": ["@babel/preset-env"],
  "plugins": ["@babel/plugin-syntax-jsx", "@babel/plugin-transform-react-jsx"]
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We are almost done, now all we need to do is run the babel-cli to compile our file containing JSX code into a which the browser can understand.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;babel ./src/main.js -o ./dist/bundle.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;code&gt;-o&lt;/code&gt; flag tells babel to output the file as a specified name in a folder.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code &amp;amp; Demo
&lt;/h2&gt;

&lt;p&gt;The entire code for this is available on &lt;a href="https://github.com/anamritraj/my-react"&gt;Github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can check out this &lt;a href="https://babeljs.io/repl#?babili=false&amp;amp;browsers=&amp;amp;build=&amp;amp;builtIns=false&amp;amp;spec=false&amp;amp;loose=false&amp;amp;code_lz=PQKhAIAECsGcA9wFkCeAlApgQwMYBcA6HAJ2zwwFEAbDAWwwDs9wRgAoHAewdmdU1zMAvOADmGPP2z4AFAEoA3B269wAFQoANNQH0KAGQpIKAOTXgRAIg3a9h42ctLlPZrRTU6jYeBltw4AA8ACYAlgBuAHz-AUEArlTRsbGBVKGRAJK0AA409EzgAvjgpAzBGMSBwGlJyUE1WbleBUXMXDnc3lU1Mcmp6Y153oXSzABmoQBGFd3pvSk1mLm4GOCcxKGioQxYVCOCs7V9NQDC3ACOcRXgeAAWqwDu61TBAISH81UJtVVhUWyKNhsKSCAilcrEGTuTz5PAAGnAwU4ODisII4jwMO8ACEUBlgjJLO4ALSkQTErDZbKWOSAthjOIMfChbhiCQg2RycAAbxiDKZeBZDBKjAhMgwQyYCOyWFKeC5vOSwGA4AA4hIbvdwNliJxsrBwFgyjcUNlVmNdbRwBLmsxOJNoBh8PMuK4eSazdLdfrwABfCzWyV4ZxKlUne44ADW4FCYxjzFCBqwNww8GYNthLpUCdgalTmKDAbwptWQjL4GsWl0BiMpjUTiBofAJzJ5EN4AYGAeiM4Voz3izbqRVpEr0TebTWKY8wCAH4eyi0SQyJQgzJi2a5DPwAAuBeo7xEVsYCd4EyccoyHV62AEBgXjAANV2VzpTYAYqEqORiOAxutrXCbx9ETchO2IA1tk1VZr31QdVETEDeEYa4RB2egLEiDssHoAheFlPBYAAdVCO5CW4GkQ1iZVwAAQWCYJAOA0CUIgm5OGgns-yDeYAHkHSdQhIwwFBYCvb1YC3OpwAICZvwqGREJY8CpLqWT1goXBbhkdDSywxVpPAV1VAwICmDUEsA10gg8E4fROAeCoTiwWAMHkPC4kmXgNgYUQZAAJkBQyuIILAGIoMy8CQsCFNM7wLM9bUJIAbV0gBdIK6l9N9YmMnNaLwPANkmOI2zQnC9PAMdYAKoqplK1YADJGuwjDXnLSwcFuL9glKBs-IE_ACGE0TxJvVTklkr8f0UmrCuKhqJtidTiE0rqdIqzCeW3AJh1Siq0oDWDYH2-g0qUaTsqogIaPDJ1o1jaDSENZ6jRQIzupeUoDU4OM7lWLYzMDW14LaT7ginQijokohwdKcAAB8EfAZLzsbaiVXBa47k4VyPp676RRRCCIgld6JggvAXXByHb3_VatPFPYhCwrHIQlBFh1pa7wBoiYdioKh3spM1jX-4HYXYziZTlCWB2SGXDxF0Vwx6mQuYuv10f5ZlWWXLByEh9cSwRV0JlEBECCt2VREk7bkjypKbwDfjHSGlzYE2BgZG5X1Te4c3MoCR3bhc1WvsYAMbdvGhfLucAsIABh5x3diocPesjkRQ9gDP4fnVGiG4HADZkK3QuIW2uT3VGeeO2GCazw1Bbzxhtym-TIS6nqtu7l4qvLBgEj2Zr8f79qRDGXZXKWgICFoSkZD7xiWZ2sfGO2fCmQwX7wFdwTwHnZfdyM49TyN5fZ_AHKAlIPA4mIYVuQ9DAvWd31Nd9bXGV14V9fIc-a5wgvgwAqeYd8H5P23BuDAe4bDVnsHWOE25jp7gMtJe85RnxUCuHuYBOCMDbi_skD-MRiEinvo_e2sQ2bIIdseSGZClBfyAA&amp;amp;debug=false&amp;amp;forceAllTransforms=false&amp;amp;shippedProposals=false&amp;amp;circleciRepo=&amp;amp;evaluate=false&amp;amp;fileSize=false&amp;amp;timeTravel=false&amp;amp;sourceType=module&amp;amp;lineWrap=true&amp;amp;presets=react&amp;amp;prettier=false&amp;amp;targets=&amp;amp;version=6.26.0&amp;amp;envVersion=1.6.2"&gt;REPL&lt;/a&gt; to see how babel converts the code into a bunch of &lt;code&gt;MyReact.createElement&lt;/code&gt; calls.&lt;/p&gt;

&lt;p&gt;I also made a &lt;a href="https://codepen.io/anamritraj/pen/gZVKBy"&gt;&lt;strong&gt;codepen demo&lt;/strong&gt;&lt;/a&gt; to demonstrate how you would use this in a real-world application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Endnotes
&lt;/h2&gt;

&lt;p&gt;This is the second post in the series where we are creating a clone of ReactJs! As always, the entire code for this is available on &lt;a href="https://github.com/anamritraj/my-react"&gt;Github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you see any errors then please let me know! I am also human and don’t know everything. Thanks for reading! :)&lt;/p&gt;

&lt;p&gt;I would love to know what features would you want me to implement next. Though I have only started, I plan to make this as close to original React as possible. It may never be production ready but I will learn a lot.&lt;/p&gt;

&lt;p&gt;See you next time!&lt;/p&gt;


</description>
      <category>react</category>
      <category>javascript</category>
      <category>reverseengineering</category>
    </item>
    <item>
      <title>Let's create ReactJS from scratch- Part 1</title>
      <dc:creator>Anand Amrit Raj</dc:creator>
      <pubDate>Fri, 18 Jan 2019 00:00:00 +0000</pubDate>
      <link>https://dev.to/anamritraj/lets-create-reactjs-from-scratch--part-1-35do</link>
      <guid>https://dev.to/anamritraj/lets-create-reactjs-from-scratch--part-1-35do</guid>
      <description>

&lt;p&gt;Being a React fanboy, I have always wondered how it is so performant even in heavy data-driven applications. Also, I have always wanted to contribute to ReactJS on GitHub but somehow, I feel that the repository can be overwhelming for someone who has never contributed to open-source apart from creating issues.&lt;/p&gt;

&lt;p&gt;Right now I am brushing up my Data Structures and Algorithmic skills and was thinking where to apply what I have learnt. Implementing your own linked lists and hashmaps is cool but what next? This is when I thought to create my own version of ReactJS.&lt;/p&gt;

&lt;p&gt;This would help me with a couple of things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Understand how React works internally.&lt;/li&gt;
&lt;li&gt;Apply my little knowledge of data structures to re-create something which I currently use as a black box.&lt;/li&gt;
&lt;li&gt;Make me a better Javascript developer.&lt;/li&gt;
&lt;li&gt;Helping me in contributing to the original ReactJS library.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s also list out the features which I am planning to add to &lt;em&gt;MyReact&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Render DOM elements&lt;/li&gt;
&lt;li&gt;Possibly explore JSX and use it to render DOM elements.&lt;/li&gt;
&lt;li&gt;Custom Class components and state&lt;/li&gt;
&lt;li&gt;And the MVP virtual DOM!&lt;/li&gt;
&lt;li&gt;Also, I want to understand the Fiber Architecture and re-create it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So let’s get started, first of all, we need a name. I am really not good at naming things. So I named it &lt;em&gt;MyReact&lt;/em&gt;. Pretty innovative eh?&lt;/p&gt;

&lt;p&gt;Okay now, let’s really start. So our aim is to create a basic version of ReactJs first without worrying about performance, debuggability, portability etc. Although, we are going to improve it over time and &lt;em&gt;soon replace the original ReactJS with MyReact.&lt;/em&gt; *laughs like a villain*&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can find more information about the &lt;a href="https://reactjs.org/docs/codebase-overview.html"&gt;implementation details&lt;/a&gt; or enjoy &lt;a href="https://www.youtube.com/watch?v=_MAD4Oly9yg"&gt;this talk&lt;/a&gt; by Paul O’Shannessy.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let’s start by creating the &lt;code&gt;render()&lt;/code&gt; function which is responsible for creating the DOM elements. You don’t need to be a pro with javascript to understand the &lt;code&gt;document.createElement()&lt;/code&gt; function but for the sake of this tutorial, let’s revisit the basic DOM API available in the browser&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Get an element by its id,&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;parent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementByID&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'app-root'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Now create a new element of a given tag&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;child&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'h1'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Add properties to the DOM element&lt;/span&gt;
&lt;span class="nx"&gt;child&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'bold'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'fancy-color'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;child&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Hello World!'&lt;/span&gt;

&lt;span class="c1"&gt;// Now append that element to the parent&lt;/span&gt;
&lt;span class="nx"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;child&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So far we haven’t defined anything new, all the operations above are supported in all browsers without any libraries.&lt;/p&gt;

&lt;p&gt;As you can see in order to render tags on a webpage we are going to use the &lt;code&gt;document.createElement()&lt;/code&gt;. That will take care of rendering tags on a page. Also, we can modify the properties and make it look like whatever we want using classes and custom inline CSS.&lt;/p&gt;

&lt;p&gt;Now that we have a way to render tags on the webpage, let’s go a step back and define what an element may look like in MyReact.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// If we want to represent a DOM element as an object,&lt;/span&gt;
&lt;span class="c1"&gt;// following would be its properties&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'div'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// properties of the element&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'body'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;// children can again contain elements,&lt;/span&gt;
    &lt;span class="c1"&gt;// which are going to have the same structure&lt;/span&gt;
    &lt;span class="na"&gt;children&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="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'p'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;nodeValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'If you want to know more '&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="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'a'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'/home'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;nodeValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Click here'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Nothing fancy here, just a javascript object which represents the following structure in MyReact. Let’s call them MyReact Elements from now on.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"body"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;If you want to know more&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/home"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Click here&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;MyReact elements are &lt;strong&gt;not&lt;/strong&gt; really different from &lt;a href="https://reactjs.org/blog/2014/10/14/introducing-react-elements.html"&gt;React Elements&lt;/a&gt;. You usually don’t use javascript objects to define and create elements in React and probably use JSX. We are going to do the same in future posts. For now, we are going to use the above javascript object to define and render MyReact elements as DOM elements.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Render function
&lt;/h2&gt;

&lt;p&gt;We have MyReact elements, let’s implement the &lt;code&gt;MyReact.render&lt;/code&gt; function which is equivalent to &lt;a href="https://facebook.github.io/react/docs/react-dom.html#render"&gt;ReactDOM.render&lt;/a&gt;. This function will create the DOM element defined by the javascript object and append it’s to its parent.&lt;/p&gt;



&lt;div class="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;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Get the props and type from element object&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;

  &lt;span class="c1"&gt;// Check if there are any childrens of the given element&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;childElements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

  &lt;span class="c1"&gt;// render those childrens recursively first&lt;/span&gt;
  &lt;span class="nx"&gt;childElements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dom&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

  &lt;span class="c1"&gt;// finally append the element to the parent element&lt;/span&gt;
  &lt;span class="nx"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dom&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is the most basic version of the &lt;code&gt;render&lt;/code&gt; function you’ll ever see. All this is doing is creating a DOM element and recursively adding all its children to the parent. This is still missing all the attributes and the eventListeners.&lt;/p&gt;

&lt;p&gt;Let’s iterate over the &lt;code&gt;props&lt;/code&gt; keys using &lt;code&gt;Object.keys&lt;/code&gt; to get eventListeners &amp;amp; attributes and set them properly.&lt;/p&gt;



&lt;div class="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;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Get the props and type from element object&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;

  &lt;span class="c1"&gt;// Filter for eventListeners in the props&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isListener&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'on'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;// Add eventListeners to the dom element&lt;/span&gt;
  &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;eventType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;substring&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="nx"&gt;dom&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;eventType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isAttribute&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isAttribute&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;'children'&lt;/span&gt;

  &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isAttribute&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&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;dom&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;

  &lt;span class="c1"&gt;// Check if there are any childrens of the given element&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;childElements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

  &lt;span class="c1"&gt;// render those childrens recursively first&lt;/span&gt;
  &lt;span class="nx"&gt;childElements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dom&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

  &lt;span class="c1"&gt;// finally append the element to the parent element&lt;/span&gt;
  &lt;span class="nx"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dom&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;
  
  
  Render DOM Text Nodes
&lt;/h2&gt;

&lt;p&gt;Now, this looks like a pretty complete &lt;code&gt;render&lt;/code&gt; function. Except for one thing. The pure Text Nodes. Let’s define how a text element will look like as a javascript object.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;textElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;span&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;children&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="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'TEXT_NODE'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;nodeValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Hello World!'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above definition would define something like this when passed through our &lt;code&gt;render&lt;/code&gt; function&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;span&amp;gt;&lt;/span&gt; Hello World! &lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Notice how we defined a new type &lt;code&gt;TEXT_ELEMENT&lt;/code&gt; which we will use in our render function. Let’s see how we use that. Instead of using &lt;code&gt;createElement&lt;/code&gt; we are going to use &lt;code&gt;createTextNode&lt;/code&gt; function. The &lt;code&gt;nodeValue&lt;/code&gt; property will be set in the same way as before and we don’t need to pass it explicitly in the &lt;code&gt;createTextNode&lt;/code&gt; function.&lt;/p&gt;



&lt;div class="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;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Get the props and type from element object&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;

  &lt;span class="c1"&gt;// Check if it is a text element&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isTextElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'TEXT_ELEMENT'&lt;/span&gt;

  &lt;span class="c1"&gt;// Create a new dom element or TextNode based on the type&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dom&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isTextElement&lt;/span&gt;
    &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createTextNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;// Filter for eventListeners in the props&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isListener&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'on'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;// Add eventListeners to the dom element&lt;/span&gt;
  &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;eventType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;substring&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="nx"&gt;dom&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;eventType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isAttribute&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isAttribute&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;'children'&lt;/span&gt;

  &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isAttribute&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&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;dom&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;

  &lt;span class="c1"&gt;// Check if there are any childrens of the given element&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;childElements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

  &lt;span class="c1"&gt;// render those childrens recursively first&lt;/span&gt;
  &lt;span class="nx"&gt;childElements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dom&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

  &lt;span class="c1"&gt;// finally append the element to the parent element&lt;/span&gt;
  &lt;span class="nx"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dom&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The entire code for this is available on &lt;a href="https://github.com/anamritraj/my-react/blob/master/src/render.js"&gt;Github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I made a &lt;a href="https://codepen.io/anamritraj/pen/aPgOPj"&gt;&lt;strong&gt;codepen demo&lt;/strong&gt;&lt;/a&gt; to demonstrate how you would use this in a real world application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Endnotes
&lt;/h2&gt;

&lt;p&gt;This was really fun! The entire code for this is available on &lt;a href="https://github.com/anamritraj/my-react"&gt;Github&lt;/a&gt;. This will be a series of posts where I will incrementally add features and post about my findings.&lt;/p&gt;

&lt;p&gt;I would love to know what features would you want me to implement next. Though I have only started, I plan to make this as close to original React as possible. It might never be production ready but I will learn a lot.&lt;/p&gt;

&lt;p&gt;See you next time!&lt;/p&gt;




&lt;p&gt;Update &lt;a href="https://dev.to/anamritraj/lets-create-reactjs-from-scratch--part-2-1pf0"&gt;here's the part 2&lt;/a&gt;!&lt;/p&gt;


</description>
      <category>react</category>
      <category>reverseengineering</category>
      <category>javascript</category>
      <category>learning</category>
    </item>
    <item>
      <title>How to create a mobile-first super-fast Gatsby.js blog</title>
      <dc:creator>Anand Amrit Raj</dc:creator>
      <pubDate>Wed, 26 Dec 2018 16:32:21 +0000</pubDate>
      <link>https://dev.to/anamritraj/how-to-create-a-mobile-first-super-fast-gatsbyjs-blog-4dnm</link>
      <guid>https://dev.to/anamritraj/how-to-create-a-mobile-first-super-fast-gatsbyjs-blog-4dnm</guid>
      <description>&lt;p&gt;Recently I created this amazing, super fast, mobile-first, super-responsive website for myself and I was amazed by its performance. It took me some time to get it right but the process was not that tough and once I completed it I thought I would document it so others can benefit.&lt;/p&gt;

&lt;p&gt;My Blog: &lt;a href="https://anamritraj.tech" rel="noopener noreferrer"&gt;https://anamritraj.tech&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What did I use?
&lt;/h2&gt;

&lt;p&gt;The whole blog is a server-side rendered static website powered by &lt;a href="https://www.gatsbyjs.org/" rel="noopener noreferrer"&gt;Gatsby.js&lt;/a&gt;. If you are not living under a rock for the past few months you must have heard about it. Gatsby.js is an amazing piece of technology which lets you create super-fast websites with minimal code.&lt;/p&gt;

&lt;p&gt;It uses the power of React.js, web pack and modern JavaScript and CSS to build powerful web apps. As the backend you can use anything, for my case I will be using simple MarkDown files. Gatsby.js will automatically (read &lt;em&gt;magically&lt;/em&gt;) convert you markdown files into HTML and load them as blog posts. And there are tons of plugins available to build additional features to your website. For instance, there are plugins which will convert your website into a Progressive Web App without you having to do anything.&lt;/p&gt;

&lt;p&gt;Gatsby.js will generate static assets which can be served through any server which can handle HTML, CSS and JavaScript. This means that you can use Github Pages to host your website for free, &lt;em&gt;forever&lt;/em&gt;. There are other &lt;em&gt;free&lt;/em&gt; ways to host a Gatsby.js website but I will cover what I am using for this awesome website.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why did I choose Gatsby.js?
&lt;/h2&gt;

&lt;p&gt;It's simple, easy to deploy and &lt;em&gt;hot&lt;/em&gt; right now! Apart from that it is super fast, SEO friendly, responsive and provides a PWA out of the box without having to do much.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8hietah9uc3aw4h7a93i.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8hietah9uc3aw4h7a93i.PNG" alt="Also this!" width="582" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see pretty high numbers in the Google Lighthouse Audit tool. Those are some pretty high scores and great for SEO and Mobile.&lt;/p&gt;

&lt;h2&gt;
  
  
  How can I build my own?
&lt;/h2&gt;

&lt;p&gt;So you want to build your own blog like this? You are at the right place! Let's cover that!&lt;/p&gt;

&lt;p&gt;I will assume you have the following things already, if not please search the internet on how to get them.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Git&lt;/li&gt;
&lt;li&gt;A GitHub Account&lt;/li&gt;
&lt;li&gt;A text-editor (use VS code)&lt;/li&gt;
&lt;li&gt;A Travis-CI account. (This is optional)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 1: Clone
&lt;/h3&gt;

&lt;p&gt;Clone &lt;a href="https://github.com/anamritraj/anamritraj.tech.git" rel="noopener noreferrer"&gt;this repository&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/anamritraj/anamritraj.tech.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Make changes
&lt;/h3&gt;

&lt;p&gt;Now that you have cloned this repository, move into that folder using you cmd/terminal and run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn
&lt;span class="c"&gt;# or if you are an npm user&lt;/span&gt;
npm &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will install all the project dependencies in your machine. Now, let's test this..&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn dev 
&lt;span class="c"&gt;# or &lt;/span&gt;
npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will start the development server on &lt;a href="http://localhost:8000" rel="noopener noreferrer"&gt;http://localhost:8000&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Go to &lt;code&gt;/src/pages/&lt;/code&gt; and create a new file. Keep an eye on your browser. As soon as you hit save, the post will be reflected in the browser. This is Hot-reloading and one of the features I love the most. This is by far my favourite feature of Gatsby.js. &lt;/p&gt;

&lt;p&gt;Now before deploying a website with my name and photo on it (which I would love, but you probably don't want to) let's make some changes.&lt;/p&gt;

&lt;p&gt;I will list the exact places where you may want to make the changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;README.md
package.json
script/deploy-to-gh-pages.sh
gatsby-config.js
src/components/Bio.js
src/templates/blog-post.js
static/CNAME
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: If you are not planning to use a custom domain delete that &lt;code&gt;static/CNAME&lt;/code&gt; file. Otherwise, add your domain there.&lt;/p&gt;

&lt;p&gt;There's one particular change which I would like to talk about. If you check the &lt;code&gt;/gatsby-config.js&lt;/code&gt; file. There is a parameter called &lt;code&gt;pathPrefix&lt;/code&gt;. If you are not planning to use a custom domain then you need to set it to &lt;code&gt;/REPO_NAME&lt;/code&gt;. This will tell Gatsby.js to add the necessary path to links while navigating around your website.&lt;/p&gt;

&lt;p&gt;These are all the files where you will have make changes to customize the names and some variables. I'll leave the exact changes for you to explore.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Deploy!
&lt;/h3&gt;

&lt;p&gt;Now that you have made changes to &lt;em&gt;your&lt;/em&gt; site. Let's deploy it for the world to see. We are going to use Github Pages for this.&lt;/p&gt;

&lt;p&gt;If you don't have a Github account then its probably a good idea to create one now.&lt;/p&gt;

&lt;p&gt;Now let's create a new repository on Github. &lt;br&gt;
Goto &lt;a href="https://github.com/YOUR_USERNAME?tab=repositories" rel="noopener noreferrer"&gt;https://github.com/YOUR_USERNAME?tab=repositories&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click that big green button which says &lt;em&gt;New&lt;/em&gt;. Give your repo a name and keep it Public. Don't select anything else and click Create Repository.&lt;/p&gt;

&lt;p&gt;From your terminal, run&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="c"&gt;# Rename any old origins if you have any&lt;/span&gt;
git remote rename origin destination
&lt;span class="c"&gt;# Point to the newly created repository&lt;/span&gt;
git remote add origin https://github.com/YOUR_USERNAME/REPO_NAME.git
git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin master
&lt;span class="c"&gt;# Now the usual stuff&lt;/span&gt;
git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Initial commit"&lt;/span&gt;
git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reload the page on GitHub and you should see the code there. &lt;/p&gt;

&lt;p&gt;Now, there are 2 ways to deploy code and both use GitHub Pages to serve the static files. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use your terminal to deploy to &lt;code&gt;gh-pages&lt;/code&gt; branch&lt;/li&gt;
&lt;li&gt;Use Travis-CI to deploy your static assets&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;WAY 1: The easy way&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you look at the &lt;code&gt;package.json&lt;/code&gt; file there is a &lt;code&gt;npm&lt;/code&gt; script &lt;code&gt;git-deploy&lt;/code&gt;. This will build the project and push everything in the &lt;code&gt;/public&lt;/code&gt; directory to the &lt;code&gt;gh-pages&lt;/code&gt; remote branch.&lt;/p&gt;

&lt;p&gt;From there you can go to repository settings here &lt;a href="https://github.com/YOUR_USERNAME/REPO_NAME/settings" rel="noopener noreferrer"&gt;https://github.com/YOUR_USERNAME/REPO_NAME/settings&lt;/a&gt; and enable GitHub pages to use &lt;code&gt;gh-pages&lt;/code&gt; branch.&lt;/p&gt;

&lt;p&gt;Congratulations! You have successfully deployed your code and your website is live at &lt;/p&gt;

&lt;p&gt;&lt;a href="https://YOUR_USERNAME.github.io/REPO_NAME" rel="noopener noreferrer"&gt;https://YOUR_USERNAME.github.io/REPO_NAME&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WAY 2: The cool way, and less annoying, and less manual&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's setup a Travis-CI account for this repository. Goto &lt;a href="https://travis-ci.com" rel="noopener noreferrer"&gt;https://travis-ci.com&lt;/a&gt; and SignUp / Sign In. Go ahead and setup your Github Repository with Travis-CI.&lt;/p&gt;

&lt;p&gt;Now that you have this setup, go to Travis dashboard, choose your repository, Goto settings for that repository and then go to the section of &lt;strong&gt;Environment Variables&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's add a couple of environment variables which are used in our &lt;code&gt;/script/deploy-to-gh-pages.sh&lt;/code&gt; script.&lt;br&gt;
The first one is the path of your repo&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;repo_path &lt;span class="o"&gt;=&lt;/span&gt; YOUR_GITHUB_USERNAME/REPO_NAME
&lt;span class="c"&gt;# In my case it is anamritraj/anamritraj.tech&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second one is a GitHub API key. Goto &lt;a href="https://github.com/settings/tokens" rel="noopener noreferrer"&gt;this page&lt;/a&gt; and click generate new token. Select the first checkbox which says &lt;code&gt;repo&lt;/code&gt;. Give your token a name. Now make sure you save this somewhere safe, treat it like your password and don't share it with anyone.&lt;/p&gt;

&lt;p&gt;Now, back to the Travis settings page, add another environment variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;github_token &lt;span class="o"&gt;=&lt;/span&gt; YOUR_TOKEN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, make sure that the &lt;strong&gt;Display value in build log&lt;/strong&gt; is off. This will prevent this token to show up in build logs.&lt;/p&gt;

&lt;p&gt;Now all you have to do is make changes and push the code to &lt;code&gt;master&lt;/code&gt;. Travis will automatically build it for you and deploy the code to &lt;code&gt;gh_pages&lt;/code&gt; branch.&lt;/p&gt;

&lt;p&gt;The script for this is written in &lt;code&gt;/script/deploy-to-gh-pages.sh&lt;/code&gt;. You can tweak the settings if you want to.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Iterate!
&lt;/h2&gt;

&lt;p&gt;This was in no way a complete tutorial and only scratches the top of what you can achieve with Gatsby.js. If you know basic React.js then you can make it do whatever you want.&lt;/p&gt;

&lt;p&gt;I feel like writing more stuff on this blog just because it feels so snappy while reading it. I probably will write more.&lt;/p&gt;

&lt;p&gt;Till then Merry Christmas and Happy New year!&lt;/p&gt;

</description>
      <category>gatsby</category>
      <category>react</category>
      <category>pwa</category>
      <category>blog</category>
    </item>
  </channel>
</rss>
