<?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: Shane Mitchell</title>
    <description>The latest articles on DEV Community by Shane Mitchell (@shanesc).</description>
    <link>https://dev.to/shanesc</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%2F138507%2F0fa64a65-2ac2-4621-8027-8fd77391c8db.jpg</url>
      <title>DEV Community: Shane Mitchell</title>
      <link>https://dev.to/shanesc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shanesc"/>
    <language>en</language>
    <item>
      <title>How to: Enable JavaScript auto-import suggestions in VS Code</title>
      <dc:creator>Shane Mitchell</dc:creator>
      <pubDate>Wed, 09 Mar 2022 00:00:00 +0000</pubDate>
      <link>https://dev.to/shanesc/how-to-get-javascript-auto-import-suggestions-working-in-vs-code-aig</link>
      <guid>https://dev.to/shanesc/how-to-get-javascript-auto-import-suggestions-working-in-vs-code-aig</guid>
      <description>&lt;p&gt;&lt;a href="/static/cbe16545c7353b60b32c3f8a86c52c1f/ee3fb/splash.png"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.shanemitchell.dev%2Fstatic%2Fcbe16545c7353b60b32c3f8a86c52c1f%2Ff058b%2Fsplash.png" title="Auto import suggestions" alt="Auto import suggestions" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Auto-import problems
&lt;/h2&gt;

&lt;p&gt;If you work on JavaScript projects in VS Code, you’ve almost certainly been frustrated with the hit-or-miss nature of the auto-import suggestions. When you try to import code from elsewhere in your project, the correct suggestion is nowhere to be found.&lt;/p&gt;

&lt;p&gt;&lt;a href="/static/701a246b600a80a8cc6d2683bd402fdc/f53a0/auto-import-not-working.png"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.shanemitchell.dev%2Fstatic%2F701a246b600a80a8cc6d2683bd402fdc%2Ff058b%2Fauto-import-not-working.png" title="Import missing from suggestions" alt="Import missing from suggestions" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are extensions to help with this, but it turns out VS Code now handles this natively – using the &lt;code&gt;jsconfig.json&lt;/code&gt; file – and luckily it’s very simple to setup.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create the &lt;code&gt;jsconfig.json&lt;/code&gt; file
&lt;/h2&gt;

&lt;p&gt;As of 2018, VS Code treats all JS files as separate from one another. In order to tell it that your files are all part of an &lt;strong&gt;Explicit Project&lt;/strong&gt; , you need to create and configure a &lt;code&gt;jsconfig.json&lt;/code&gt; file (this is a descendant of &lt;code&gt;tsconfig.json&lt;/code&gt;, which is required for TypeScript projects).&lt;/p&gt;

&lt;p&gt;Here’s how:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create the &lt;code&gt;jsconfig.json&lt;/code&gt; file at the root of your project.&lt;/li&gt;
&lt;li&gt;(Optional) Configure the compiler options.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Technically an empty file will suffice to tell VS Code this is a project, but you’ll likely want to configure a few things.&lt;/p&gt;

&lt;p&gt;There’s a lot of options that can be set, but a few that I like to set for React projects are:&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="c1"&gt;// jsconfig.json at project root&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;compilerOptions&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;module&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ES6&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;jsx&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;preserve&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;checkJs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;exclude&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;node_modules&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;**/node_modules/*&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://code.visualstudio.com/docs/languages/jsconfig" rel="noopener noreferrer"&gt;See the docs&lt;/a&gt; for details and more config settings.&lt;/p&gt;

&lt;h2&gt;
  
  
  And it works! 👍
&lt;/h2&gt;

