<?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>Forem: Rei Yoshizawa</title>
    <description>The latest articles on Forem by Rei Yoshizawa (@reiyszw).</description>
    <link>https://forem.com/reiyszw</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%2F115023%2F90ae6c21-492e-4543-b0cb-5e1b9a7a22a5.jpg</url>
      <title>Forem: Rei Yoshizawa</title>
      <link>https://forem.com/reiyszw</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/reiyszw"/>
    <language>en</language>
    <item>
      <title>How to Properly Use $refs for DOM manipulation in Vue.js</title>
      <dc:creator>Rei Yoshizawa</dc:creator>
      <pubDate>Tue, 07 Jul 2020 05:41:58 +0000</pubDate>
      <link>https://forem.com/reiyszw/how-to-properly-use-refs-for-dom-manipulation-in-vue-js-18i8</link>
      <guid>https://forem.com/reiyszw/how-to-properly-use-refs-for-dom-manipulation-in-vue-js-18i8</guid>
      <description>&lt;p&gt;Vue is one of the most beginner-friendly JavaScript frameworks I have ever used before. I have been using Vue for almost 2 years and I have no stress about creating and updating the Vue component.&lt;/p&gt;

&lt;p&gt;However, right after I started using Vue I wondered how we could manipulate DOM inside a Vue file. This issue will be resolved by using &lt;code&gt;$refs&lt;/code&gt; to access DOM. Many developers might get the same issue so that I decided to write today's blog post.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is $refs and ref
&lt;/h2&gt;

&lt;p&gt;So, I refer to it from the official Vue documentation.&lt;/p&gt;

&lt;h3&gt;
  
  
  $refs
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://gyazo.com/a70464bd944aea94dc29cee38df61580"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9xy20oOm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.gyazo.com/a70464bd944aea94dc29cee38df61580.png" alt="Image from Gyazo" width="713" height="255"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://vuejs.org/v2/api/#vm-refs"&gt;https://vuejs.org/v2/api/#vm-refs&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  ref
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;ref&lt;/code&gt; is used to register a reference to an element or a child component. The reference will be registered under the parent component’s &lt;code&gt;$refs&lt;/code&gt; object. If used on a plain DOM element, the reference will be that element; if used on a child component, the reference will be component instance: &lt;a href="https://vuejs.org/v2/api/#ref"&gt;https://vuejs.org/v2/api/#ref&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- vm.$refs.p will be the DOM node --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;ref=&lt;/span&gt;&lt;span class="s"&gt;"p"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;hello&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- vm.$refs.child will be the child component instance --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;child-component&lt;/span&gt; &lt;span class="na"&gt;ref=&lt;/span&gt;&lt;span class="s"&gt;"child"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/child-component&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  But, I can't understand it by checking the official documentation...
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/fstgqv79jrn0KnscKo/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/fstgqv79jrn0KnscKo/giphy.gif" alt="Wait What Idk GIF by Originals" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have attached the details of both &lt;code&gt;$refs&lt;/code&gt; and &lt;code&gt;ref&lt;/code&gt; introduced by the official Vue.js Documentation. However, These are not kind enough for most of the developers who have never experienced using Vue.js.&lt;/p&gt;

&lt;p&gt;That's why hopefully this blog post will be a valuable source to help to understand the core concepts about &lt;code&gt;$refs&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use $refs and ref?
&lt;/h2&gt;

&lt;p&gt;To clarify the difference between &lt;code&gt;$refs&lt;/code&gt; and &lt;code&gt;ref&lt;/code&gt;, &lt;code&gt;$refs&lt;/code&gt; is the object and all the DOM elements are contained within this object.&lt;/p&gt;

&lt;p&gt;But, &lt;code&gt;$refs&lt;/code&gt; itself is useless.  &lt;code&gt;ref&lt;/code&gt; should always be registered in the HTML code to take effect &lt;code&gt;$refs&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For example, to access to the DOM of the element which is set &lt;code&gt;ref="slider"&lt;/code&gt;, either &lt;code&gt;this.$refs.slider&lt;/code&gt; or &lt;code&gt;this.$refs['slider']&lt;/code&gt; can be accessible to DOM. &lt;/p&gt;

&lt;p&gt;In order to confirm the DOM of the one you are supposed to access, &lt;strong&gt;you can write &lt;code&gt;console.log(this.$refs.slider)&lt;/code&gt; in mounted().&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Then, the result of DOM will be displayed in the console of the dev tool as below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gyazo.com/51e50576f13e29066d99b5bd914bdeba"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YEQZM4GX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.gyazo.com/51e50576f13e29066d99b5bd914bdeba.png" alt="Image from Gyazo" width="588" height="86"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gyazo.com/a63b56bc9002c2029249ff418b9aa3c5"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_TDXAwJF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.gyazo.com/a63b56bc9002c2029249ff418b9aa3c5.png" alt="Image from Gyazo" width="570" height="492"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Possible to DOM access using vanilla JavaScript, However...
&lt;/h2&gt;

&lt;p&gt;Until now, I have explained about &lt;code&gt;$refs&lt;/code&gt; for DOM access. But actually, you can even manipulate DOM by using vanilla JavaScript like &lt;code&gt;document.querySelector('test')&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you only need to manipulate DOM of the current component, You could use vanilla JavaScript instead of &lt;code&gt;$refs&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The reason why &lt;code&gt;$refs&lt;/code&gt; can be prepared for Vue is that with &lt;code&gt;$refs&lt;/code&gt; we can &lt;strong&gt;access the DOM of a parent and child component.&lt;/strong&gt; Moreover, even DOM of the plugin will be accessible by &lt;code&gt;$refs&lt;/code&gt;. With only vanilla JavaScript, It won't be possible. &lt;/p&gt;

