<?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: Badri</title>
    <description>The latest articles on DEV Community by Badri (@kbadri01).</description>
    <link>https://dev.to/kbadri01</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%2F656304%2Fb1166e16-9231-4a51-ba4e-b787b51fec97.jpeg</url>
      <title>DEV Community: Badri</title>
      <link>https://dev.to/kbadri01</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kbadri01"/>
    <language>en</language>
    <item>
      <title>React - Combining useMemo and Switch</title>
      <dc:creator>Badri</dc:creator>
      <pubDate>Wed, 08 Sep 2021 05:43:52 +0000</pubDate>
      <link>https://dev.to/kbadri01/react-combining-usememo-and-switch-pdn</link>
      <guid>https://dev.to/kbadri01/react-combining-usememo-and-switch-pdn</guid>
      <description>&lt;p&gt;useMemo is a react hook that gets executed only if any of the dependency changes. We can make it work like a switch by returning an object whose key will be the switch expression.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Form&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;switch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;selectedUser&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;AdminForm&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                       &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;User&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;UserForm&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                      &lt;span class="k"&gt;break&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;//*AdminForm and UserForm are functional components&lt;/span&gt;

&lt;span class="c1"&gt;//This code is equivalent to &lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Form&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useMemo&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Admin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;AdminForm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;User&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;UserForm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="p"&gt;}[&lt;/span&gt;&lt;span class="nx"&gt;selectedUser&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;},[&lt;/span&gt;&lt;span class="nx"&gt;selectedUser&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="cm"&gt;/*
Breaking this down, if selectedUser is "Admin", we would return 
   { 
     "Admin" : AdminForm,
     "User" : UserForm,
   }["Admin"];
which is AdminForm.
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, Form gets executed only when selectedUser changes, so the expression need not be evaluated every time. This method allows us to optimise the expression evaluation as switch needs to execute it every time but useMemo doesn't. &lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to see git history in VsCode?</title>
      <dc:creator>Badri</dc:creator>
      <pubDate>Thu, 08 Jul 2021 19:05:20 +0000</pubDate>
      <link>https://dev.to/kbadri01/how-to-see-git-history-in-vscode-1355</link>
      <guid>https://dev.to/kbadri01/how-to-see-git-history-in-vscode-1355</guid>
      <description>&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=donjayamanne.githistory"&gt;Git History&lt;/a&gt;&lt;br&gt;
Git History helps to view history and compare current code with previous commits.&lt;br&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=mhutchie.git-graph"&gt;Git Graph&lt;/a&gt;&lt;br&gt;
Git Graph helps in visualising the repository and understanding the connection between the branches.&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
    </item>
    <item>
      <title>How to commit minor changes into a previous commit (changing history of repo)?</title>
      <dc:creator>Badri</dc:creator>
      <pubDate>Thu, 08 Jul 2021 18:41:01 +0000</pubDate>
      <link>https://dev.to/kbadri01/how-to-commit-minor-changes-into-a-previous-commit-changing-history-of-repo-1fbe</link>
      <guid>https://dev.to/kbadri01/how-to-commit-minor-changes-into-a-previous-commit-changing-history-of-repo-1fbe</guid>
      <description>&lt;p&gt;If you have a minor change for which you don't want to create a new commit. Use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit --amend --no-edit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will allow you to create a new commit but replace the older one. But it will appear as if the old commit was never created. If you need to give a new message use -m flag to give a new message.&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
    </item>
    <item>
      <title>How to remove files from git?</title>
      <dc:creator>Badri</dc:creator>
      <pubDate>Thu, 08 Jul 2021 18:37:34 +0000</pubDate>
      <link>https://dev.to/kbadri01/how-to-remove-files-from-git-jil</link>
      <guid>https://dev.to/kbadri01/how-to-remove-files-from-git-jil</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git rm filename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you need to remove a file from git but not from local repository. Use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git rm --cached filename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do not forget to add the file to .gitignore if that file would be created again. &lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
    </item>
    <item>
      <title>How to revert local branch to the remote branch commit?</title>
      <dc:creator>Badri</dc:creator>
      <pubDate>Wed, 07 Jul 2021 11:04:44 +0000</pubDate>
      <link>https://dev.to/kbadri01/how-to-revert-local-branch-to-the-remote-branch-commit-3f6f</link>
      <guid>https://dev.to/kbadri01/how-to-revert-local-branch-to-the-remote-branch-commit-3f6f</guid>
      <description>&lt;p&gt;&lt;br&gt;
&lt;code&gt;git reset --hard origin/upstream_branch_name&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;This replaces the local branch with remote branch.&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
    </item>
  </channel>
</rss>