&lt;p&gt;Now that VS Code knows to treat all your JS files as an explicit project, auto-import suggestions will populate with all your relevant exported code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8k5z8e4ikbtue7o7d3ot.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8k5z8e4ikbtue7o7d3ot.gif" alt="Auto import suggestion working" width="768" height="620"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope that helps! For more VS Code import tips, &lt;a href="https://dev.to/shanesc/how-to-sort-and-cleanup-imports-on-save-in-vs-code-52p1"&gt;see my post on automatic import sorting&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>vscode</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to: Enable automatic import sorting in VS Code</title>
      <dc:creator>Shane Mitchell</dc:creator>
      <pubDate>Wed, 09 Mar 2022 00:00:00 +0000</pubDate>
      <link>https://dev.to/shanesc/how-to-sort-and-cleanup-imports-on-save-in-vs-code-52p1</link>
      <guid>https://dev.to/shanesc/how-to-sort-and-cleanup-imports-on-save-in-vs-code-52p1</guid>
      <description>&lt;p&gt;&lt;a href="/static/9482c9283fa42138ce86975623e280a9/d5bfb/splash.png"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.shanemitchell.dev%2Fstatic%2F9482c9283fa42138ce86975623e280a9%2Ff058b%2Fsplash.png" title="Sorted ES6 imports" alt="Sorted ES6 imports" width="630" height="172"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There’s a VS Code setting that enables automatic organizing of imports on file saves.&lt;/p&gt;

&lt;p&gt;It primarily does two things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;sorts imports based on ESLint settings&lt;/li&gt;
&lt;li&gt;removes any unused imports&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Aside from being a timesaver, this also avoids linting errors (which is especially useful in CI/CD codebases where linting errors will stop a job from completing).&lt;/p&gt;

&lt;p&gt;What’s great is you can set it in your user or project settings and forget about it, and it’s only a couple lines.&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="c1"&gt;// settings.json&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// put this in your settings object&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;editor.codeActionsOnSave&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;source.organizeImports&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that’s it! Now when you save, your imports magically sort themselves out!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl2au8tbqpdpbds66cgco.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl2au8tbqpdpbds66cgco.gif" alt="Imports automatically organizing themselves" width="800" height="214"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>vscode</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Next.js Custom Link Attributes</title>
      <dc:creator>Shane Mitchell</dc:creator>
      <pubDate>Fri, 07 Jan 2022 16:35:00 +0000</pubDate>
      <link>https://dev.to/shanesc/nextjs-custom-link-attributes-7ck</link>
      <guid>https://dev.to/shanesc/nextjs-custom-link-attributes-7ck</guid>
      <description>&lt;p&gt;Next.js provides a nifty little &lt;code&gt;Link&lt;/code&gt; component, which allows internal linking within your React application without causing a page refresh.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Home&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While this works great, there are situations where you want to pass additional attributes to your anchor tag, such as &lt;code&gt;aria&lt;/code&gt; attributes or custom &lt;code&gt;data&lt;/code&gt; attributes.&lt;/p&gt;

&lt;p&gt;Since &lt;code&gt;Link&lt;/code&gt; is a React component and expects specific props to be passed, you can’t simply pass in the attributes as props to the &lt;code&gt;Link&lt;/code&gt; component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// This doesn't work, the rendered anchor tag ignores&lt;/span&gt;
&lt;span class="c1"&gt;// the additional attribute&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;data-name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"custom"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Home&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lucky for us, Next provides a simple solution to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&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;a&lt;/span&gt; &lt;span class="na"&gt;data-name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"custom"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Home&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;a&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="nc"&gt;Link&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: It's important that your &lt;code&gt;href&lt;/code&gt; stay as a prop in &lt;code&gt;Link&lt;/code&gt; rather than an attribute in the anchor tag.&lt;/p&gt;