&lt;h2&gt;
  
  
  2 things you should be considered before using $refs
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Don't overuse $refs
&lt;/h3&gt;

&lt;p&gt;Before adding &lt;code&gt;$refs&lt;/code&gt; into the component code, Please take a deep breath and consider that you do really need &lt;code&gt;$refs&lt;/code&gt; to achieve the expected behavior. &lt;/p&gt;

&lt;p&gt;According to the basic concept of Vue.js, we should use Vue's features as much as possible &lt;strong&gt;rather than directly manipulate DOM.&lt;/strong&gt; That's how Vue is welcomed for the developers. We were all fatigued direct manipulation of DOM using jQuery.&lt;/p&gt;

&lt;h3&gt;
  
  
  Don't forget adding &lt;code&gt;ref&lt;/code&gt; to the element
&lt;/h3&gt;

&lt;p&gt;To be honest, I have had this mistake several times. It looks so amateur mistake but It has happened it anyway. To make &lt;code&gt;$refs&lt;/code&gt; be applied to the component, &lt;strong&gt;the &lt;code&gt;ref&lt;/code&gt; must be set to the target element&lt;/strong&gt; you want to call out.&lt;/p&gt;

&lt;p&gt;Note that &lt;code&gt;$refs&lt;/code&gt; and &lt;code&gt;ref&lt;/code&gt; are the pair used for DOM manipulation. &lt;/p&gt;

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

&lt;p&gt;I personally don't prefer to use or update the code which &lt;code&gt;$refs&lt;/code&gt; are included in several parts. However, sometimes It happens for the Vue developers.&lt;/p&gt;

&lt;p&gt;In addition, getting familiar with the specific feature of the daily used technology will eventually help to save your time a lot.&lt;/p&gt;

&lt;p&gt;So hopefully, this blog post is worth reading and gaining someone's knowledge. Cheers for all the devs, Thanks!&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Vue $listeners, $attrs are the handy way for passing event and data</title>
      <dc:creator>Rei Yoshizawa</dc:creator>
      <pubDate>Tue, 30 Jun 2020 04:24:45 +0000</pubDate>
      <link>https://forem.com/reiyszw/vue-listeners-attrs-are-the-handy-way-for-passing-event-and-data-323e</link>
      <guid>https://forem.com/reiyszw/vue-listeners-attrs-are-the-handy-way-for-passing-event-and-data-323e</guid>
      <description>&lt;p&gt;Today, I will explain about &lt;strong&gt;$listeners&lt;/strong&gt; and &lt;strong&gt;$attrs&lt;/strong&gt; of Vue. These features may probably be underestimated among developers despite the handy features since there is not enough information on the internet.&lt;/p&gt;

&lt;p&gt;Try to search &lt;code&gt;$listeners vue&lt;/code&gt; &lt;code&gt;$attrs vue&lt;/code&gt;. You won't grasp the whole concept of $listeners and $attrs by reading and watching the information you find. I am the one who has been feeling that way. So I decided to contribute to helping other developers who can't fully understand that.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is $listeners? How is it used?
&lt;/h2&gt;

&lt;p&gt;So, the code will be below when the click event is required. Pretty basic code of handling event. This time &lt;code&gt;clickHanlder&lt;/code&gt; is invoked when the button is clicked. Nothing is complicated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;v-on:click=&lt;/span&gt;&lt;span class="s"&gt;"clickHanlder"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But how about this situation?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;inherited-child&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click=&lt;/span&gt;&lt;span class="s"&gt;"sayHello"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/inherited-child&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this situation, the click event is not invoked in &lt;code&gt;inherited-child&lt;/code&gt;. To make it possible, click event here should be passed to &lt;code&gt;inherited-child&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding $listeners will resolve this problem.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;inherited-child&lt;/span&gt; &lt;span class="na"&gt;v-on=&lt;/span&gt;&lt;span class="s"&gt;"$listeners"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/inherited-child&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, &lt;code&gt;sayHello&lt;/code&gt; function is successfully invoked when clicked. This is very straightforward. If you are a Vue developer, $listeners can be used more casually.&lt;/p&gt;

&lt;h2&gt;
  
  
  $listeners and v-bind="$attrs"
&lt;/h2&gt;

&lt;p&gt;$listeners is used for passing the event to be invoked in a child component. As similar to $listeners, Setting v-bind="$attrs" in a parent component with props can be also used for passing data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;inherited-child&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"1"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"rei"&lt;/span&gt; &lt;span class="na"&gt;v-bind=&lt;/span&gt;&lt;span class="s"&gt;"$attrs"&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click=&lt;/span&gt;&lt;span class="s"&gt;"sayHello"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/inherited-child&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both &lt;code&gt;id&lt;/code&gt; and &lt;code&gt;name&lt;/code&gt; props are passed to &lt;code&gt;inherited-child&lt;/code&gt; from the parent component. And the key point is it is not necessary to receive props in the child component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt; &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Child&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
      $attrs -&amp;gt; {{$attrs.id}}, {{$attrs.name}}
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What kind of situation $listeners and $attrs would be useful?
&lt;/h2&gt;

&lt;p&gt;I have explained about $listeners and $attrs by using an example of the parent&amp;amp;child components.&lt;/p&gt;

