<?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: Chris</title>
    <description>The latest articles on DEV Community by Chris (@chgldev).</description>
    <link>https://dev.to/chgldev</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%2F19279%2F142e92d1-f000-479d-878e-974d6b3e380c.jpg</url>
      <title>DEV Community: Chris</title>
      <link>https://dev.to/chgldev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chgldev"/>
    <language>en</language>
    <item>
      <title>How to setup pretty import paths in a create-react-app application</title>
      <dc:creator>Chris</dc:creator>
      <pubDate>Mon, 05 Jul 2021 17:00:01 +0000</pubDate>
      <link>https://dev.to/chgldev/how-to-setup-pretty-import-paths-in-a-create-react-app-application-5dck</link>
      <guid>https://dev.to/chgldev/how-to-setup-pretty-import-paths-in-a-create-react-app-application-5dck</guid>
      <description>&lt;h2&gt;
  
  
  Pretty import paths?
&lt;/h2&gt;

&lt;p&gt;We've all seen relative file import paths inside react applications. If you structure your apps like me you end up with terribly long paths to import other components. Auto-import can take care of that for you automatically, but isn't it hard to read and let's be honest, very, very error prone?&lt;/p&gt;

&lt;h2&gt;
  
  
  Webpack aliases
&lt;/h2&gt;

&lt;p&gt;One way to solve this issue is adding webpack aliases. Now if you created your application using the &lt;a href="https://www.npmjs.com/package/create-react-app"&gt;&lt;code&gt;create-react-app&lt;/code&gt; cli&lt;/a&gt;, you will notice that there isn't a webpack config to mess with unless you &lt;a href="https://create-react-app.dev/docs/available-scripts/#npm-run-eject"&gt;eject&lt;/a&gt; it running &lt;code&gt;npm run eject&lt;/code&gt;, which will expose the entire configuration and makes you responsible of maintaining it. I prefer not ejecting my react application because I prefer the ease of use using react-scripts, so there must be another way.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introducing craco
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/@craco/craco"&gt;Create React App Configuration Override (CRACO)&lt;/a&gt; offers a way of overriding or extending configurations like webpack for example. &lt;/p&gt;

&lt;p&gt;Bingo! &lt;/p&gt;

&lt;p&gt;Install it running the following command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i @craco/craco
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next we need to configure craco. We do so adding a craco configuration file. Create the file &lt;code&gt;craco.config.js&lt;/code&gt; in the root of the project and add the following content&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;path&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;path&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;webpack&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;alias&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="s1"&gt;@&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src&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="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;Let me explain how I intend to use this alias. I usually have a &lt;code&gt;src/&lt;/code&gt; folder in the root of the project containing all the components I use in a &lt;code&gt;components/&lt;/code&gt; subfolder. Other folders are helpers under &lt;code&gt;helpers/&lt;/code&gt; or custom hooks &lt;code&gt;hooks/&lt;/code&gt;. The alias I am setting up will point to the &lt;code&gt;src/&lt;/code&gt; folder. So whenever I write &lt;code&gt;import Component from '@/components/myComponent'&lt;/code&gt; it will resolve to &lt;code&gt;'src/components/myComponent'&lt;/code&gt;, independent of the path I am currently work in. &lt;/p&gt;

