<?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: Adam Laycock</title>
    <description>The latest articles on DEV Community by Adam Laycock (@arcath).</description>
    <link>https://dev.to/arcath</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%2F94885%2F540aa9ac-81ea-47c6-8eb6-b7c8004d2aec.jpeg</url>
      <title>DEV Community: Adam Laycock</title>
      <link>https://dev.to/arcath</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arcath"/>
    <language>en</language>
    <item>
      <title>Robocopy, the best copying tool you already have.</title>
      <dc:creator>Adam Laycock</dc:creator>
      <pubDate>Mon, 25 Nov 2019 21:31:56 +0000</pubDate>
      <link>https://dev.to/arcath/robocopy-the-best-copying-tool-you-already-have-la8</link>
      <guid>https://dev.to/arcath/robocopy-the-best-copying-tool-you-already-have-la8</guid>
      <description>&lt;p&gt;Robocopy is an amazing tool that is built into Windows. If your running Windows 10 you already have it! Just fire up a command prompt and your away.&lt;/p&gt;

&lt;p&gt;I've known about and used Robocopy for quite a few years now. In my line of work I often find I need to copy multiple terrabytes of data from one server to another and the standard Windows file copy is just not setup for that.&lt;/p&gt;

&lt;p&gt;The standard file copy does some helpful stuff that doesn't scale well. Counting the remaining files, estimating the time remaining, and calculating the total transfer speed all take time and effort that could be spent copying.&lt;/p&gt;

&lt;p&gt;Robocopy or &lt;em&gt;Robust File Copy&lt;/em&gt; to use its full name is a command line utility that is faster and has quite a few more options than the standard file copier.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some Numbers
&lt;/h2&gt;

&lt;p&gt;Lets put some numbers to the performance of robocopy.&lt;/p&gt;

&lt;p&gt;First off the standard copy dialog.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ffm5tnpyp53eghttsmcuh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ffm5tnpyp53eghttsmcuh.png" alt="Standard File Copy dialog"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To keep things fair I am copying the same 140MB folder from one place on my SSD to another.&lt;/p&gt;