&lt;p&gt;However, these can be more useful when you need to &lt;strong&gt;pass the event or data to a deeper hierarchy.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For example, In the situation below if we need to pass the event and data from &lt;code&gt;A component&lt;/code&gt; to &lt;code&gt;C component&lt;/code&gt;, $listeners and $attrs can be set in &lt;code&gt;B component&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;A component -&amp;gt; B component -&amp;gt; C component&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Of course, Setting emit or props in the B component will also make it work exactly the same. However, It bothers you adding them in both B and C components. &lt;/p&gt;

&lt;p&gt;In addition, That's not readable and also confuse the developers to update in the future. If the project has Vuex installed we could rely on storing data using that but otherwise, you could probably have an opportunity using $listeners and $attrs sometime soon.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclution
&lt;/h2&gt;

&lt;p&gt;Vue has a lot of useful features but not all of the details are introduced carefully. Since utilizing features makes the project more concise, I will keep publishing these things to encourage especially beginners to write code more simple and clean. Thanks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reference
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://jsfiddle.net/nw2r8d63"&gt;https://jsfiddle.net/nw2r8d63&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Discard File Changes by VSCode Instead of git stash </title>
      <dc:creator>Rei Yoshizawa</dc:creator>
      <pubDate>Thu, 25 Jun 2020 01:14:30 +0000</pubDate>
      <link>https://forem.com/reiyszw/discard-file-changes-by-vscode-instead-of-git-stash-47h6</link>
      <guid>https://forem.com/reiyszw/discard-file-changes-by-vscode-instead-of-git-stash-47h6</guid>
      <description>&lt;p&gt;This is a small tip for anyone who uses git command daily. &lt;/p&gt;

&lt;p&gt;How do you manage when you don't want file changes to be staged but need to checkout another branch? &lt;/p&gt;

&lt;p&gt;I have usually cleared a branch by using git stash. git stash is not for discarding unnecessary files but for storing the file changes for just a temporary moment.&lt;/p&gt;

&lt;p&gt;I knew that this way would not be ideal but didn't know the proper way of that.&lt;/p&gt;

&lt;p&gt;Lately, I have found a much simple solution to discard file changes. Everyone should use that.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gyazo.com/db4f6dc2f262555cdced2523140b9694" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.gyazo.com%2Fdb4f6dc2f262555cdced2523140b9694.gif" alt="Image from Gyazo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Discard file changes
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Use Visual Studio Code&lt;/li&gt;
&lt;li&gt;Select &lt;code&gt;Sorce Control&lt;/code&gt; in the left option (with shortcut key, Control + Shift + G)&lt;/li&gt;
&lt;li&gt;Click &lt;code&gt;Discard All Changes&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's it! If you have specific files to discard, You only need to select that file.&lt;/p&gt;

&lt;p&gt;I'm not familiar with this type of superpower of VSCode. If you know about VSCode tips to improve productivity, Please let me know. I would really appreciate it. Thanks!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>productivity</category>
      <category>git</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Dynamic Components is A Great Vuejs Feature</title>
      <dc:creator>Rei Yoshizawa</dc:creator>
      <pubDate>Tue, 23 Jun 2020 00:15:54 +0000</pubDate>
      <link>https://forem.com/reiyszw/dynamic-components-is-a-great-vuejs-feature-2mo1</link>
      <guid>https://forem.com/reiyszw/dynamic-components-is-a-great-vuejs-feature-2mo1</guid>
      <description>&lt;p&gt;I have been using Vue for over 1.5 years now. I don't think I have known all the Vue features but I can at least share some knowledge about Vue. &lt;/p&gt;

&lt;p&gt;Today's topic is about &lt;strong&gt;Dynamic Components&lt;/strong&gt; of Vuejs. In my understanding, this feature is not widely taught in tutorials. However, This will be helpful to make the project more scalable and maintainable. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is Dynamic Components?
&lt;/h2&gt;

&lt;p&gt;As &lt;a href="https://vuejs.org/v2/guide/components.html#Dynamic-Components"&gt;It's mentioned in the official Vuejs Documentation&lt;/a&gt;, Dynamic Components provide a simple way to &lt;strong&gt;switch dynamically each component.&lt;/strong&gt; Since we don't need to add an either &lt;code&gt;v-if&lt;/code&gt; or &lt;code&gt;v-show&lt;/code&gt;, Code would be more concise and readable.&lt;/p&gt;

&lt;p&gt;The gif image below lets you convince how Dynamic Components is a useful feature.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x1uuSX7u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/ac855e42cb30f5daea4ced8625a87624.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x1uuSX7u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://i.gyazo.com/ac855e42cb30f5daea4ced8625a87624.gif" alt="alt text" title="Dynamic Components tabs" width="352" height="84"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see the above code &lt;a href="https://vuejs.org/v2/guide/components.html#Dynamic-Components"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The basic concept is simple. In this case, &lt;code&gt;currentTabComponent&lt;/code&gt; is a computed property that is updated every time the result of this property is changed. You can see how it works in the code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;component&lt;/span&gt; &lt;span class="na"&gt;v-bind:is=&lt;/span&gt;&lt;span class="s"&gt;"currentTabComponent"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"tab"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/component&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;component&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tab-home&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;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;div&amp;gt;Home component&amp;lt;/div&amp;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;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;component&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tab-posts&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;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;div&amp;gt;Posts component&amp;lt;/div&amp;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;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;component&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tab-archive&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;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;div&amp;gt;Archive component&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;

      &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;el&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#dynamic-component-demo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;currentTab&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Home&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;tabs&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;Home&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;Posts&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;Archive&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;computed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;currentTabComponent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tab-&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentTab&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&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;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Multiple modals -&amp;gt; 1 modal + dynamic components