&lt;p&gt;This renders out to &lt;code&gt;&amp;lt;a href="/" data-name="custom"&amp;gt;Home&amp;lt;/a&amp;gt;&lt;/code&gt; in the DOM and maintains the internal linking speediness we love about Next!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>nextjs</category>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>Remote Pair Programming in VS Code</title>
      <dc:creator>Shane Mitchell</dc:creator>
      <pubDate>Mon, 26 Apr 2021 00:00:00 +0000</pubDate>
      <link>https://dev.to/shanesc/remote-pair-programming-in-vs-code-54k2</link>
      <guid>https://dev.to/shanesc/remote-pair-programming-in-vs-code-54k2</guid>
      <description>&lt;p&gt;Pair programming – two programmers working together on one workstation at the same time – is easy enough to do when both people are sitting at the same computer. But when attempting to pair program remotely, there is a little bit of setup required to get an effective workspace. Fortunately, if both programmers are using Visual Studio Code, it is easy to setup using a few great extensions – &lt;a href="https://marketplace.visualstudio.com/items?itemName=MS-vsliveshare.vsliveshare" rel="noopener noreferrer"&gt;Live Share&lt;/a&gt;, &lt;a href="https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer" rel="noopener noreferrer"&gt;Live Server&lt;/a&gt;, and &lt;a href="https://marketplace.visualstudio.com/items?itemName=lostintangent.vsls-pomodoro" rel="noopener noreferrer"&gt;Live Share Pomodoro&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;As part of the curriculum for &lt;a href="https://www.theodinproject.com" rel="noopener noreferrer"&gt;The Odin Project&lt;/a&gt;, I worked on an assignment to create a Pomodoro Timer application. But the real purpose of the project was to introduce students to pair programming. And seeing that the course is all online, the first step (after finding a partner) was setting up the workspace to replicate in-person pair programming.&lt;/p&gt;

&lt;p&gt;I use VS Code, and lucky for me Microsoft has developed the Live Share extension that allows collaborative coding on a hosts local files to all invited participants. This, coupled with a couple other extensions, makes for a very effective pair programming environment, which should be as effective as in-person pairs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;If you don’t already have VS Code installed, &lt;a href="https://code.visualstudio.com/download" rel="noopener noreferrer"&gt;download and install&lt;/a&gt; for your operating system.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Important Note:&lt;/strong&gt; VS Code and the extensions must be installed on both programmers’ computers in order to be used together.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Install Extensions
&lt;/h3&gt;

&lt;p&gt;You’ll need to install two extensions, and one optional extension. Open up VS Code, navigate to the Extensions tab, then search for and install the following (alternatively just open the links and install from the browser):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=MS-vsliveshare.vsliveshare" rel="noopener noreferrer"&gt;Live Share&lt;/a&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fciyplwmkgpyhddta7ypc.png" alt="Live Share Extension" width="800" height="552"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer" rel="noopener noreferrer"&gt;Live Server&lt;/a&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiweglnniwloupgx9kknx.png" alt="Live Server Extension" width="800" height="552"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=lostintangent.vsls-pomodoro" rel="noopener noreferrer"&gt;Live Share Pomodoro&lt;/a&gt; (&lt;em&gt;Optional&lt;/em&gt;)&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5h15gt315ms04a6774la.png" alt="Live Share Pomodoro Extension" width="800" height="552"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With these extensions installed, close and reopen VS Code. You’re now ready to start the Live Share server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hosting and Collaborating
&lt;/h2&gt;

