<?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: bagus prabangkoro</title>
    <description>The latest articles on DEV Community by bagus prabangkoro (@prabangkoro).</description>
    <link>https://dev.to/prabangkoro</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%2F233714%2Fc3de86e1-f7a3-4e3d-a19b-b013959c75a9.jpg</url>
      <title>DEV Community: bagus prabangkoro</title>
      <link>https://dev.to/prabangkoro</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/prabangkoro"/>
    <language>en</language>
    <item>
      <title>React: Method Component vs Class Component</title>
      <dc:creator>bagus prabangkoro</dc:creator>
      <pubDate>Sun, 29 Sep 2019 12:45:17 +0000</pubDate>
      <link>https://dev.to/prabangkoro/react-method-component-vs-class-component-56fj</link>
      <guid>https://dev.to/prabangkoro/react-method-component-vs-class-component-56fj</guid>
      <description>&lt;p&gt;There are some differences between method component and class component. I'll try to highlight some of it, and when to use it.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Method Component&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The simplest way to declare a component in React. We only need to declare a method that returns a jsx syntax and it's done. Below is an example:&lt;/p&gt;


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


&lt;p&gt;We can also pass something into the component using &lt;em&gt;props&lt;/em&gt;. This &lt;em&gt;props&lt;/em&gt; will be the first parameter on the method component.&lt;/p&gt;


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


&lt;h3&gt;
  
  
  &lt;strong&gt;Class Component&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This is the robust version of the component. With class component you can do more. &lt;em&gt;Props&lt;/em&gt; will by default, included in the class (this.props). You can use &lt;em&gt;state&lt;/em&gt;, kinda local variable for your component. You may intruduce many class' method that share the same state. And don't forget to be careful with object binding, I often use the arrow method to avoid object binding problem.&lt;/p&gt;


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


&lt;p&gt;Class component also allows you to use lifecycle method. It's kinda bunch of methods that will be called in particular event like component mount, updated, unmount, etc.&lt;/p&gt;


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


&lt;p&gt;You can see the diagram of lifecycle here:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/"&gt;http://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;When to Use Class Component or Method Component&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The major reason to not using class component is when you only need a simple component or dumb component like a button, card, or representational component. If your component doesn't need a complex state, not using lifecycle, method component is best for you. And vice versa.&lt;/p&gt;

&lt;p&gt;Sometimes, I'm not sure if my component will suits method or class component. In this case, I prefer to use class component from the beginning, so I don't need to change anything if I need more robust component.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Bonus&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you are using VS Code, you can install a React plugin:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=dsznajder.es7-react-js-snippets"&gt;https://marketplace.visualstudio.com/items?itemName=dsznajder.es7-react-js-snippets&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This plugin will save your time a lot. There are tons of shortcut that make your life easier, such as &lt;code&gt;rcc&lt;/code&gt; to create React Class Component, and &lt;code&gt;rfc&lt;/code&gt; to create React Method Component.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;stay hungry, stay foolish&lt;/em&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>vscode</category>
    </item>
    <item>
      <title>My First Thought of React</title>
      <dc:creator>bagus prabangkoro</dc:creator>
      <pubDate>Fri, 27 Sep 2019 09:25:39 +0000</pubDate>
      <link>https://dev.to/prabangkoro/my-first-thought-of-react-1p8e</link>
      <guid>https://dev.to/prabangkoro/my-first-thought-of-react-1p8e</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AIrvyAnp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/dmbsryj45/image/upload/v1569576258/dev.to/pchrhjrdnzfyqbazub3g.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AIrvyAnp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/dmbsryj45/image/upload/v1569576258/dev.to/pchrhjrdnzfyqbazub3g.jpg" alt="Computer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lately, I am continuing my online course on Udemy with an interesting topic: Modern React with Redux. This is my first time learning about this library, so I'm a bit curious about why this library is so famous. I am a Vue person, doing my work on the office mostly with Vue, and this React feels so strange to me. Strange but interesting at the same time. Here is my first thought of exploring React:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;JSX!&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you have knowing Vue for a while, you might wonder how React put between template and logic. And here it comes JSX in-game. JSX combine template and logic. Nothing more, no place to separate them. It's a bit weird to me and changes my workflow as well.&lt;/p&gt;

&lt;p&gt;Although it combines everything, it has benefit. &lt;strong&gt;Creating component in React is extremely simple!&lt;/strong&gt; You can create one line of the method, and call it a component.&lt;/p&gt;


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


&lt;h3&gt;
  
  
  &lt;strong&gt;Functional Paradigm&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;React drives you to write short and reusable code. You rarely see any deep (Hadouken) code, especially in DOM element. React doesn't give you a syntactic sugar like &lt;strong&gt;v-for, v-if, v-else,&lt;/strong&gt; like in Vue.&lt;/p&gt;

&lt;p&gt;For example, every time you want to show repeated element. You have to utilize js syntax &lt;strong&gt;map&lt;/strong&gt;.&lt;/p&gt;


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


&lt;p&gt;A bit deep huh?&lt;/p&gt;

&lt;p&gt;This situation has no syntactic sugar will drive you to write readable code, with no deep loop, no nested loop. A good practice is to separate this looping item into a single component.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Wonderful Props&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;I think this is the key value of React. It provides really powerful props. With props, you can pass anything, string, object, or even a Component! (passing component in props is not a good practice anyway, you can use props child instead) This is mind-blowing really.&lt;/p&gt;

&lt;p&gt;Passing any data to props is really simple, and using it is simpler.&lt;/p&gt;


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


&lt;p&gt;We don't need to define what props are passing, we just use it instantly.&lt;/p&gt;




&lt;p&gt;React has pros and cons against Vue. It is limited on its syntactic sugar, but React has a simple rule so we can basically do anything with it. It gives us flexibility more than Vue.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Stay hungry, stay foolish&lt;/em&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>vue</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Hello World</title>
      <dc:creator>bagus prabangkoro</dc:creator>
      <pubDate>Fri, 27 Sep 2019 08:17:31 +0000</pubDate>
      <link>https://dev.to/prabangkoro/hello-world-181d</link>
      <guid>https://dev.to/prabangkoro/hello-world-181d</guid>
      <description>&lt;p&gt;Hi all!&lt;/p&gt;

&lt;p&gt;First thing first: I've start writing not long ago. I stumbled on Medium before, and I realize that I can get more opportunity here if I write about developer stuff. So here we are.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Stay hungry, stay foolish&lt;/em&gt;&lt;/p&gt;

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