&lt;/h2&gt;

&lt;p&gt;Dynamic Components itself is a simple feature as I have already explained it. No complicated trick involved. What I would like to share with you here is my specific story using this feature in the project.&lt;/p&gt;

&lt;p&gt;So, I have recently had a task to update a canceling flow of our software. I won't tell the detail of that but note that the previous canceling flow was made by using multiple modals. &lt;/p&gt;

&lt;p&gt;Although there were no bugs in it, I could have found a lot of duplicate codes. So I decided to switch this to only have 1 modal with dynamic components. &lt;/p&gt;

&lt;p&gt;As a result, All the &lt;strong&gt;duplicate codes were gone&lt;/strong&gt; and made it more readable. Less code, more maintainable. I think I have successfully completed the task.&lt;/p&gt;

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

&lt;p&gt;Vue has various useful features to help develop more easily and keep adding great features constantly. I would like to share some techniques more and more. &lt;/p&gt;

&lt;p&gt;I hope that this article would help your developer's life. Please ask me if you have any questions. Also Please let me know if you have some interesting thoughts about this feature or other features. Thanks!&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
      <category>frontend</category>
      <category>webdev</category>
    </item>
    <item>
      <title>18 Basic Git Commands Beginners Must Learn </title>
      <dc:creator>Rei Yoshizawa</dc:creator>
      <pubDate>Tue, 16 Jun 2020 05:20:49 +0000</pubDate>
      <link>https://forem.com/reiyszw/18-basic-git-commands-beginners-must-learn-hc3</link>
      <guid>https://forem.com/reiyszw/18-basic-git-commands-beginners-must-learn-hc3</guid>
      <description>&lt;p&gt;Understanding perfectly about Git must be almost impossible. I use Git command almost every day and still have the massive amount of Git commands I have never known about. when I get stuck in the errors related to Git in terminal then I just ask the internet. Fortunately, almost all of the problem which occurs to us have a solution on the internet.&lt;/p&gt;

&lt;p&gt;What I want to say to you the most in this article (especially for the beginner developers) is that don't get overwhelmed by looking over the Git command list. I have recently heard the 80 20 rule in many different media. In that idea, It says that basically 20% of your activity will accomplish 80% of your objective. The idea can be totally applied to the Git command.&lt;/p&gt;

&lt;p&gt;I even feel like I have only used less than 20% of Git commands. It means that you just have to learn a few Git commands. Now, are you feeling so relieved? In this article, I will show you the very basic Git commands you use on a daily basis as a developer.&lt;/p&gt;

&lt;h2&gt;
  
  
  git clone 
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git clone &amp;lt;url&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command literally downloads the project as a clone in your folder. So you can work on the same project with your team members. &lt;/p&gt;

&lt;h2&gt;
  
  
  git branch
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It simply shows all the branches you have ever created. The branch with the mark &lt;code&gt;*&lt;/code&gt; attached at the beginning of the sentence is the one you are currently working on.&lt;/p&gt;

&lt;h2&gt;
  
  
  git checkout 
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git checkout &amp;lt;branch name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will switch you to the branch you want to work on. Note that you don't leave the branch with the unstaged commits. Either complete &lt;code&gt;git commit&lt;/code&gt; or &lt;code&gt;git stash&lt;/code&gt; to clear it out in the branch before switching. That will help make the branch without unexpected errors.&lt;/p&gt;

&lt;h2&gt;
  
  
  git checkout -b 
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; &amp;lt;new branch name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can achieve the exact same thing when you type &lt;code&gt;git branch &amp;lt;new branch name&amp;gt;&lt;/code&gt; then &lt;code&gt;git checkout &amp;lt;new branch name&amp;gt;&lt;/code&gt;. &lt;code&gt;git checkout -b &amp;lt;new branch name&amp;gt;&lt;/code&gt; is just a short version of these commands. Developers love the way more productive no matter what. So why not using the command line of 1 line instead of 2 lines.&lt;/p&gt;

&lt;h2&gt;
  
  
  git add .
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command moves all the unstaged files to be staged. But note that these files which were updated need to be committed with &lt;code&gt;git commit&lt;/code&gt; . Always remember you choose which changed files should be staged first then commit with the message what kind of changes is included within these changed files. &lt;/p&gt;

&lt;h2&gt;
  
  
  git add 
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git add &amp;lt;file name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;git add &amp;lt;file name&amp;gt;&lt;/code&gt; helps you choose the specific changed file to be staged. I just introduced about  &lt;code&gt;git add .&lt;/code&gt; as if the command is the only method to move the files to be staged but It's not. &lt;/p&gt;

&lt;p&gt;With &lt;code&gt;git add &amp;lt;file name&amp;gt;&lt;/code&gt;, It can avoid including the files which were accidentally updated with some reason. The reviewer feels so secured and happy to see the only updated files that you would like the reviewer to check without spending some time to figure out which files were actually updated.&lt;/p&gt;

&lt;h2&gt;
  
  
  git commit -m"message"
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt;&lt;span class="s2"&gt;"message"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Obviously this command is the essence of git commands. Developers use the version control system such as Git to update and store the data in an efficient way. &lt;code&gt;git commit -m"message"&lt;/code&gt; commits all the staged files to be ready for pushing. &lt;/p&gt;

&lt;p&gt;However, If you care about the quality of the commit messages you make, &lt;code&gt;git commit -m"message"&lt;/code&gt; is not the only way.&lt;/p&gt;