&lt;p&gt;There’s a few steps to take, but once it’s setup you will be ready to collaborate!&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open VS Code and a new Workspace.&lt;/li&gt;
&lt;li&gt;Open the Live Share tab, and click &lt;strong&gt;Start collaboration session…&lt;/strong&gt;
&lt;a href="https://blog.shanemitchell.dev/static/b9677c77dc7a9c2aab1842fcf9c4088d/67a79/hosting-step-1.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.shanemitchell.dev%2Fstatic%2Fb9677c77dc7a9c2aab1842fcf9c4088d%2Ff058b%2Fhosting-step-1.png" title="Hosting Step 1" alt="Hosting Step 1" width="800" height="400"&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;This should create a Live Share server and copy a link to your clipboard. This can now be shared with your programming partner and will allow them to join.
&lt;a href="https://blog.shanemitchell.dev/static/d90bcc5b73a745ee532ae4a126b72850/67a79/hosting-step-2.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.shanemitchell.dev%2Fstatic%2Fd90bcc5b73a745ee532ae4a126b72850%2Ff058b%2Fhosting-step-2.png" title="Hosting Step 2" alt="Hosting Step 2" width="800" height="400"&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;With your index HTML file open, right-click in the editor window and select &lt;strong&gt;Open with Live Server&lt;/strong&gt;.
&lt;a href="https://blog.shanemitchell.dev/static/615f78dfb391389d53510dda95eb2dcc/33c15/hosting-step-3.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.shanemitchell.dev%2Fstatic%2F615f78dfb391389d53510dda95eb2dcc%2Ff058b%2Fhosting-step-3.png" title="Hosting Step 3" alt="Hosting Step 3" width="800" height="400"&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This will launch a local version of the HTML file in your browser, and &lt;em&gt;also&lt;/em&gt; create a shared server that your partner can click to load the file in their browser (look for &lt;strong&gt;Live Server&lt;/strong&gt; in the &lt;strong&gt;Shared Server&lt;/strong&gt; dropdown).&lt;/p&gt;

&lt;p&gt;Any changes that are saved to this file will update the browser view for both you &lt;em&gt;and&lt;/em&gt; your partner. Pretty rad!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.shanemitchell.dev/static/df6080889e83b1901f4530e33d7dd355/29114/hosting-step-4.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.shanemitchell.dev%2Fstatic%2Fdf6080889e83b1901f4530e33d7dd355%2Ff058b%2Fhosting-step-4.png" title="Hosting Step 4" alt="Hosting Step 4" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap Up
&lt;/h2&gt;

&lt;p&gt;In only a few minutes you can have a really nice pair programming environment setup for you and your partner(s).&lt;/p&gt;

&lt;p&gt;What’s great about this setup is that you can see live code updates as your buddy codes along, and see the HTML page reflect the changes even if the file is not local to your computer! No need to constantly push and pull from GitHub.&lt;/p&gt;

&lt;p&gt;I also find the installed Pomodoro Timer extension to be really useful. If you both have this installed, you can start a 25min timer that is great for switching roles between driving and navigating.&lt;/p&gt;

&lt;p&gt;There is also built-in voice chat within Live Share, however I have not used that feature. But great to know that it has all the tools you need in one clean package!&lt;/p&gt;

</description>
      <category>tutorial</category>
    </item>
    <item>
      <title>An Introduction to REST APIs</title>
      <dc:creator>Shane Mitchell</dc:creator>
      <pubDate>Wed, 07 Apr 2021 00:00:00 +0000</pubDate>
      <link>https://dev.to/shanesc/an-introduction-to-rest-apis-2dgh</link>
      <guid>https://dev.to/shanesc/an-introduction-to-rest-apis-2dgh</guid>
      <description>&lt;p&gt;The term “REST API” (aka “RESTful API”) is thrown around all the time when talking about web applications. But what exactly does the term REST mean? And why is it important to API design?&lt;/p&gt;

&lt;p&gt;There’s a number of guidelines that define REST, but there are a couple of key points that will help to introduce and understand REST APIs.&lt;/p&gt;

&lt;h2&gt;
  
  
  First, what is an API?
&lt;/h2&gt;

&lt;p&gt;Before getting into what REST is, let’s briefly describe an API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An API (Application Programming Interface) is a way of communicating with an application and tapping into some of its functionality.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For example, an API can be used to request information (data) from an application, or used to run complex computations on data passed into an API request. The application’s API exposes its functionality as methods, operations, endpoints, etc., and the specific language of the API depends on the application.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: in order to use an API, you need to know the functionality available and the format which it expects the request/response to be in.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As an analogy, imagine a vending machine. A customer walks up to the vending machine, sees a bunch of buttons for different sodas, and presses the button for the one they want. The vending machine then does a bunch of stuff behind the scenes and pops out the soda.&lt;/p&gt;