&lt;p&gt;Standard File Copy (SFC so I don't have to keep typing it) managed to copy the folder in 9 seconds which isnt bad.&lt;/p&gt;

&lt;p&gt;Robocopy on the other hand managed the same copy in 2 seconds.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fmwej5wow127qq4elg0uv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fmwej5wow127qq4elg0uv.png" alt="Robocopy"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thats a pretty good reduction although you do lose more than 7 seconds to opeing command prompt and typing the command out but thats not the point, if you need robocopy over the standard file copy chances are your copying something pretty big.&lt;/p&gt;

&lt;h2&gt;
  
  
  More features
&lt;/h2&gt;

&lt;p&gt;Robocopy can do more than just copy files/folders from one place to another. The quickest way to use robocopy is with &lt;code&gt;/MIR&lt;/code&gt; e.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="nb"&gt;robocopy&lt;/span&gt; &lt;span class="kd"&gt;C&lt;/span&gt;:\Data &lt;span class="kd"&gt;D&lt;/span&gt;:\Backup &lt;span class="na"&gt;/MIR
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;/MIR&lt;/code&gt; or &lt;em&gt;Mirror&lt;/em&gt; is a shorthand for &lt;code&gt;/E /PURGE&lt;/code&gt; which means copy all subdirectories include empty ones (&lt;code&gt;/E&lt;/code&gt;) and delete files/folders in the destination that are not present in the source (&lt;code&gt;/PURGE&lt;/code&gt;). Couple this with the fact that robocopy will skip exisiting unchanged files and youve got a great way to migrate data. I frequently run a robocopy that takes hours one week then come back a week later to finish the job and have a really quick robocopy only unpdate the destination with the weeks changes.&lt;/p&gt;

&lt;p&gt;There are a multitude of options that can change the way robocopy works. I wont go into them all here &lt;code&gt;robocopy /?&lt;/code&gt; will list them all for you. The options I use a lot is &lt;code&gt;/XD&lt;/code&gt; which can exclude directories from your copy and &lt;code&gt;/XF&lt;/code&gt; which does the same for files. These options are incredibly useful when copying a user profile.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;&lt;span class="nb"&gt;robocopy&lt;/span&gt; &lt;span class="kd"&gt;C&lt;/span&gt;:\Users\Adam &lt;span class="kd"&gt;D&lt;/span&gt;:\Backups\Adam &lt;span class="na"&gt;/MIR /XD &lt;/span&gt;&lt;span class="kd"&gt;AppData&lt;/span&gt; &lt;span class="na"&gt;/XF &lt;/span&gt;&lt;span class="kd"&gt;ntuser&lt;/span&gt;.dat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This excludes &lt;code&gt;AppData&lt;/code&gt; that is normally pretty big and contains a lot of content that isnt really something you can copy, &lt;code&gt;ntuser.dat&lt;/code&gt; is the users registry which if your logged on as the user you are copying will be in use and un readable.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/W:0 /R:0&lt;/code&gt; also features alot when I do big copies as it reduces the wait time to 0 and the retries to 0 which stops robocopy wasting its time on corrupt or in use files. As menitoned earlier I can simply re run the same copy later and it will only try the files it had problems with again.&lt;/p&gt;

&lt;p&gt;The robocopy help file an be read online over on &lt;a href="https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy" rel="noopener noreferrer"&gt;Microsoft Docs&lt;/a&gt; which goes into great detail of the other options robocopy has.&lt;/p&gt;

</description>
      <category>windows</category>
    </item>
    <item>
      <title>Destructuring in JavaScript</title>
      <dc:creator>Adam Laycock</dc:creator>
      <pubDate>Mon, 25 Nov 2019 13:20:56 +0000</pubDate>
      <link>https://dev.to/arcath/destructuring-in-javascript-2bck</link>
      <guid>https://dev.to/arcath/destructuring-in-javascript-2bck</guid>
      <description>&lt;p&gt;Destructuring allows you to assign values to variables in a quick shorthand instead of having multiple lines. I use it pretty much every day but I can’t remember a time when I actually learnt anything about it, it just kind of appeared in my code and I’ve used it ever since.&lt;/p&gt;

&lt;p&gt;A prime example of its use in the wild is React, take this function component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;FC&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;startCount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;startCount&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;startCount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&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="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Count&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&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;Without destructuring it would look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;FC&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;startCount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&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;=&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;countState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&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;startCount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&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="nx"&gt;countState&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="nx"&gt;countState&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Count&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;countState&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]})&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&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;Both types of destructuing occur in this example so lets take a look at them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Array Destructuring
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;c1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;c2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;c3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;

&lt;span class="nx"&gt;c1&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="nx"&gt;c2&lt;/span&gt; &lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;span class="nx"&gt;c3&lt;/span&gt; &lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With Array Destructuring you are taking the elements in the array and assigning them to variables, as a result the order of variable names is important.&lt;/p&gt;

&lt;p&gt;This is how React’s &lt;code&gt;useState&lt;/code&gt; works and it is used here because the React developers that wrote &lt;code&gt;useState&lt;/code&gt; have no idea what the names you want to use for the variables are.&lt;/p&gt;

&lt;h2&gt;
  
  
  Object Destructuring
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;author&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;29&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;adam&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&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;age&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;author&lt;/span&gt;

&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="c1"&gt;// 29&lt;/span&gt;
&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="c1"&gt;// adam&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With Object destructuring the names of the object’s properties are important. The properties of the object become the variables that come out of the destructuring.&lt;/p&gt;

&lt;p&gt;Lets say &lt;code&gt;useState&lt;/code&gt; actually returned an object of &lt;code&gt;{value: T, setValue: (newValue: T) =&amp;gt; void}&lt;/code&gt; we would have to assign those values as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As you can see its not very descriptive which is why the return value from &lt;code&gt;useState&lt;/code&gt; is an array.&lt;/p&gt;

&lt;p&gt;You can assign different variable names to destructured properties but the process would be cumbersome if we had to do it for every &lt;code&gt;useState&lt;/code&gt; call.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  useQuery and useLazyQuery
&lt;/h2&gt;

&lt;p&gt;A great example of when/why you would use either return type is Apollo GraphQLs React Hooks of &lt;code&gt;useQuery&lt;/code&gt; and &lt;code&gt;useLazyQuery&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;useQuery&lt;/code&gt; runs the query the moment the component is mounted and returns an object. This is great as you usually only have one query per component, and if you have more you should really merge them or move the code into another component. This means at a minimum you are pulling &lt;code&gt;loading&lt;/code&gt;, &lt;code&gt;error&lt;/code&gt; and &lt;code&gt;data&lt;/code&gt; from &lt;code&gt;useQuery&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;SOME_QUERY&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;useLazyQuery&lt;/code&gt; on the other hand waits until it is called to run the query. To this end it returns an array the first element of which is the function to run the query and the second is the same return object as &lt;code&gt;useQuery&lt;/code&gt; with an additional &lt;code&gt;called&lt;/code&gt; property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;getAuthors&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;called&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useLazyQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;AUTHOR_QUERY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I use destructring every day across all the code I write and it’s become my default way of working as I’m sure it has for a lot of my fellow developers. Hopefully this article gives everyone new and old to destructuing an idea of what is going on when you use it.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Using HTMR to bring life to links in Gatsby</title>
      <dc:creator>Adam Laycock</dc:creator>
      <pubDate>Wed, 15 May 2019 10:12:51 +0000</pubDate>
      <link>https://dev.to/arcath/using-htmr-to-bring-life-to-links-in-gatsby-1968</link>
      <guid>https://dev.to/arcath/using-htmr-to-bring-life-to-links-in-gatsby-1968</guid>
      <description>&lt;p&gt;One of the amazing things about Gatsby is that your site is a full blown React app. Because of this it’s always bugged me that whilst the navigation within &lt;em&gt;app&lt;/em&gt; is extremely fast anything I link to from my markdown triggers a full request for the page.&lt;/p&gt;

&lt;p&gt;This happens because the links in markdown are just an &lt;code&gt;a&lt;/code&gt; tag placed on the page from &lt;code&gt;dangerouslySetInnerHTML&lt;/code&gt;. This means no event listeners or anything, just a plain old fashioned link. The solution is to parse the HTML string and swap ot the links for the proper React components.&lt;/p&gt;

&lt;p&gt;There are a few HTML to React converters but I found &lt;a href="https://github.com/pveyes/htmr"&gt;HTMR&lt;/a&gt; easy to use for my needs. I’m only looking to swap out &lt;code&gt;a&lt;/code&gt; tags for a &lt;code&gt;Link&lt;/code&gt; component, not binding events or anything fancy like that.&lt;/p&gt;

&lt;p&gt;I already have a &lt;code&gt;Content&lt;/code&gt; component that takes a &lt;code&gt;html&lt;/code&gt; prop. I created it for just such a case as this where I want to change the way content is rendered across the whole site.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;ReactHTMLElement&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;convert&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;htmr&lt;/span&gt;&lt;span class="dl"&gt;'&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;HtmrOptions&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;htmr/lib/types&lt;/span&gt;&lt;span class="dl"&gt;'&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;OutboundLink&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;gatsby-plugin-google-gtag&lt;/span&gt;&lt;span class="dl"&gt;'&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;Link&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;gatsby&lt;/span&gt;&lt;span class="dl"&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;Content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;FunctionComponent&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;html&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;html&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="kd"&gt;const&lt;/span&gt; &lt;span class="na"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;HtmrOptions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;transform&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;node&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Partial&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ReactHTMLElement&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;HTMLAnchorElement&lt;/span&gt;&lt;span class="o"&gt;&amp;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;props&lt;/span&gt;&lt;span class="dl"&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="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="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;node&lt;/span&gt;

      &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OutboundLink&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;OutboundLink&lt;/span&gt;&lt;span class="p"&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;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt; &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&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;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;&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="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;convert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;transform&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="si"&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;So what is this doing?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;convert&lt;/code&gt; comes from HTMR and performs the actual conversion. I’ve put it in a &lt;code&gt;div&lt;/code&gt; tag here to deal with the edge case of &lt;code&gt;html&lt;/code&gt; being a string with no tags in it. To bring life to links I used the optional &lt;code&gt;transform&lt;/code&gt; option that you can pass to the &lt;code&gt;convert&lt;/code&gt; function. From here you can map tags to other tags e.g. &lt;code&gt;b: 'strong'&lt;/code&gt; to use &lt;code&gt;strong&lt;/code&gt; instead of &lt;code&gt;b&lt;/code&gt; for all &lt;code&gt;b&lt;/code&gt; tags. Or you can provide a replacement component, &lt;code&gt;button: Button&lt;/code&gt; to use a styled button instead. The third usage method is to provide a function.&lt;/p&gt;

&lt;p&gt;The function is passed a single argument which is the &lt;code&gt;props&lt;/code&gt; that HTMR would use for the orginal tag.&lt;/p&gt;

&lt;p&gt;For Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// HTML
&amp;lt;a href="/something"&amp;gt;a link&amp;lt;/a&amp;gt;
// Props
{href: '/something', children: 'a link'}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the code above I do a check of the &lt;code&gt;href&lt;/code&gt; prop to see if this is an internal link, or an external link. If its an external link it is replaced with an &lt;code&gt;OutboundLink&lt;/code&gt; which makes sure Google Analytics handles the link correctly. Otherwise it must be an internal link which gets replaced with a &lt;code&gt;Link&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The outcome of all this is much faster internal links.&lt;/p&gt;

&lt;p&gt;Take this link to &lt;a href="https://dev.to/about"&gt;about me&lt;/a&gt; it is an internal link that is now a proper &lt;code&gt;Link&lt;/code&gt;. Give it a try and notice how fast it is. This link to my &lt;a href="https://arcath.net/uses"&gt;uses page&lt;/a&gt; on the other hand, thats a full blown link and works like internal links did before HTMR.&lt;/p&gt;

&lt;p&gt;There is the plugin &lt;a href="https://www.gatsbyjs.org/packages/gatsby-plugin-catch-links/"&gt;gatsby-plugin-catch-links&lt;/a&gt; that provides a similar outcome but does it in a very heavy handed way. It binds itself to all links in the browser and on a per-link basis decides if its an internal link and how to navigate to its target. My method with HTMR &lt;em&gt;fixes&lt;/em&gt; the links during site build and requires no extra even bindings on the client side. Plus it only applies to the markdown and not other links on the site that are already React components.&lt;/p&gt;

</description>
      <category>gatsby</category>
      <category>react</category>
    </item>
    <item>
      <title>Generated Social Images</title>
      <dc:creator>Adam Laycock</dc:creator>
      <pubDate>Wed, 23 Jan 2019 13:30:00 +0000</pubDate>
      <link>https://dev.to/arcath/generated-social-images-49ca</link>
      <guid>https://dev.to/arcath/generated-social-images-49ca</guid>
      <description>&lt;p&gt;I follow &lt;a href="https://dev.to"&gt;dev.to&lt;/a&gt; who have some great images on their tweets that are bascially just the post title and author. I really like the way it looks and want to try something here.&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
        &lt;br&gt;
        &lt;br&gt;
        &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7C_iaQfd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://arcath.net/static/c42e951fbe37ecb63a80c9c5841f30fe/a7edf/dev.to.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7C_iaQfd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://arcath.net/static/c42e951fbe37ecb63a80c9c5841f30fe/a7edf/dev.to.png" alt="dev.to example" title=""&gt;&lt;/a&gt;&lt;br&gt;
      &lt;/p&gt;

&lt;p&gt;I’m not a fan of manual labour and that includes using photoshop to create an image for each post so that only leaves generating the images with &lt;a href="https://www.gatsbyjs.org/"&gt;Gatsby&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  JIMP
&lt;/h1&gt;

&lt;p&gt;I wanted to keep the image generation entirely in Gatsby to keep things easier. This meant I needed a JS only image creation library which is where I found &lt;a href="https://www.npmjs.com/package/jimp"&gt;JIMP&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I fire my &lt;code&gt;createImage&lt;/code&gt; function for nodes that I might share like posts, notes and books during the &lt;code&gt;on-create-node&lt;/code&gt; hook.&lt;/p&gt;

&lt;p&gt;This function creates an image for both Facebook and Twitter that I link to through the open graph tags in the templates &lt;code&gt;Helmet&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The images themselves are nothing special just the content background colour, the sites icon, the post date, and the title. Take the one for this post:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jP7s7e66--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://arcath.net/static/e7761fdc1eeb7ad94ab422a50838e4d2/12106/social-image.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jP7s7e66--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://arcath.net/static/e7761fdc1eeb7ad94ab422a50838e4d2/12106/social-image.png" alt="This posts image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code to do this is pretty simple and can be found in the sites source &lt;a href="https://github.com/Arcath/arcath.net-gatsby/blob/master/gatsby/create-page-image.js"&gt;here&lt;/a&gt;. I was surprised how easy this turned out to be.&lt;/p&gt;

&lt;p&gt;Having gatsby generate the images instead is pretty handy. I can keep the images out of the git repository which is already pretty big and I wont have to remember to make sure they commit.&lt;/p&gt;

&lt;p&gt;This is a small feature that most users of the site wont even see but its a nice one to have. I’ve been more and more impressed with Gatsby as I’ve been using it to the point that I now think along with Netlify CMS it can be a complete replacement for WordPress for the School websites I build.&lt;/p&gt;

</description>
      <category>gatsby</category>
    </item>
    <item>
      <title>Netlify CMS on the filesystem with Gatsby</title>
      <dc:creator>Adam Laycock</dc:creator>
      <pubDate>Sat, 19 Jan 2019 21:35:47 +0000</pubDate>
      <link>https://dev.to/arcath/netlify-cms-on-the-filesystem-with-gatsby-2lge</link>
      <guid>https://dev.to/arcath/netlify-cms-on-the-filesystem-with-gatsby-2lge</guid>
      <description>&lt;p&gt;I was looking at &lt;a href="https://www.netlifycms.org/"&gt;Netlify CMS&lt;/a&gt; for a website I was building and I wanted to test it before I put code to repo. Unfortunatley by default Netlify CMS will only let you use git as a backend which is great once the site is launched but when I want to test the CMS or dratically change the config the only way to test it would be to commit code that &lt;em&gt;should&lt;/em&gt; work and then hope. This leaves a bad taste in my mouth, if code is hitting the repo it should pass tests so comitting something that on paper should work doesn't feel right to me.&lt;/p&gt;

&lt;p&gt;Netlify CMS edits the &lt;em&gt;source&lt;/em&gt; files directly normally by commiting to the git repo. I needed a way of making changes to the local file system directly.&lt;/p&gt;

&lt;p&gt;Before making changes to the config I needed to install &lt;a href="https://www.npmjs.com/package/gatsby-plugin-netlify-cms"&gt;gatsby-plugin-netlify-cms&lt;/a&gt; which adds everything you need to get going with Netlify CMS and Gatsby and created &lt;code&gt;static/admin/config.yml&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The important part of the file for this article is the &lt;code&gt;backend&lt;/code&gt; which for me is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;backend&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;github&lt;/span&gt;
  &lt;span class="na"&gt;repo&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Arcath/...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  FS Backend
&lt;/h1&gt;

&lt;p&gt;Enter &lt;a href="https://www.npmjs.com/package/netlify-cms-backend-fs"&gt;netlify-cms-backend-fs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To get this working in Gatsby I needed to make a couple of edits to my &lt;code&gt;gatsby-config.js&lt;/code&gt; to load the fs-api and configure &lt;code&gt;gatsby-plugin-netlify-cms&lt;/code&gt; so that it uses the fs backend.&lt;/p&gt;

&lt;p&gt;First off the entry in the &lt;code&gt;plugins&lt;/code&gt; array needs changing to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`gatsby-plugin-netlify-cms`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;modulePath&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="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/src/cms/init.js`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Or another path if you don't want to create /src/cms/init.js&lt;/span&gt;
    &lt;span class="nx"&gt;enableIdentityWidget&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;publicPath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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;htmlTitle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content Manager&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;manualInit&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;After that I needed to require the file system api from the backend.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;fsApi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;netlify-cms-backend-fs/dist/fs/fs-express-api&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 Gatsby config needs the middleware loading which can be done by adding &lt;code&gt;developMiddleware: fsApi&lt;/code&gt; to the config object.&lt;/p&gt;

&lt;p&gt;To use it in development I added a &lt;code&gt;development_overrides&lt;/code&gt; key to my &lt;code&gt;config.yml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;development_overrides&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;backend&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;file-system&lt;/span&gt;
    &lt;span class="na"&gt;api_root&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;http://localhost:8000/api'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now I have all the config in place I just need to tie it all together with &lt;code&gt;src/cms/init.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;CMS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;init&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;netlify-cms&lt;/span&gt;&lt;span class="dl"&gt;'&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;FileSystemBackend&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;netlify-cms-backend-fs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// If running in development&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODE_ENV&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;development&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="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;CMS_ENV&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;development_overrides&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="c1"&gt;// Set the CMS_ENV to the development_ overrides.&lt;/span&gt;
  &lt;span class="nx"&gt;CMS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;registerBackend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;file-system&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;FileSystemBackend&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Register the FileSystemBackend.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Start NetlifyCMS&lt;/span&gt;
&lt;span class="nx"&gt;init&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This has worked really well for me letting me test and use Netlify CMS on my local machine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Originally posted on my blog &lt;a href="https://arcath.net/2019/01/netlify-cms-on-the-filesystem-with-gatsby"&gt;here&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>netlifycms</category>
      <category>gatsby</category>
    </item>
  </channel>
</rss>