&lt;h2&gt;
  
  
  git commit
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of heavily using &lt;code&gt;git commit -m&lt;/code&gt; you better use &lt;code&gt;git commit&lt;/code&gt; to create the solid and helpful commit messages to other developers.&lt;/p&gt;

&lt;p&gt;Once you use &lt;code&gt;git commit&lt;/code&gt;, the intimidating message is appeared. Don't worry. You can write a commit message with the detail information. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click &lt;code&gt;i&lt;/code&gt; to insert the message&lt;/li&gt;
&lt;li&gt;After writing a commit message, select &lt;code&gt;shift + :&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Then select &lt;code&gt;wq&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everything goes well if you follow the above order. &lt;/p&gt;

&lt;p&gt;You may not notice how the commit messages are important to work as a team, and how each great commit messages helps the teams by keeping the helpful commit messages to the future team members and also yourself in the future.&lt;/p&gt;

&lt;p&gt;Believe me, It's worth it.&lt;/p&gt;

&lt;h2&gt;
  
  
  git status
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command may be the most frequently used within the Git commands. The command helps you in which files are updated and also currently on stage, ready to commit. Before using &lt;code&gt;git add&lt;/code&gt; or &lt;code&gt;git commit&lt;/code&gt; commands, It would be helpful to confirm which files are updated or on stage.&lt;/p&gt;

&lt;h2&gt;
  
  
  git stash
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git stash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sometimes you need to switch a branch to another one in the middle of working on some changes in the current branch. And your change is not completed, don't want to commit with this incompleted changes. if so, &lt;code&gt;git stash&lt;/code&gt; let the current change on hold so you can go back to where you were working on whenever you want.&lt;/p&gt;

&lt;h2&gt;
  
  
  git stash list
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git stash list 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can check all the stash you have already saved.&lt;/p&gt;

&lt;h2&gt;
  
  
  git branch -d
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git branch &lt;span class="nt"&gt;-d&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you finish updating the specific task, the branch might be useless. To delete the branch you simply use&lt;code&gt;git branch -d&lt;/code&gt;. If your branch has already been pushed and merged into the remote branch, It works.&lt;/p&gt;

&lt;h2&gt;
  
  
  git branch -D
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git branch &lt;span class="nt"&gt;-D&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As same as the previous command, This command is used for deleting a branch. This command works well regardless of its push and merge status.&lt;/p&gt;

&lt;h2&gt;
  
  
  git remote add  
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git remote add &amp;lt;remote name&amp;gt; &amp;lt;url&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In stead of the remote setting in Git, There is no way to send pull request to an existing GitHub repository. Set the remote url using &lt;code&gt;git remote add&lt;/code&gt;. For instance, when you need an origin as a new remote you can type &lt;code&gt;git remote add origin &amp;lt;url&amp;gt;&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Without a remote setting in Git, There is no way to send a pull request to an existing GitHub repository. Set the remote URL using &lt;code&gt;git remote add&lt;/code&gt;. For instance, when you need an origin as a new remote you can use the command with &lt;code&gt;git remote add origin &amp;lt;url&amp;gt;&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;In addition to adding your own GitHub URL, It would be useful to add the other team member's GitHub URL as a remote directory, especially for a code review. Just pull your team member's branch and test it out in the local environment. &lt;/p&gt;

&lt;h2&gt;
  
  
  git remote -v
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git remote &lt;span class="nt"&gt;-v&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can check all the remote URLs using this command.&lt;/p&gt;

&lt;h2&gt;
  
  
  git push  
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git push &amp;lt;remote name&amp;gt; &amp;lt;branch name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After completing the commits, Just push to the remote URL. &lt;/p&gt;

&lt;h2&gt;
  
  
  git pull  
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git pull &amp;lt;remote name&amp;gt; &amp;lt;branch name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As I mentioned about pulling the team member's remote branch in &lt;code&gt;git remote add &amp;lt;remote name&amp;gt; &amp;lt;url&amp;gt;&lt;/code&gt;, &lt;code&gt;git pull&lt;/code&gt; pulls the target branch. So you will have the same code that the target branch owns. &lt;/p&gt;

&lt;h2&gt;
  
  
  git cherry-pick 
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;git cherry-pick &amp;lt;commit&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When PR has plenty of commits and you don't want all the commits to be included in PR, &lt;code&gt;git cherry-pick&lt;/code&gt; will be helpful. At first, Create the new branch. Then &lt;code&gt;git cherry-pick &amp;lt;commit&amp;gt;&lt;/code&gt;. After that that commit will be included in the branch you are working on.&lt;/p&gt;

&lt;p&gt;This is a very useful command. It will save time especially when you struggle to fix the uncountable merge conflicts.&lt;/p&gt;

&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;What I wanted to let you guys know in this article is that you don't need to worry about the complexity of Git more than necessary. I know Git is intimidating. I only know and use the limited Git commands at work but I'm still alive in this extremely fast speed industry.&lt;/p&gt;

&lt;p&gt;Get a basic understanding of Git at first. Even if you encounter any issues, you can resolve most of them searching on the internet, I swear. Or Just ask your team members who are knowledgeable about Git.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>git</category>
      <category>github</category>
      <category>developer</category>
    </item>
    <item>
      <title>I Prefer Using CSS Grid to Flexbox</title>
      <dc:creator>Rei Yoshizawa</dc:creator>
      <pubDate>Tue, 02 Jun 2020 01:19:11 +0000</pubDate>
      <link>https://forem.com/reiyszw/i-prefer-using-css-grid-to-flexbox-52fl</link>
      <guid>https://forem.com/reiyszw/i-prefer-using-css-grid-to-flexbox-52fl</guid>
      <description>&lt;p&gt;As a frontend developer, The way we achieve the layout of each section is significantly important. In other words, if you fully understand how to achieve the layout using CSS accurately and quickly, you will not encounter a big hurdle in your work in most cases.&lt;/p&gt;