&lt;p&gt;The front of the machine is like the API, and the buttons are like available methods of an API. Pressing a button is like calling a method, i.e. requesting something from the application. The machine and the application both perform some magic behind closed doors and respond to the request.&lt;/p&gt;

&lt;p&gt;The customer doesn’t really care what happened behind the scenes, they just want a soda. The same is true of one application using another application’s functionality through its API.&lt;/p&gt;

&lt;p&gt;In the context of web applications, server APIs are often used to pull data from the server and/or database into the client (or vice versa, sending data from the client to the server). This is where the practice of REST comes into play.&lt;/p&gt;

&lt;h2&gt;
  
  
  RESTful APIs
&lt;/h2&gt;

&lt;p&gt;REST stands for &lt;u&gt;&lt;strong&gt;Re&lt;/strong&gt;&lt;/u&gt;presentational &lt;u&gt;&lt;strong&gt;S&lt;/strong&gt;&lt;/u&gt;tate &lt;u&gt;&lt;strong&gt;T&lt;/strong&gt;&lt;/u&gt;ransfer. These three words do a great job of describing the essence of a REST API, but require a little deciphering first.&lt;/p&gt;

&lt;p&gt;Put another way, REST defines &lt;strong&gt;a standard way for web applications to share information, by transferring a representation of the state of some data&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If we break this down:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Representational State: A snapshot of the data saved in a database, or the data sent from the client. This represents its state at the moment of the transfer.&lt;/li&gt;
&lt;li&gt;Transfer: The &lt;a href="https://www.w3schools.com/whatis/whatis_http.asp" rel="noopener noreferrer"&gt;HTTP&lt;/a&gt; requests and responses between the client and the server, which allows standardized operations across the web.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;So, an application using a REST API uses HTTP requests/responses to transfer a snapshot of some data.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using the vending machine analogy, the “buttons” of a REST API are endpoints (i.e. URLs) and HTTP methods, and the “soda” is the representational state of the data.&lt;/p&gt;