&lt;p&gt;The last thing to do is to run &lt;code&gt;craco&lt;/code&gt; instead of &lt;code&gt;react-scripts&lt;/code&gt; in our &lt;code&gt;package.json&lt;/code&gt; scripts section:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "scripts": {
    "start": "craco start",
    "build": "craco build",
    "test": "craco test"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will load the craco config for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  ESLint
&lt;/h2&gt;

&lt;p&gt;When using ESLint you will notice red squiggly line whenever you start using the new import paths. This is because ESLint doesn't know how to deal with those. I am also using the import plugin &lt;code&gt;eslint-plugin-import&lt;/code&gt; to keep import order clean and tidy.&lt;/p&gt;

&lt;p&gt;Inside your eslint config add the following block to the &lt;code&gt;settings&lt;/code&gt; key.&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="nx"&gt;settings&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="s1"&gt;import/resolver&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="nl"&gt;alias&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;map&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="s1"&gt;@&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="s1"&gt;./src&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;
      &lt;span class="na"&gt;extensions&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="s1"&gt;.ts&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="s1"&gt;.tsx&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="s1"&gt;.js&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="s1"&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="s1"&gt;.json&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="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 &lt;code&gt;alias&lt;/code&gt; key here will tell ESLint about the alias key we've setup in our webpack config through craco. I also want to import the extensions listed above without typing out the extension, so that's what that part is for.&lt;/p&gt;

&lt;p&gt;If you use the import plugin, don't forget to add that to the &lt;code&gt;extends&lt;/code&gt; key:&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;extends&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="s1"&gt;plugin:react/recommended&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="s1"&gt;plugin:import/recommended&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="s1"&gt;plugin:import/typescript&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;I also use Typescript, see next section on how to add support for aliases.&lt;/p&gt;

&lt;p&gt;Last thing which is entirely optional if you don't care about import order, is to tell the import plugin where we want to place the import statements using aliases. You do so by adding a configuration to the import rule:&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="nx"&gt;rules&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="s1"&gt;import/order&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="s1"&gt;error&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;pathGroups&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;pattern&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@/**&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;group&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;parent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;before&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="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;This tells ESLint that all import paths matching the &lt;code&gt;pattern&lt;/code&gt; key should be treated the same way as parent imports. Adding that last key &lt;code&gt;position&lt;/code&gt; with value &lt;code&gt;'before'&lt;/code&gt; will move them over relative parent imports. You can read about what those keys do in the &lt;a href="https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md"&gt;official docs of eslint-plugin-import&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Typescript (Bonus)
&lt;/h2&gt;

&lt;p&gt;Finally if you are using typescript, we also need to set up alias support as the TS compiler will complain about the alias paths not being valid. &lt;/p&gt;

&lt;p&gt;For that open your &lt;code&gt;tsconfig.json&lt;/code&gt; and add the following:&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;"compilerOptions"&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;span class="nl"&gt;"paths"&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;span class="nl"&gt;"@/*"&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;"./src/*"&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;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;As mentioned before this maps paths like &lt;code&gt;@/*&lt;/code&gt; to my &lt;code&gt;src/&lt;/code&gt; folder.&lt;/p&gt;

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

&lt;p&gt;Completing the steps described above will give you cleaner import paths and reproducible and saner import order. You don't necessarily need the import order, but it's good practice and helps keeping your code more organized.&lt;/p&gt;

</description>
      <category>react</category>
      <category>webpack</category>
      <category>typescript</category>
      <category>eslint</category>
    </item>
    <item>
      <title>Master Vue's render function by creating a custom grid component</title>
      <dc:creator>Chris</dc:creator>
      <pubDate>Wed, 24 Jul 2019 17:44:59 +0000</pubDate>
      <link>https://dev.to/chgldev/master-vue-s-render-function-by-creating-a-custom-grid-component-3gi1</link>
      <guid>https://dev.to/chgldev/master-vue-s-render-function-by-creating-a-custom-grid-component-3gi1</guid>
      <description>&lt;p&gt;For those of you writing Frontend applications with ReactJs, you are probably familiar with &lt;code&gt;render&lt;/code&gt; functions to control what is rendered once the component is ready.&lt;/p&gt;

&lt;p&gt;In Vue you usually go for its &lt;a href="https://vuejs.org/v2/guide/syntax.html"&gt;template solution&lt;/a&gt; to control what is being rendered. It is really powerful and offers lots of &lt;a href="https://vuejs.org/v2/guide/syntax.html"&gt;custom directives&lt;/a&gt;, which are prefixed by a &lt;code&gt;v-&lt;/code&gt;. You can for example conditionally render a DOM node depending on your current state.&lt;/p&gt;

&lt;p&gt;While this already offers a great amount of flexibility, you may sometimes reach for &lt;a href="https://vuejs.org/v2/guide/render-function.html"&gt;Vue's render function&lt;/a&gt; to fully control the html being rendered. Imagine having to apply custom class attributes to children being passed to your custom component.&lt;/p&gt;

&lt;p&gt;This is exactly what we will be going for in this tutorial.&lt;/p&gt;

&lt;p&gt;I will be utilizing &lt;a href="https://tailwindcss.com/docs/what-is-tailwind/"&gt;Tailwind CSS&lt;/a&gt;, as it offers everything we will need for a basic flexbox grid. I found the class names it is using very intuitive and its utility-first approach goes very well with Vue components.&lt;/p&gt;

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

&lt;p&gt;Using render gives you control over a function that is called &lt;code&gt;createElement&lt;/code&gt;, or &lt;code&gt;h&lt;/code&gt; for short.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hint&lt;/strong&gt;: In this tutorial I will be naming the &lt;code&gt;createElement&lt;/code&gt; function &lt;code&gt;h&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A very simple example of a render function can look like the following:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The example above will render an h1 element with the content of "This is a heading". Pretty straightforward.&lt;/p&gt;

&lt;h2&gt;
  
  
  createElement syntax
&lt;/h2&gt;

&lt;p&gt;So let's have a look of how createElement works and what can be supplied.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;As you can see, the function accepts 3 arguments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The HTML tag name that should be rendered&lt;/li&gt;
&lt;li&gt;The data object, which defines how to configure this element. You can find more information about it &lt;a href="https://vuejs.org/v2/guide/render-function.html#The-Data-Object-In-Depth"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The children&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With this information, let's create a basic grid component.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;This component doesn't do much yet. It simply renders a div element with a class of "flex" and no children.&lt;/p&gt;

&lt;p&gt;I would like the grid to render anything what I pass in. Vue uses the concept of slots for this. To read the default prop in Vue, you can use &lt;code&gt;this.$slots.default&lt;/code&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Great, this will render the children the pass into the grid component.&lt;/p&gt;

&lt;p&gt;So how do we make the grid more flexible? We would like to the tell the grid of many columns it consists of. This way we know which class names to apply. So it sounds like we need a prop in our grid component:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;I am using prop validation here, to make sure we are not using any arbitrary class name that the default tailwind configuration doesn't support. By default it uses w-1/2 through w-1/6.&lt;/p&gt;

&lt;h2&gt;
  
  
  Apply the class names to children
&lt;/h2&gt;

&lt;p&gt;As we don't want to modify the children directly, we will add an additional wrapper around each child and apply the tailwind class names to them. This way we don't have to mess with the child elements directly, which might potentially mess them up:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;This reads as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a &lt;code&gt;div&lt;/code&gt; element with class "flex"&lt;/li&gt;
&lt;li&gt;Map over the default slot and for each child create a new &lt;code&gt;div&lt;/code&gt; with a class depending on the &lt;code&gt;cols&lt;/code&gt; prop and put the actual child inside of that.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example usage
&lt;/h2&gt;

&lt;p&gt;So how do you actually use this component in your application?&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;To make clear what is rendered, this is the final HTML:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Please note that passing in &lt;code&gt;:cols="3"&lt;/code&gt;, but only 2 children will mess up the layout. You could easily account for that by checking before you render. Depending on your requirements, you could not render nothing or just spit out a console.error/warning.&lt;/p&gt;

&lt;h2&gt;
  
  
  Troubleshooting
&lt;/h2&gt;

&lt;p&gt;I noticed &lt;code&gt;this.$slot.default&lt;/code&gt; consisting of 3 children instead of the expected 2. This was because there has been a space character somewhere between the components. To account for this I added an additional filter before iterating the children:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


</description>
      <category>vue</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Getting Prettier, Eslint and Vscode to work together</title>
      <dc:creator>Chris</dc:creator>
      <pubDate>Wed, 24 Jul 2019 13:55:40 +0000</pubDate>
      <link>https://dev.to/chgldev/getting-prettier-eslint-and-vscode-to-work-together-3678</link>
      <guid>https://dev.to/chgldev/getting-prettier-eslint-and-vscode-to-work-together-3678</guid>
      <description>&lt;p&gt;For quite a while I've tried getting Prettier, Eslint and Vscode to work together, but never found a solution that satisfied me. Now, as I'm working on a new React project in my day job, I finally found some time to make it work. &lt;/p&gt;

&lt;h2&gt;
  
  
  Wait what are Eslint and Prettier?
&lt;/h2&gt;

&lt;p&gt;Eslint is a javascript linter that can help you find syntax or other errors. Eslint can be extended by plugging in pre-defined configs or completely configuring it yourself. Paired with the plugin for vscode, it can show you errors as you type.&lt;/p&gt;

&lt;p&gt;Prettier is a code formatter for &lt;a href="https://prettier.io/docs/en/index.html"&gt;quite a few languages&lt;/a&gt;, including javascript. You can have code being automatically or optionally formatted with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;I assume you have basic knowledge about NPM and Vscode, as I won't cover it here. You need to have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Vscode installed&lt;/li&gt;
&lt;li&gt;NodeJS and NPM installed&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Install Vscode plugins
&lt;/h2&gt;

&lt;p&gt;First of all install the Vscode plugins &lt;a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint"&gt;ESLint&lt;/a&gt; and &lt;a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode"&gt;Prettier - Code formatter&lt;/a&gt; and make sure they're enabled.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install dependencies
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -D eslint eslint-config-prettier eslint-plugin-prettier prettier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setup the config files
&lt;/h2&gt;

&lt;p&gt;Create an &lt;code&gt;.eslintrc&lt;/code&gt; file in your project root.&lt;/p&gt;

&lt;p&gt;In here we basically tell Eslint to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Extend from the recommended prettier config&lt;/li&gt;
&lt;li&gt;Register the Prettier plugin we installed&lt;/li&gt;
&lt;li&gt;Show Prettier errors as errors
&lt;/li&gt;
&lt;/ul&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;"extends"&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;span class="s2"&gt;"plugin:prettier/recommended"&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;span class="nl"&gt;"plugins"&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;"prettier"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;

  &lt;/span&gt;&lt;span class="nl"&gt;"rules"&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;span class="nl"&gt;"prettier/prettier"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"error"&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;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;&lt;strong&gt;Note&lt;/strong&gt;: Your eslint config can include many more rules. I'm keeping it simple and easy to grasp.&lt;/p&gt;

&lt;p&gt;Next create a &lt;code&gt;.prettierrc&lt;/code&gt; file in your project root. &lt;/p&gt;

&lt;p&gt;You can tweak these settings, or &lt;a href="https://prettier.io/docs/en/options.html"&gt;add new ones&lt;/a&gt; as you like:&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;"semi"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"singleQuote"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"tabWidth"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"useTabs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&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;h2&gt;
  
  
  Enable formatOnSave in Vscode
&lt;/h2&gt;

&lt;p&gt;Look for &lt;code&gt;formatOnSave&lt;/code&gt; and check the checkbox, or add this line to &lt;code&gt;settings.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"editor.formatOnSave": true,
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Try it out
&lt;/h2&gt;

&lt;p&gt;If you kept the &lt;code&gt;.prettierrc&lt;/code&gt; file like above, Vscode should now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;indent your code with 2 spaces&lt;/li&gt;
&lt;li&gt;use single quotes instead of double &lt;/li&gt;
&lt;li&gt;add semicolons add the end of each line&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're having trouble try restarting Vscode.&lt;/p&gt;

</description>
      <category>prettier</category>
      <category>eslint</category>
      <category>vscode</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Hi, I'm Chris ðŸ‘ ”ðŸ’»</title>
      <dc:creator>Chris</dc:creator>
      <pubDate>Fri, 19 May 2017 05:24:05 +0000</pubDate>
      <link>https://dev.to/chgldev/hi-im-chris-</link>
      <guid>https://dev.to/chgldev/hi-im-chris-</guid>
      <description>&lt;p&gt;I have been coding for 5 years.&lt;/p&gt;

&lt;p&gt;You can find me on Twitter as &lt;a href="https://twitter.com/chgldev" rel="noopener noreferrer"&gt;@chgldev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I mostly program in these languages: Javascript, Perl, PHP.&lt;/p&gt;

&lt;p&gt;I am currently learning more about VueJS .&lt;/p&gt;

&lt;p&gt;Nice to meet you.&lt;/p&gt;

</description>
      <category>introduction</category>
    </item>
  </channel>
</rss>