&lt;p&gt;In this article, I will share my knowledge about CSS Grid compared to Flexbox. The CSS Grid information is accessible in many blog posts, Youtube videos, tutorials, etc. I will try to focus on explaining that in a simple way as much as possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the difference between CSS Grid and Flexbox
&lt;/h2&gt;

&lt;p&gt;CSS Grid is a two-dimensional system and Flexbox is one dimensional. Although Flexbox has the restriction to control the layout only for one dimensional, with CSS Grid you can easily set the position of items no matter how the layout is complicated.&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%2Fgyazo.com%2F4dc28e70057aa4c9a9640ea12b21fe51.gif" 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%2Fgyazo.com%2F4dc28e70057aa4c9a9640ea12b21fe51.gif" alt="Example of CSS Grid"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can achieve this layout with only 3 lines of CSS code using CSS Grid. I will show you the code for the above gif&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.images&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;auto-fill&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minmax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;400px&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="py"&gt;grid-gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;32px&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"images"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;article&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://picsum.photos/400/225?random=1"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;title&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;ultrices dui sapien eget mi proin sed libero enim sed faucibus turpis&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/article&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;article&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://picsum.photos/400/225?random=2"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;title&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;ultrices dui sapien eget mi proin sed libero enim sed faucibus turpis&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/article&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;article&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://picsum.photos/400/225?random=3"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;title&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;ultrices dui sapien eget mi proin sed libero enim sed faucibus turpis&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/article&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;article&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://picsum.photos/400/225?random=4"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;title&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;ultrices dui sapien eget mi proin sed libero enim sed faucibus turpis&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/article&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;article&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://picsum.photos/400/225?random=5"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;title&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;ultrices dui sapien eget mi proin sed libero enim sed faucibus turpis&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/article&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;article&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://picsum.photos/400/225?random=6"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;title&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;ultrices dui sapien eget mi proin sed libero enim sed faucibus turpis&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/article&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;article&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://picsum.photos/400/225?random=7"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;title&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;ultrices dui sapien eget mi proin sed libero enim sed faucibus turpis&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/article&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;article&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://picsum.photos/400/225?random=8"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;title&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;ultrices dui sapien eget mi proin sed libero enim sed faucibus turpis&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/article&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's possible to make the exact same layout using Flexbox as below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.images&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-wrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;wrap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;article&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;400px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin-right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;32px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;32px&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;With Flexbox, CSS will be a little bit more complicated. Both flex container and flex items need to include some CSS properties. To make code more maintainable, I personally prefer to substitute &lt;code&gt;margin&lt;/code&gt; with CSS Grid properties for the layout as much as possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  grid-gap is a great weapon for a responsive design
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;grid-gap&lt;/code&gt; is a useful property for responsive design. Nowadays most websites apply responsive design. Therefore a frontend developer should always consider the layout for multiple devices.&lt;/p&gt;

&lt;p&gt;Responsive design sounds intimidating to the beginners but &lt;code&gt;grid-gap&lt;/code&gt; can make your frontend development so much easier and you will never be afraid of responsive design.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;grid-gap&lt;/code&gt; can be written as below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.images&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;/* To set the same amount of gap to both dimensions */&lt;/span&gt;
  &lt;span class="py"&gt;grid-gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;32px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c"&gt;/* To set a different amount of gap to the vertical and horizontal dimension  */&lt;/span&gt;
  &lt;span class="py"&gt;grid-gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt; &lt;span class="m"&gt;32px&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;As I said in the previous topic, I personally don't prefer using &lt;code&gt;margin&lt;/code&gt; for adjusting the layout. In the case of using Flexbox in the mobile view, in most cases, you need to add &lt;code&gt;margin&lt;/code&gt; to the last flex item something like that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;article&lt;/span&gt;&lt;span class="nd"&gt;:last-child&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;margin-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a kind of ugly code for me. Only setting margin to the last item is irregular and sometimes It may cause the confusion of development. With &lt;code&gt;grid-gap&lt;/code&gt; code will be more readable and can prevent any confusion.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently used CSS Grid patterns
&lt;/h2&gt;

&lt;p&gt;Here, I show you the CSS Grid patterns that I have used often for the project.&lt;/p&gt;

&lt;p&gt;The first one is the code for the gif that I have already shown in the first paragraph.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.images&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;auto-fill&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minmax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;400px&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="py"&gt;grid-gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;32px&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;You can also achieve it switching &lt;code&gt;auto-fill&lt;/code&gt; to &lt;code&gt;8&lt;/code&gt; because this grid container contains 8 grid items. &lt;code&gt;minmax(auto, 400px)&lt;/code&gt; is literally for setting &lt;code&gt;min&lt;/code&gt; and &lt;code&gt;max&lt;/code&gt; values for the width of the item so the width of these items won't be wider than 400px in this case.&lt;/p&gt;