&lt;p&gt;As an example, a client might make an HTTP “GET” request to a server (using the JavaScript &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch" rel="noopener noreferrer"&gt;Fetch API&lt;/a&gt; here), a little like this:&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="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some-server.com/api/tacos&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;GET&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The server would receive this request, do some magic based on what was requested, and respond back with a snapshot of the data at that point in time. Without going into details, the response might look a little like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"tacos"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"carnitas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"cheese"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"carne asada"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The client could then go off and use this data as it pleases, for instance to display a menu of available tacos!&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is this important for web APIs?
&lt;/h2&gt;

&lt;p&gt;One component of reliable and scalable web applications is separation of concerns. This is where REST guidelines shine.&lt;/p&gt;

&lt;p&gt;When the client and server communicate via the REST API, they are sending snapshots which represent the data state at the time of transfer. The data could change one second after the API transfer, but what the client received remains unchanged. In other words, outside of the API call, neither knows anything about the state of the other.&lt;/p&gt;

&lt;p&gt;Additionally, different clients can use the API to communicate with the server, and the server will happily perform its functions for them all. And once the client has received its snapshot of the data in response, it doesn’t care what the server does afterwards.&lt;/p&gt;

&lt;p&gt;Again, outside of the API, the server and any of its clients are not concerned with each other.&lt;/p&gt;

&lt;p&gt;When the client and the server are decoupled from each other like this, the code on either end can change independently of each other, so long as the API remains the same. This allows independent scalability and improved reliability on both sides.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;So there you go, a brief introduction to what REST APIs are and why they are important in web applications.&lt;/p&gt;

&lt;p&gt;Key points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;APIs allow communication between clients and a server, in accordance with a defined “language”.&lt;/li&gt;
&lt;li&gt;REST APIs adhere to a standard format for transferring information to and from the application.&lt;/li&gt;
&lt;li&gt;REST APIs ensure separation of concerns by decoupling the logic of the client/server, instead transferring snapshots of data then carrying on independently.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Named vs. Default Exports in ES6 Modules</title>
      <dc:creator>Shane Mitchell</dc:creator>
      <pubDate>Sat, 02 Jan 2021 18:08:54 +0000</pubDate>
      <link>https://dev.to/shanesc/named-vs-default-exports-in-es6-modules-1cim</link>
      <guid>https://dev.to/shanesc/named-vs-default-exports-in-es6-modules-1cim</guid>
      <description>&lt;p&gt;JavaScript Modules using ES6 syntax have two different types of exports: &lt;strong&gt;named&lt;/strong&gt; and &lt;strong&gt;default&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;There are differences in how they are declared as well as how they are imported.&lt;/p&gt;

&lt;h2&gt;
  
  
  Named Exports
&lt;/h2&gt;

&lt;p&gt;Named exports can be used to export several variables from a module. The &lt;code&gt;export&lt;/code&gt; keyword can be used for each variable that you want to export. When importing, you use &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment" rel="noopener noreferrer"&gt;object destructuring&lt;/a&gt; to assign the exported variables. The imported variables must use the same name as the exports.&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="c1"&gt;// foo.js&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;foo&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;foo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;foo.js&lt;/code&gt; has two named exports, &lt;code&gt;foo&lt;/code&gt; and &lt;code&gt;bar&lt;/code&gt;, which can be imported from any other JavaScript file like:&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="c1"&gt;// anotherComponent.js&lt;/span&gt;

&lt;span class="c1"&gt;// import the foo and bar named exports from foo.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;bar&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./foo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// both variables can now be used&lt;/span&gt;
&lt;span class="nf"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// logs 'foo' to the console&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// logs the number 123 to the console&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Named exports can be used to export and import several variables from a module.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;When using named exports, the imported variables must use the same name as the exported variables.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;If you want to rename imported variables, you can use the &lt;code&gt;as&lt;/code&gt; keyword:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;myVariable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;bar&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./foo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;myVariable&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// logs 'foo' to the console&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Default Exports
&lt;/h2&gt;

&lt;p&gt;You can only have one default export in a module. You use the &lt;code&gt;default&lt;/code&gt; keyword to specify which variable is the default export. When importing default exports, any name can be used for variable assignment.&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="c1"&gt;// baz.js&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;baz&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;baz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;baz&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that &lt;code&gt;baz.js&lt;/code&gt; has defined its default export, any other JavaScript file can import and use the &lt;code&gt;baz&lt;/code&gt; variable by importing as so:&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="c1"&gt;// anotherComponent.js&lt;/span&gt;

&lt;span class="c1"&gt;// import the default export from baz.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;bazDefault&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./baz&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// the imported variable can now be used&lt;/span&gt;
&lt;span class="nf"&gt;bazDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// logs 'baz' to the console&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We've successfully imported &lt;code&gt;baz&lt;/code&gt; into a variable called &lt;code&gt;bazDefault&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Each module can only have one default export&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;You define the default export using the &lt;code&gt;default&lt;/code&gt; keyword.&lt;/li&gt;
&lt;li&gt;When using default exports, we can choose any name for the variable we import into. I chose &lt;code&gt;bazDefault&lt;/code&gt;, but could have just as easily called it &lt;code&gt;baz&lt;/code&gt;, &lt;code&gt;someVariable&lt;/code&gt;, or &lt;code&gt;apples&lt;/code&gt; and it would have been perfectly valid.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;So that's it, the differences between named and default exports in ES6 and how they are used.&lt;/p&gt;

&lt;p&gt;Key points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Modules can have several named exports, but only one default export.&lt;/li&gt;
&lt;li&gt;When importing, named exports must use the same name, while default exports can be imported to any name.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