&lt;p&gt;Another CSS Grid pattern I have frequently used is the code below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.images&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;space-between&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;In this code, When the grid container only contains 2 grid items &lt;code&gt;grid-template-columns&lt;/code&gt; will set the width of each item to either &lt;code&gt;auto auto&lt;/code&gt;, or &lt;code&gt;1fr 1fr&lt;/code&gt;, or even a specific pixel such as &lt;code&gt;400px 400px&lt;/code&gt;. &lt;code&gt;align-items&lt;/code&gt; and &lt;code&gt;justify-content&lt;/code&gt; are available for both Flexbox and CSS Grid. These are not tricky properties. &lt;code&gt;align-items&lt;/code&gt; manage the vertical position and &lt;code&gt;justify-content&lt;/code&gt; adjusts the space between each item horizontally in this case.&lt;/p&gt;

&lt;p&gt;Getting a grasp of the fundamental idea of CSS is not difficult. The easiest path to achieve that is playing around CSS Grid then eventually you will be comfortable working with CSS Grid.&lt;/p&gt;

&lt;h2&gt;
  
  
  In which case Flexbox should be used ?
&lt;/h2&gt;

&lt;p&gt;No doubt that CSS Grid has more features than Flexbox but It doesn't mean you should always prioritize CSS Grid. When the items don't require the tweak of a gap and also the container is 1 dimensional I prefer to use Flexbox.&lt;/p&gt;

&lt;p&gt;Also using both CSS Grid and Flexbox can't cause anything harmful to the project. With a mix of CSS Grid and Flexbox, Let's make the project more concise and great.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclution
&lt;/h2&gt;

&lt;p&gt;I hope you guys have enjoyed my article. There is not the perfect way of writing CSS as same as any other programming language. However, I'm pretty sure that CSS Grid must be the smart choice to achieve each section under a grid container.&lt;/p&gt;

&lt;p&gt;If you have any questions about CSS Grid or have an own way of writing CSS code different from the one I explained in this article, I would love to hear your brilliant idea.&lt;/p&gt;

&lt;p&gt;As usual thanks for reading my article. Keep coding, devs!&lt;/p&gt;

&lt;h3&gt;
  
  
  Reference
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://picsum.photos/" rel="noopener noreferrer"&gt;https://picsum.photos/&lt;/a&gt; \&lt;br&gt;
Used for getting random pics&lt;/p&gt;

&lt;p&gt;&lt;a href="https://loremipsum.io/" rel="noopener noreferrer"&gt;https://loremipsum.io/&lt;/a&gt; \&lt;br&gt;
Used for getting random sentences&lt;/p&gt;

</description>
      <category>css</category>
      <category>beginners</category>
      <category>grid</category>
      <category>frontend</category>
    </item>
    <item>
      <title>5 Tips to Use BEM CSS Naming Convention Properly</title>
      <dc:creator>Rei Yoshizawa</dc:creator>
      <pubDate>Tue, 26 May 2020 04:30:36 +0000</pubDate>
      <link>https://forem.com/reiyszw/5-tips-to-use-bem-css-naming-convention-properly-3mn7</link>
      <guid>https://forem.com/reiyszw/5-tips-to-use-bem-css-naming-convention-properly-3mn7</guid>
      <description>&lt;p&gt;CSS seems pretty easy at first sight. But trust me, It doesn't. If you are a beginner as a frontend developer then CSS might be the biggest hurdle to complete your task. To make your life more comfortable as a frontend developer, I highly recommend you to follow the BEM naming convention.&lt;/p&gt;

&lt;p&gt;As many of you know, BEM stands for &lt;strong&gt;Block, Element, Modifier&lt;/strong&gt;. &lt;code&gt;Bloc__Element--Modifier&lt;/code&gt; may be more recognizable for some people. For those who would like me to introduce BEM, I will refer this to you. &lt;a href="http://getbem.com/naming/"&gt;the introduction of the official website for BEM&lt;/a&gt;. Please look over this official website of BEM.&lt;/p&gt;

&lt;p&gt;However, To deeply understand how to use BEM for your project, no offence, but this official website is just useless compared to the official documentation of Vue.js, React, or other well-documented ones especially. You will obviously not use BEM properly if you only saw the official website of BEM or only know more or less about the keywords as &lt;code&gt;Block__Element--Modifier&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In this article, I will talk about how to apply BEM properly since many developers may not know about including BEM into the project.&lt;/p&gt;

&lt;h2&gt;
  
  
  The way I use BEM was wrong
&lt;/h2&gt;

&lt;p&gt;I can not remember when I started using BEM for a project. It probably was 2 or 3 years ago. Believe it or not, I have never reached &lt;a href="http://getbem.com/"&gt;the official website of BEM&lt;/a&gt; until last week. I do not blame myself about that since I found out this page is rather created for just a short introduction about BEM. not much new information was found.&lt;/p&gt;

&lt;p&gt;BEM is not a framework or a library that shines brightly in the frontend world. In most cases, BEM is categorized as a principle.&lt;/p&gt;

&lt;p&gt;While BEM does not force us to follow the strict rules. Some developers might have been kept considering about the proper way to use BEM.&lt;/p&gt;

&lt;p&gt;So now I would like to suggest how to use BEM more efficient and maintainable way. Don't get me wrong that my opinion is not perfect. These are just my suggestions but I hope some of them could help you to rethink BEM and make your project better.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don't do this: Block__Element__Element or Block__Element--modifier__element
&lt;/h2&gt;

&lt;p&gt;I am pretty sure some of you might have ever written BEM like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card__title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card__subtitle"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card__body"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"card__body__link"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card__body__title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this BEM style, class name could be relatively long and hard for someone who do not have enough knowledge about the project and file structures to update CSS.&lt;/p&gt;

&lt;p&gt;In the case you need to write the second element in the block, I would suggest writing BEM like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card__title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card__subtitle"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card__body"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"card__link"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card__linkTitle"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you prefer to use kebab case, code could be like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"card__link"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card__link-title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep following the rule, &lt;code&gt;Block__Element--modifier&lt;/code&gt;. Instead of connecting an element to another element, you should always follow this simple rule.&lt;/p&gt;

&lt;h2&gt;
  
  
  Naming is definitely important
&lt;/h2&gt;

&lt;p&gt;Naming is hard for anything. Not only for class name, id name, but also for variable, function or any kind of names. Take some time to let you convince yourself to add an appropriate class name to make it a great BEM structure. If you have no idea what kind of name would be appropriate for class names, &lt;a href="https://9elements.com/bem-cheat-sheet/"&gt;Check this cheat sheet out&lt;/a&gt;. I have recently found this and It is simple and easy to understand.&lt;/p&gt;

&lt;p&gt;Few suggestions for naming to the class name of HTML, I often use these as the class name of an element.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;title&lt;/code&gt;, &lt;code&gt;link&lt;/code&gt;, &lt;code&gt;image&lt;/code&gt;, &lt;code&gt;body&lt;/code&gt;, &lt;code&gt;box&lt;/code&gt;, &lt;code&gt;item&lt;/code&gt;, &lt;code&gt;inner&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Pretty simple and easy, isn't it?&lt;/p&gt;

&lt;h2&gt;
  
  
  The meaningful name is crucial
&lt;/h2&gt;

&lt;p&gt;Some developers prefer to put shorthand names on the class names. That is not 100% a bad thing. Also, if the team has the specific naming rule which recommends to use shorthand names, that would totally be ok.&lt;/p&gt;

&lt;p&gt;However, from my point of view, a meaningful names should be always preferred to a shorthand name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card__ttl"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card__subttl"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ttl&lt;/code&gt; stands for title, &lt;code&gt;subttl&lt;/code&gt; should probably be for subtitle in this case. But what is the point of making it short? What if someone gets confused about the meaning of a word? Although putting Shorthand class names on class may reduce a tiny bit of bytes, a Meaningful name is always secured and understandable for everyone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deep nesting is not readable
&lt;/h2&gt;

&lt;p&gt;Applying a CSS preprocessor such as Sass or less is standard in frontend. Nesting is one of the efficient features of these preprocessors. I have recently been keen to write clean code as much as possible and realized deep nesting (I suppose that more than 4 hierarchies could be called as deep nesting) is unreadable.&lt;/p&gt;

&lt;p&gt;Look how deep nesting is not readable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.card {
  &amp;amp;__title {
  }

  &amp;amp;__subtitle {
  }

  .cardBody {
    &amp;amp;__title {
    }

    .cardList {
      &amp;amp;__title {
      }
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead, You should write code something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.card {
  &amp;amp;__title {
  }

  &amp;amp;__subtitle {
  }
}

.cardBody {
  &amp;amp;__title {
  }
}

.cardList {
  &amp;amp;__title {
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the latter, when you get asked to fix styles you can reach to where the code should be updated without any hesitation. It would not only save developer's time but also prevent a possibility to occur a side effect which might have been caused by updating code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Do not add !important to your code as much as possible
&lt;/h2&gt;

&lt;p&gt;No wonder that if you are a frontend developer you have been ended up adding &lt;code&gt;!important&lt;/code&gt; to code countless times. or you may even have added &lt;code&gt;!important&lt;/code&gt; to the code which already &lt;code&gt;important&lt;/code&gt; was assigned to many classes.&lt;/p&gt;

&lt;p&gt;In my point of view, In most of the cases, the reason why we have to add &lt;code&gt;!important&lt;/code&gt; is caused by having common styles in a root directory.&lt;/p&gt;

&lt;p&gt;I remember the days I applied bootstrap to a project and somehow I was forced to add &lt;code&gt;!important&lt;/code&gt; to some CSS instead of updating a default stylesheet of bootstrap.&lt;/p&gt;

&lt;p&gt;I am not saying that having a common CSS is relatively bad. However adding common CSS without thinking about the whole project, would make CSS code being messy.&lt;/p&gt;

&lt;h2&gt;
  
  
  I don't recommend to customize BEM
&lt;/h2&gt;

&lt;p&gt;BEM naming convention is just a principle and obviously we have no reason to follow all of them. For example, some people decide to add a class name something like that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;i&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"button_icon"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"button_title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"button_body"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It just replaced a double underscore with a single underscore. That's not a big deal. However, a double underscore reminds me of BEM, undoubtedly. Even when a new employee joins a team and looks over the code for the first time, he or she realizes that BEM is applied to this project without asking a team member.&lt;/p&gt;

&lt;p&gt;So that there is no point to let BEM rules customize to be your original way. Always care about how the other developers feel when updating your code. Don't make your team member get confused.&lt;/p&gt;

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

&lt;p&gt;Not so many frontend developers try to explore about a naming convention. Without organizing code, the bigger the project goes the less organized the code would be. So that organizing code makes a massive impact on the project to reduce refactoring time and team member's stress.&lt;/p&gt;

&lt;p&gt;I introduced BEM to you since I have never encountered any CSS naming convention more convincing than BEM. BEM is simple, easy to understand, and more importantly maintainable.&lt;/p&gt;

&lt;p&gt;I hope this post will help you write CSS code. If you have any questions or opinions about the post, please feel free to reach to my social account or email. Especially if you know a great tip to be a productive way of writing CSS more, I would love to hear that. Thanks!&lt;/p&gt;

</description>
      <category>bem</category>
      <category>css</category>
      <category>frontend</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
