<?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: Nesha Zoric</title>
    <description>The latest articles on DEV Community by Nesha Zoric (@neshaz).</description>
    <link>https://dev.to/neshaz</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%2F60066%2Fb0a0701d-17a8-4b44-94f3-c9dae49c1d20.jpeg</url>
      <title>DEV Community: Nesha Zoric</title>
      <link>https://dev.to/neshaz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/neshaz"/>
    <language>en</language>
    <item>
      <title>React JSX - How to do it the right way - Part II</title>
      <dc:creator>Nesha Zoric</dc:creator>
      <pubDate>Mon, 04 May 2020 07:54:59 +0000</pubDate>
      <link>https://dev.to/neshaz/react-jsx-how-to-do-it-the-right-way-part-ii-13k7</link>
      <guid>https://dev.to/neshaz/react-jsx-how-to-do-it-the-right-way-part-ii-13k7</guid>
      <description>&lt;p&gt;In &lt;a href="https://www.kolosek.com/react-jsx-loops/"&gt;the previous part of React JSX series&lt;/a&gt;, we took a look at how to correctly loop through arrays and objects in React. In this article, we'll help you learn how to write conditional statements when rendering components.&lt;/p&gt;

&lt;p&gt;Everything below applies to React Native as well!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conditional statements inside React render
&lt;/h2&gt;

&lt;p&gt;While learning to code in React, most of us have probably tried this and realized it won't work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// this won't work&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="c1"&gt;// do something&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="c1"&gt;// do something else&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;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;JSX is just a syntactic sugar for function calls and object construction, and, although JavaScript is pretty flexible, we still can't pass the code like the if-else above as a parameter to a function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Below are the correct ways to do the conditioning!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's say we have a &lt;code&gt;flight&lt;/code&gt; object and in our Flight component, we want to show whether it's cancelled or not. The most usual way to do simple conditioning like this is via ternary expressions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cancelled&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt;
                    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cancelled&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;Regular&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;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;Ternary expressions are okay for simpler stuff but what happens if we have something more complex?&lt;/p&gt;

&lt;p&gt;Let's say, what if we have a situation where we should use an else if statement?&lt;/p&gt;

&lt;p&gt;Of course, we can do something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cancelled&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt;
                    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cancelled&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="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;arrived&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt;
                           &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Arrived&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;Regular&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;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 can easily pile up and start looking pretty messy and unreadable. What's the better way then? Do the conditioning above the return statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cancelled&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cancelled&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;arrived&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Arrived&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Regular&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;status&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;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;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;Now, in previous examples, we were only rendering a status in our component, but usually, there will be much more to render. So, if we want to render the departure time, the destination, the arrival time and status, for example, it might look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cancelled&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cancelled&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;arrived&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Arrived&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Regular&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="na"&gt;Destination&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;destination&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;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="nx"&gt;Departure&lt;/span&gt; &lt;span class="na"&gt;time&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;departureTime&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;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="nx"&gt;Arrival&lt;/span&gt; &lt;span class="na"&gt;time&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;arrivalTime&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;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="nx"&gt;Flight&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;status&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;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;Now, this is okay, it's working, &lt;strong&gt;but we're polluting the render method of a component&lt;/strong&gt;. Imagine we had more if-else statements - it'd be a mess.&lt;br&gt;
Instead, why wouldn't we &lt;strong&gt;move it outside of a render method&lt;/strong&gt;, so it's completely separate?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="nx"&gt;renderStatus&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cancelled&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cancelled&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;arrived&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Arrived&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Regular&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="na"&gt;Destination&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;destination&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;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="nx"&gt;Departure&lt;/span&gt; &lt;span class="na"&gt;time&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;departureTime&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;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="nx"&gt;Arrival&lt;/span&gt; &lt;span class="na"&gt;time&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;arrivalTime&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;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="nx"&gt;Flight&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&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;renderStatus&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;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;Our code looks way neater now, right?&lt;/p&gt;

&lt;p&gt;All of the examples above were about rendering a simple string based on some boolean values but what could have happened if we had to add a different class, or pass a different prop? Logic is the same.&lt;/p&gt;

&lt;p&gt;Let's say we have a button to book a flight unless it's cancelled:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;renderButton&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;handleOnPress&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;buttonClassName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;buttonText&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cancelled&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;buttonClassName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;button disabled&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;buttonText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cancelled&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;buttonClassName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;buttonText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Book&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;handleOnPress&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;bookFlight&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;
            &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;buttonClassName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="nx"&gt;onPress&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleOnPress&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;buttonText&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We can also use ternary expressions to have the same result as the one produced by code above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;renderButton&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// for className, you can also use this:&lt;/span&gt;
    &lt;span class="c1"&gt;// `button ${flight.cancelled ? 'disabled' : ''}`&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;
            &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cancelled&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;button disabled&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;button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="nx"&gt;onPress&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cancelled&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="p"&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;bookFlight&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt; 
                &lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cancelled&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt;
                    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cancelled&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;Book&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you just want to render/pass something if the condition is fullfilled, you can also write it this way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// condition &amp;amp;&amp;amp; what_to_render&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt; 
                &lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cancelled&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cancelled&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;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;h3&gt;
  
  
  Conditional rendering inside for loop
&lt;/h3&gt;

&lt;p&gt;When &lt;a href="https://kolosek.com/react-jsx-loops"&gt;rendering a list of items&lt;/a&gt;, you might want to render them differently based on some condition. For example, you might want to add grey background to all the even items. How to do this? You can either use ternary expression or standard if/else, both will work! Remember that it's a function like any other!  Here's a small example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&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;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="c1"&gt;// if even, render grey background&lt;/span&gt;
                    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                      &lt;span class="c1"&gt;// don't forget to return what you want to render!&lt;/span&gt;
                      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
                        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt;&lt;span class="na"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;grey&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                          &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
                        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;                      &lt;span class="p"&gt;);&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                      &lt;span class="c1"&gt;// you can also use ternary expression&lt;/span&gt;
                      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
                        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;expired&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&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="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                          &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
                        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;                      &lt;span class="p"&gt;);&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                  &lt;span class="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;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;Of course, this mapping function can be &lt;em&gt;extracted outside of render method&lt;/em&gt;, for increased readability. &lt;/p&gt;

&lt;h3&gt;
  
  
  Switch statement
&lt;/h3&gt;

&lt;p&gt;We've been talking about if-else, but conditioning can, also, be done with a switch statement. Let's say that, instead of the boolean attributes for cancelled and arrived, we have one status attribute. Of course, we can't just type something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// this will raise an error&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt; 
                &lt;span class="k"&gt;switch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cancel&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Cancelled&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;arrive&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Arrived&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="nl"&gt;default&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;Regular&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;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;For switch, there's no neat way to do it directly in return statement. We can, of course, use &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/IIFE"&gt;immediately-invoked function&lt;/a&gt; containing a switch, but it's neither practical nor does it look nice. To make the switch above work, just move it to some function outside of render method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;renderStatus&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;switch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cancel&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Cancelled&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;arrive&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Arrived&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;default&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;Regular&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="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&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;renderStatus&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;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;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;Of course, switch can also be specified in render method, above the return statement. Just remember not to use &lt;strong&gt;'return'&lt;/strong&gt; in cases, but a &lt;strong&gt;'break'&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;switch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;flight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cancel&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Cancelled&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;arrive&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Arrived&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Regular&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;status&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;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now you're completely ready to do conditioning in React! Go ahead and try these out, make that code you've been struggling with for hours finally work properly!&lt;/p&gt;

&lt;p&gt;If you already knew how to use if-else and switch in React, we hope you still enjoyed the article and freshened up your knowledge a bit.&lt;/p&gt;

&lt;p&gt;Thank you for your time!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="//kolosek.com/react-jsx-conditions/"&gt;Kolosek blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>jsx</category>
    </item>
    <item>
      <title>Rails RSpec Setup</title>
      <dc:creator>Nesha Zoric</dc:creator>
      <pubDate>Fri, 01 May 2020 08:49:48 +0000</pubDate>
      <link>https://dev.to/neshaz/rails-rspec-setup-1f5n</link>
      <guid>https://dev.to/neshaz/rails-rspec-setup-1f5n</guid>
      <description>&lt;p&gt;RSpec is an awesome tool for testing Rails apps. It is a hugely popular  BDD-oriented (&lt;strong&gt;B&lt;/strong&gt;ehavior &lt;strong&gt;D&lt;/strong&gt;riven &lt;strong&gt;D&lt;/strong&gt;evelopment) testing framework in the Ruby community.&lt;/p&gt;

&lt;p&gt;It makes writing tests simpler, more expressive and easier to maintain!&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;First, you'll need to install RSpec but you’ll also need &lt;a href="https://github.com/DatabaseCleaner/database_cleaner"&gt;Database Cleaner&lt;/a&gt; to help hold things together and ensure a clean state during tests. Add the following gems to the :test and :development groups in your &lt;a href="https://kolosek.com/rails-bundle-install-and-gemfile/"&gt;Gemfile&lt;/a&gt; and then run &lt;code&gt;bundle install&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;group :development, :test do
  gem "database_cleaner"
  gem "rspec-rails"
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It is very common to use RSpec together with &lt;a href="https://kolosek.com/rails-capybara-setup/"&gt;Capybara&lt;/a&gt; to improve your testing development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuring RSpec
&lt;/h2&gt;

&lt;p&gt;Before you can start with writing your RSpec tests your will need to run &lt;code&gt;rails generate rspec:install&lt;/code&gt;. This will create the following files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create  .rspec
create  spec
create  spec/spec_helper.rb
create  spec/rails_helper.rb
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Files such as, &lt;strong&gt;spec_helper.rb&lt;/strong&gt; and &lt;strong&gt;rails_helper.rb&lt;/strong&gt; contain the default RSpec set up with lots of comments. It is &lt;em&gt;strongly&lt;/em&gt; recommended to read through all of those comments to get a good understanding of what each option does.&lt;/p&gt;

&lt;h3&gt;
  
  
  spec_helper.rb
&lt;/h3&gt;

&lt;p&gt;spec_helper.rb file is used to configure RSpec. The base configuration file, after uncommenting some useful configuration options, is written in the following way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RSpec.configure do |config|
  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end

  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end

  config.shared_context_metadata_behavior = :apply_to_host_groups
  config.filter_run_when_matching :focus
  config.disable_monkey_patching!

  if config.files_to_run.one?
    config.default_formatter = "doc"
  end

  config.profile_examples = 10

  config.order = :random
  Kernel.srand config.seed
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;expectations.include_chain_clauses_in_custom_matcher_descriptions = true&lt;/code&gt; - &lt;a href="https://relishapp.com/rspec/rspec-expectations/docs/custom-matchers/define-matcher-with-fluent-interface"&gt;Chain method&lt;/a&gt; allows custom matcher descriptions and failure messages to include text for helper methods.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;mocks.verify_partial_doubles = true&lt;/code&gt; - &lt;a href="http://relishapp.com/rspec/rspec-mocks/docs/verifying-doubles/partial-doubles"&gt;Partial doubles&lt;/a&gt; prevent you from stubbing any methods that don’t already exist on an object, it typo-proofs your mocks.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;config.shared_context_metadata_behavior = :apply_to_host_groups&lt;/code&gt; - &lt;a href="http://www.rubydoc.info/github/rspec/rspec-core/RSpec%2FCore%2FConfiguration%3Ashared_context_metadata_behavior"&gt;Shared context metadata&lt;/a&gt; configures how RSpec treats metadata passed as part of a shared example group definition.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;filter_run_when_matching&lt;/code&gt; - &lt;a href="https://relishapp.com/rspec/rspec-core/docs/filtering/filter-run-when-matching"&gt;Filter run when matching&lt;/a&gt; allows you to limit a spec run to individual examples or groups you tagged with &lt;code&gt;:focus&lt;/code&gt; metadata.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;disable_monkey_patching!&lt;/code&gt; - &lt;a href="https://relishapp.com/rspec/rspec-core/v/3-5/docs/configuration/zero-monkey-patching-mode"&gt;Prevents RSpec from monkey patching&lt;/a&gt; makes objects behave in tests as they would in "real" life.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;default_formatter&lt;/code&gt; - &lt;a href="https://relishapp.com/rspec/rspec-core/v/2-5/docs/command-line/format-option"&gt;Default formatter&lt;/a&gt; sets up the default format of your rspec tests that will be used if no formatter has been set.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;config.profile_examples&lt;/code&gt; - &lt;a href="https://relishapp.com/rspec/rspec-core/docs/configuration/profile-examples"&gt;Profile examples&lt;/a&gt; print the slowest examples and example groups at the end of the spec run, but it slows down your suite&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;config.order = :random&lt;/code&gt; and &lt;code&gt;Kernel.srand config.seed&lt;/code&gt; - Configure tests to run in a &lt;a href="https://relishapp.com/rspec/rspec-core/v/3-5/docs/command-line/order"&gt;random order&lt;/a&gt;. This helps to keep each test independent of one another. 
### rails_helper.rb
rails_helper.rb file is used for specs which depend on Rails (mostly model and &lt;a href="https://kolosek.com/rspec-controller-test/"&gt;controller tests&lt;/a&gt;, but also on nearly every part of a Rails projects). 
==rails_helper.rb requires spec_helper.rb to work.==
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'

ActiveRecord::Migration.maintain_test_schema!

RSpec.configure do |config|
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
  config.use_transactional_fixtures = true
  config.infer_spec_type_from_file_location!
  config.filter_rails_from_backtrace!
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;fixture_path&lt;/code&gt; - &lt;a href="https://relishapp.com/rspec/rspec-rails/v/3-5/docs/file-fixture"&gt;File fixture&lt;/a&gt; is a normal file stored in spec/fixtures by default.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;use_transactional_fixtures&lt;/code&gt; - &lt;a href="https://relishapp.com/rspec/rspec-rails/docs/transactions"&gt;Transactional&lt;/a&gt; fixtures allow records created for one test to be visible for the next test.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;infer_spec_type_from_file_location!&lt;/code&gt; -  Allows to automatically &lt;a href="https://relishapp.com/rspec/rspec-rails/docs/directory-structure"&gt;tag specs in directories&lt;/a&gt; with matching type metadata so that they have relevant helpers available to them.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;filter_rails_from_backtrace!&lt;/code&gt; - &lt;a href="https://relishapp.com/rspec/rspec-rails/docs/backtrace-filtering"&gt;Backtrace filtering&lt;/a&gt; is used to filter out lines in backtraces that come from Rails gems in order to reduce the noise in test failure output.
##Configuring Database Cleaner
By configuring the &lt;strong&gt;Database Cleaner&lt;/strong&gt; in your application, you make it sure that tests start with a clean state. The only thing you need to do is to add the following to your RSpec.configure block in rails_helper.rb:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;config.before(:suite) do
  DatabaseCleaner.clean_with(:truncation)
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  How to run the tests?
&lt;/h2&gt;

&lt;p&gt;Once everything is configured you are ready to go! There are four ways to run your test:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Everything at once: &lt;code&gt;bundle exec rspec&lt;/code&gt;. 
This runs all your tests.&lt;/li&gt;
&lt;li&gt;One RSpec package: &lt;code&gt;bundle exec rspec ./spec/models&lt;/code&gt;
This runs all model specs.&lt;/li&gt;
&lt;li&gt;One RSpec file at a time: &lt;code&gt;bundle exec rspec ./spec/models/story_spec.rb&lt;/code&gt;. 
This runs only tests in Story model.&lt;/li&gt;
&lt;li&gt;One by one: &lt;code&gt;bundle exec rspec ./spec/models/story_spec.rb:10&lt;/code&gt;
This runs only tests on line 10 in Story model.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the same way, you can run tests on your &lt;a href="https://kolosek.com/rspec-controller-test/"&gt;controller&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Be careful! The more tests there are the longer it takes to compile them. Only run tests for what you really need!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="//kolosek.com/rails-rspec-setup/"&gt;Kolosek blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>rails</category>
      <category>rspec</category>
      <category>setup</category>
    </item>
    <item>
      <title>Are Lean and Agile enemies or friends?</title>
      <dc:creator>Nesha Zoric</dc:creator>
      <pubDate>Wed, 29 Apr 2020 11:15:32 +0000</pubDate>
      <link>https://dev.to/neshaz/are-lean-and-agile-enemies-or-friends-pkb</link>
      <guid>https://dev.to/neshaz/are-lean-and-agile-enemies-or-friends-pkb</guid>
      <description>&lt;p&gt;If you aren't an educated and/or experienced tech person, a lot of question marks may pop up in your mind while looking at these two terms: &lt;em&gt;Lean&lt;/em&gt; and &lt;em&gt;Agile&lt;/em&gt;. Even if you are technically proficient, you may wonder what the difference between these two really is. No worries, we are here to help you.&lt;br&gt;
&lt;strong&gt;Both &lt;em&gt;Lean&lt;/em&gt; and &lt;em&gt;Agile&lt;/em&gt; are methodologies.&lt;/strong&gt; &lt;br&gt;
They are represented by sets of principles that used in order to guide the process of development (in this case, software development). &lt;br&gt;
Although usually described as two completely different approaches, by the end of this post, you will notice that &lt;strong&gt;they are actually complementary&lt;/strong&gt; and that one doesn’t exclude the other.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lean
&lt;/h2&gt;

&lt;p&gt;We will dare to say that Lean, generally speaking, has &lt;strong&gt;the process&lt;/strong&gt; in its focus. The methodology behind Lean software development comes from &lt;a href="http://en.wikipedia.org/wiki/Lean_manufacturing"&gt;Lean manufacturing&lt;/a&gt;. Here, it’s all about &lt;strong&gt;reducing any kind of a waste&lt;/strong&gt;. By eliminating all that is unnecessary, the value is added, and value is what the customer is paying for. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x_aPrFFR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.googleapis.com/kolosekblog/2017/08/photo_55974_20151203.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x_aPrFFR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.googleapis.com/kolosekblog/2017/08/photo_55974_20151203.jpg" alt="lean-methodology"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Constant learning is a part of any process, and learning means improving. Without this, there is no quality, which is the final goal. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Also, people are important, because without a good team, how can you deliver a high-quality product? In order to have a smoothly running workflow, &lt;strong&gt;every member of the team should do what they can do best&lt;/strong&gt;, and the work should be distributed evenly. The work is done more efficiently and quickly when everyone is doing their job, without unnecessary tasks (this can be tricky, because in our era, changes happen quickly, and something that was considered unnecessary yesterday, may tomorrow be crucial for the project). &lt;br&gt;
There is a systematic, overall look at the work process when it comes to Lean methodology.&lt;/p&gt;

&lt;h2&gt;
  
  
  Agile
&lt;/h2&gt;

&lt;p&gt;We will again be courageous enough to say that, generally speaking, in the focus of Agile is &lt;strong&gt;the product&lt;/strong&gt;. Agile software development methodology is based on the &lt;a href="http://agilemanifesto.org/"&gt;Agile Manifesto&lt;/a&gt;. Four main values are in the center of the manifesto, and we quote them here:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“&lt;em&gt;Individuals and interactions over processes and tools&lt;br&gt;
Working software over comprehensive documentation&lt;br&gt;
Customer collaboration over contract negotiation&lt;br&gt;
Responding to change over following a plan.&lt;/em&gt;”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j6vRSnIg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.googleapis.com/kolosekblog/2017/08/photo_83099_20161120.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j6vRSnIg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.googleapis.com/kolosekblog/2017/08/photo_83099_20161120.jpg" alt="agile-methodology"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Communication among team members, both managers, and developers, is as important as the collaboration with the customer. &lt;strong&gt;A quality final product means a satisfied customer, and that is the goal.&lt;/strong&gt; &lt;br&gt;
From interaction, one is enabled to get a feedback. The feedback is attained after each cycle of the process (the working process can be seen as a compilation of smaller projects). This is crucial in order to make any necessary changes along the way, and in order to deliver the product in the short period of time possible. &lt;/p&gt;

&lt;h2&gt;
  
  
  Lean &amp;amp; Agile
&lt;/h2&gt;

&lt;p&gt;These two methodologies are best described as &lt;strong&gt;complementary&lt;/strong&gt;. Through quality work organization and quality team, a product of high quality is made, which makes a satisfied customer.  The suggestion is that you should &lt;strong&gt;apply both of these methodologies&lt;/strong&gt;. Collaboration between team members, listening to your customer’s needs, improvement and implementation of changes when necessary, elimination of any kind of waste in order to achieve high-quality and deliver the product without any unnecessary delays. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CPVMj4YX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.googleapis.com/kolosekblog/2017/08/photo_61056_20160126.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CPVMj4YX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.googleapis.com/kolosekblog/2017/08/photo_61056_20160126.jpg" alt="lean-agile-methodology"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We hope that, after reading this post, you have managed to get a grasp of what both the terms &lt;em&gt;Lean&lt;/em&gt; and &lt;em&gt;Agile&lt;/em&gt; mean, and how they are applied in the process of software development. Our goal was to highlight the main points and deliver it in a way which is the easiest to read. However, there is definitely a lot more about these methodologies out there, and if interested, we strongly encourage you to dive into it and widen your knowledge.  &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://kolosek.com/lean-agile-enemies-or-friends/"&gt;Kolosek blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>lean</category>
      <category>agile</category>
      <category>methodology</category>
    </item>
    <item>
      <title>React JSX - How to do it the right way - Part I</title>
      <dc:creator>Nesha Zoric</dc:creator>
      <pubDate>Mon, 27 Apr 2020 12:20:15 +0000</pubDate>
      <link>https://dev.to/neshaz/react-jsx-how-to-do-it-the-right-way-part-i-3jl8</link>
      <guid>https://dev.to/neshaz/react-jsx-how-to-do-it-the-right-way-part-i-3jl8</guid>
      <description>&lt;p&gt;Usually, when developing a website, you'll need some dynamical rendering, like a listing of items, showing some element under a certain condition and so on.&lt;br&gt;
You're all aware of the standard JS syntax - a &lt;strong&gt;for&lt;/strong&gt; loop, or an &lt;strong&gt;if/else&lt;/strong&gt; - but when you try to write those under a render method in React, you'll most likely get some weird looking errors.&lt;/p&gt;

&lt;p&gt;In this, the first part of React JSX series, we will take a look at how to correctly loop through arrays the reactive way. In second part of the series you can find out more about &lt;a href="https://kolosek.com/react-jsx-conditions/"&gt;conditional rendering&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Please note that all of the examples below apply as well to React Native!&lt;/p&gt;
&lt;h2&gt;
  
  
  Using Loops Inside React Render Methods
&lt;/h2&gt;

&lt;p&gt;Let's say you have an array of movies and that you need to display the Movie component for each of them.&lt;/p&gt;

&lt;p&gt;Most of us have tried this at some point:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// this won't work!&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;movies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&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="nx"&gt;Movie&lt;/span&gt; &lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt; 
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;This, however, won't work.&lt;/strong&gt; Why? Think of it like you're just calling JavaScript functions. You can't put a for loop as a parameter when calling a function!&lt;/p&gt;

&lt;p&gt;Well, how to do it then? &lt;strong&gt;There are a few ways.&lt;/strong&gt;&lt;br&gt;
You can go through a for loop above the return statement in render method and fill in a list you'll pass in return:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;movieItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;movies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;movieItems&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Movie&lt;/span&gt; &lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;movieItems&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;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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, however, is not a neat way as it's polluting the render method. To make render more readable, better move the for loop outside of it and then call it as a function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;renderMovies&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;movies&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;movieItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;movies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;movieItems&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Movie&lt;/span&gt; &lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;movieItems&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&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;renderMovies&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;movies&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;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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 looks a bit better now. Still, you are using the for loop which doesn't really look so nice. The &lt;strong&gt;for&lt;/strong&gt; should be used when you need to render something a certain number of times. When you have an object or an array instead, there are neater ways.&lt;/p&gt;

&lt;p&gt;So, let's switch to using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map"&gt;&lt;strong&gt;map&lt;/strong&gt;&lt;/a&gt; from JS Arrays:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;renderMovies&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;movies&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// This is ES6 syntax! You'll need babel configured to use it!&lt;/span&gt;
    &lt;span class="c1"&gt;// You can still use the standard function syntax,&lt;/span&gt;
    &lt;span class="c1"&gt;// but ES6 is definitely something that'll easen your life.&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;movies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Movie&lt;/span&gt; &lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&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;renderMovies&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;movies&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;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;Now, this looks good! Yet, it might look a bit bulky for being just a simple listing you can do in one single place. However, &lt;strong&gt;the map syntax you can actually use &lt;em&gt;directly&lt;/em&gt; in a return statement&lt;/strong&gt;. Why? Because the map function basically passes a freshly created array, compared to the for loop which is just a bulk of code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// This is shortened syntax, for where we don't need to manipulate the actual items before rendering them&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;movies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Movie&lt;/span&gt; &lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="err"&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;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;When you need to manipulate the actual item in the list before rendering it, you can do it this way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;movies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="c1"&gt;// do something with a movie here&lt;/span&gt;
                    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
                        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Movie&lt;/span&gt; &lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;                    &lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="p"&gt;})&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt; 
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;Now, again, if there's a lot of manipulating to be done for a single item, doing it inside a return statement might unnecessarily pollute the render method. In that case, better move this code out of the render method. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;renderMovie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// do something with a movie here&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Movie&lt;/span&gt; &lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// map will automatically pass the list item to our function&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;movies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&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;renderMovie&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;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;All of the previous can also be used for JavaScript objects, with slight adaptation - you won't be mapping through the object, but through the list of the keys of the object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// You can as well use lodash keys function (_.keys)&lt;/span&gt;
                &lt;span class="c1"&gt;// instead of Object.keys, but it functions the same way&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;moviesObject&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;movieKey&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;movie&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;moviesObject&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;movieKey&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
                    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
                        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Movie&lt;/span&gt;
                            &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;movieKey&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
                            &lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;movie&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
                        &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;                    &lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="p"&gt;})&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt; 
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;Keep in mind that all of the codes above are just examples, pseudo codes. &lt;strong&gt;Always&lt;/strong&gt; send the key prop to the items you're rendering and keep it unique, avoiding array indexes.&lt;/p&gt;

&lt;p&gt;Now you know multiple ways on how to loop through arrays in React! Which way you'll use is up to you and the occasion, sometimes one will be more suitable than the other.&lt;/p&gt;

&lt;p&gt;Thank you for your time and good luck with coding!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="//kolosek.com/react-jsx-loops/"&gt;Kolosek blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>jsx</category>
    </item>
    <item>
      <title>Associations in Rails</title>
      <dc:creator>Nesha Zoric</dc:creator>
      <pubDate>Mon, 27 Apr 2020 09:39:16 +0000</pubDate>
      <link>https://dev.to/neshaz/associations-in-rails-4hbd</link>
      <guid>https://dev.to/neshaz/associations-in-rails-4hbd</guid>
      <description>&lt;p&gt;An &lt;strong&gt;association&lt;/strong&gt; is a connection between two &lt;strong&gt;Active Record models&lt;/strong&gt;. It makes much &lt;em&gt;easier&lt;/em&gt; to perform various operations on the records in your code. We will divide associations into four categories:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;One to One&lt;/li&gt;
&lt;li&gt;One to Many&lt;/li&gt;
&lt;li&gt;Many to Many&lt;/li&gt;
&lt;li&gt;Polymorphic One to Many&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you are new to Ruby on Rails, be sure to get up your &lt;a href="https://kolosek.com/ruby-programming-beginners-guide/"&gt;rails project&lt;/a&gt; ready and check how to &lt;a href="https://kolosek.com/rails-scaffold/"&gt;create models&lt;/a&gt; in Rails. &lt;/p&gt;

&lt;h2&gt;
  
  
  One to One
&lt;/h2&gt;

&lt;p&gt;When you set up &lt;strong&gt;one-to-one&lt;/strong&gt; relations you are saying that a record contains exactly one instance of another model. For example, if each user in your application has only one profile, you can describe your models as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class User &amp;lt; ApplicationRecord       class Profile &amp;lt; ApplicationRecord
  has_one :profile                     belongs_to :user
end                                  end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;One of the models in the given relation will have &lt;code&gt;has_one&lt;/code&gt; method invocation and another one will have &lt;code&gt;belongs_to&lt;/code&gt;. It is used to describe which model contains &lt;strong&gt;a foreign key&lt;/strong&gt; reference to the other one, in our case, it is the profiles model. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LNBZ2vh0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.kraken.io/kk8yWPxzXVfBD3654oMN/dd9c653b0c0005b92cdf4a6bdcc10a3e/one-to-one.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LNBZ2vh0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.kraken.io/kk8yWPxzXVfBD3654oMN/dd9c653b0c0005b92cdf4a6bdcc10a3e/one-to-one.png" alt="one-to-one"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cover your associations with &lt;a href="https://kolosek.com/rails-rspec-setup/"&gt;RSpec tests&lt;/a&gt; to make sure everything works the way you want it to.&lt;/p&gt;

&lt;h2&gt;
  
  
  One to Many
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;one-to-many&lt;/strong&gt; association is the most common used relation. This association indicates that each instance of the model A can have &lt;strong&gt;zero or more&lt;/strong&gt; instances of another model B and model B belongs to &lt;strong&gt;only one&lt;/strong&gt; model A. &lt;/p&gt;

&lt;p&gt;Let's check it out via example. We want to create an application where users can write multiple stories, our models should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class User &amp;lt; ApplicationRecord       class Story &amp;lt; ApplicationRecord
  has_many :stories                     belongs_to :user
end                                  end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here, deciding which model will have &lt;code&gt;has_many&lt;/code&gt; and which will have &lt;code&gt;belongs_to&lt;/code&gt; is more important than in &lt;strong&gt;one-to-one&lt;/strong&gt; relations, because it changes the logic of your application. In both cases, the second model contains one reference to the first model in form of a &lt;strong&gt;foreign key&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;The second model doesn't know about the first model relation to it - it is not aware if the first model has a reference to more than one of them or just to one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N_IgQ358--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.kraken.io/kk8yWPxzXVfBD3654oMN/ec6c6326b0948276a487af75a13ee4c9/one-to-many.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N_IgQ358--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.kraken.io/kk8yWPxzXVfBD3654oMN/ec6c6326b0948276a487af75a13ee4c9/one-to-many.png" alt="one-to-many"&gt;&lt;/a&gt;&lt;br&gt;
The tests for associations get more complex to write the more relations you create. You should check it out how to create your own &lt;a href="https://kolosek.com/factory-girl-associations/"&gt;association factories&lt;/a&gt; to make your testing life easier.&lt;/p&gt;
&lt;h2&gt;
  
  
  Many to Many
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Many-to-many&lt;/strong&gt; associations are a bit more complex and can be handled in two ways, &lt;strong&gt;"has and belongs to many"&lt;/strong&gt; and &lt;strong&gt;"has many through"&lt;/strong&gt; relations.&lt;/p&gt;
&lt;h3&gt;
  
  
  Has and Belongs to Many
&lt;/h3&gt;

&lt;p&gt;A &lt;code&gt;has_and_belongs_to_many&lt;/code&gt; association creates a direct &lt;strong&gt;many-to-many&lt;/strong&gt; connection with another model. It is simpler than the other one, as it only requires calling &lt;code&gt;has_and_belongs_to_many&lt;/code&gt; from both models.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C9eEMddp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.kraken.io/kk8yWPxzXVfBD3654oMN/6e59bce7bc11d74d4f3b42aa264f0db8/has-and-belongs-to-many.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C9eEMddp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.kraken.io/kk8yWPxzXVfBD3654oMN/6e59bce7bc11d74d4f3b42aa264f0db8/has-and-belongs-to-many.png" alt="has-and-belongs-to-many"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example:&lt;/em&gt; Let's say, a user can have many different roles and the same role may contain many users, our models would be like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class User &amp;lt; ApplicationRecord       class Role &amp;lt; ApplicationRecord
  has_and_belongs_to_many :roles       has_and_belongs_to_many :users
end                                  end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You will need to create a &lt;strong&gt;join table&lt;/strong&gt; for this association to work. It is a table that connects two different models. The join table is created with rails function &lt;code&gt;create_join_table :user, :role&lt;/code&gt; in a separate &lt;a href="https://kolosek.com/rake-db-commands/"&gt;migration&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CreateUserRoles &amp;lt; ActiveRecord::Migration
  def change
    create_table :user_roles, id: false do |t|
      t.references :user, index: true, foreign_key: true
      t.references :role, index: true, foreign_key: true
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is a very simple approach, but you don't have the direct access to related objects, you can only hold references to two models and nothing else.&lt;/p&gt;

&lt;h3&gt;
  
  
  Has Many Through
&lt;/h3&gt;

&lt;p&gt;Another way to define a &lt;strong&gt;many-to-many&lt;/strong&gt; association is to use the &lt;strong&gt;has many through&lt;/strong&gt; association type. Here we define a &lt;strong&gt;separate model&lt;/strong&gt;, to handle that connection between two different ones.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wGc6RL15--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.kraken.io/kk8yWPxzXVfBD3654oMN/78cbb30deb837728cb6d6153b31c6fb3/has_many_through.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wGc6RL15--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.kraken.io/kk8yWPxzXVfBD3654oMN/78cbb30deb837728cb6d6153b31c6fb3/has_many_through.png" alt="has_many_through"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Instead of putting down a new example, you should check &lt;a href="https://kolosek.com/rails-join-table/"&gt;this one out&lt;/a&gt;! It explains everything you should know about this association.&lt;/p&gt;

&lt;p&gt;Using the example of &lt;code&gt;has_and_belongs_to_many&lt;/code&gt; association, this time the three models should be written like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class User &amp;lt; ApplicationRecord
  has_many :user_roles
  has_many :roles, through: :user_roles
end

class UserRoles &amp;lt; ApplicationRecord
  belongs_to :user
  belongs_to :role
end

class Role &amp;lt; ApplicationRecord
  has_many :user_roles
  has_many :users, through: :user_roles
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This &lt;strong&gt;association&lt;/strong&gt; will enable you to do things like &lt;code&gt;user.role&lt;/code&gt; and to get a list of all connected second model instances. It will also enable you to get access to data specific to the relation between first and second models.&lt;/p&gt;

&lt;h2&gt;
  
  
  Polymorphic
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Polymorphic associations&lt;/strong&gt; are the most advanced associations available to us. You can use it when you have a model that may belong to many different models on a single association.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AgiX5yeP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.kraken.io/kk8yWPxzXVfBD3654oMN/6058d06ae05bb5c5ea77ebbc9fa1aabf/polymorphic.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AgiX5yeP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.kraken.io/kk8yWPxzXVfBD3654oMN/6058d06ae05bb5c5ea77ebbc9fa1aabf/polymorphic.png" alt="polymorphic"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's imagine you want to be able to write comments for users and stories. You want both models to be commentable. Here's how this could be declared:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Comment &amp;lt; ApplicationRecord
  belongs_to :commentable, polymorphic: true
end

class Employee &amp;lt; ApplicationRecord
  has_many :comment, as: :commentable
end

class Product &amp;lt; ApplicationRecord
  has_many :comment, as: :commentable
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can think of a polymorphic &lt;code&gt;belongs_to&lt;/code&gt; declaration as &lt;strong&gt;setting up an interface&lt;/strong&gt; that any other model can use. To declare the &lt;strong&gt;polymorphic interface&lt;/strong&gt; you need to declare both a foreign key column and a type column in the model. You should &lt;a href="https://kolosek.com/rake-db-commands/"&gt;run the migration&lt;/a&gt; once you are done.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CreateComments &amp;lt; ActiveRecord::Migration
  def change
    create_table :comments do |t|
      t.text :body
      t.integer :commentable_id
      t.string :commentable_type
      t.timestamps
    end

    add_index :comments, :commentable_id
  end
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This migration can be simplified by using &lt;strong&gt;references&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CreateComments &amp;lt; ActiveRecord::Migration
  def change
    create_table :comments do |t|
      t.text :body
      t.references :commentable, polymorphic: true, index: true
      t.timestamps
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Aditional Options
&lt;/h2&gt;

&lt;p&gt;There are a few additional options you can use when defining &lt;strong&gt;relations between models&lt;/strong&gt;, we will cover two most commonly used ones.&lt;/p&gt;

&lt;h3&gt;
  
  
  class_name
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;If the name of the other model cannot be derived from the association name, you can use the &lt;code&gt;:class_name&lt;/code&gt; option to supply the model name. You can read more about this on &lt;a href="http://guides.rubyonrails.org/association_basics.html#options-for-belongs-to-class-name"&gt;RailsGuides&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example:&lt;/em&gt; You want the belongs_to relation to call for an &lt;strong&gt;author&lt;/strong&gt;, but there are two problems: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;There is no model called in that way. &lt;/li&gt;
&lt;li&gt;The story table is missing an &lt;code&gt;author_id&lt;/code&gt; field. &lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Easy fix!&lt;/em&gt; To make this work and stop your &lt;a href="https://kolosek.com/rspec-controller-test/"&gt;tests from failing&lt;/a&gt;, you just have to specify the &lt;code&gt;:foreign_key&lt;/code&gt; and the actual name of the class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Story &amp;lt; ApplicationRecord
  belongs_to :author, class_name: 'User', foreign_key: 'user_id'
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  dependent
&lt;/h3&gt;

&lt;p&gt;You can use this option when you want to get rid of &lt;strong&gt;orphaned records&lt;/strong&gt; since they can lead to various problems. Orphaned records are created when we &lt;strong&gt;delete or destroy&lt;/strong&gt; a model A that was associated with model B, but model B wasn't removed in the process.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class User &amp;lt; ApplicationRecord
  has_many :stories, dependent: :destroy
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Example:&lt;/em&gt; Suppose, a user called Maria wrote a lot of stories. Then, we deleted Maria from the database, but the stories still have the user_id column set to Maria's id. These stories are called &lt;strong&gt;orphaned records&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Thank you for reading!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="//kolosek.com/rails-associations/"&gt;Kolosek blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>rails</category>
      <category>associations</category>
    </item>
    <item>
      <title>Agile and Scrum: Our Favorite Duo</title>
      <dc:creator>Nesha Zoric</dc:creator>
      <pubDate>Thu, 23 Apr 2020 09:27:32 +0000</pubDate>
      <link>https://dev.to/neshaz/agile-and-scrum-our-favorite-duo-56b2</link>
      <guid>https://dev.to/neshaz/agile-and-scrum-our-favorite-duo-56b2</guid>
      <description>&lt;p&gt;In our previous articles we wrote about &lt;a href="https://kolosek.com/agile-philosophy-youll-love/"&gt;Agile&lt;/a&gt; and &lt;a href="https://kolosek.com/scrum-agile-put-into-practice/"&gt;Scrum&lt;/a&gt;, separately, and now &lt;strong&gt;we decided to mix them and bring together&lt;/strong&gt;. If you want to know more, be sure to read those blog posts, and now, let's get to the the benefits of both of these productivity raisers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Agile and Scrum
&lt;/h2&gt;

&lt;p&gt;These two grew up in the same cocoon. Precisely, &lt;strong&gt;Agile is Scrum's older and wiser relative&lt;/strong&gt;, similar to Rick and Morty.&lt;br&gt;
As you probably learned by now, Agile is a philosophy, a concept that explains how a team should do a project, on a theoretical level. &lt;strong&gt;Agile describes principles, while Scrum is all about implementing principles&lt;/strong&gt; by following the rules. Agile is a philosophy and Scrum a methodology.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q3v8Iv8T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.googleapis.com/kolosekblog/2017/11/paul-bence-395888-7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q3v8Iv8T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.googleapis.com/kolosekblog/2017/11/paul-bence-395888-7.jpg" alt="Agile and Scrum_4"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Agile and Scrum - the similarities
&lt;/h2&gt;

&lt;p&gt;The similarities are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;using an iterative approach of making a project,&lt;/li&gt;
&lt;li&gt;adapting to change,&lt;/li&gt;
&lt;li&gt;making improvements,&lt;/li&gt;
&lt;li&gt;delivering the product on time.
## Using Scrum
Scrum is not for everybody. I mean, it is, but you don't need it all the time. Here are some cases in which Scrum can help:&lt;/li&gt;
&lt;li&gt;when you are about to do a large project,&lt;/li&gt;
&lt;li&gt;when there is no deadline for an app to be delivered to the client,&lt;/li&gt;
&lt;li&gt;when team members want more autonomy.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kUXDOi_e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.googleapis.com/kolosekblog/2017/11/lee-campbell-86958-5.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kUXDOi_e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.googleapis.com/kolosekblog/2017/11/lee-campbell-86958-5.jpg" alt="Agile and Scrum_12"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Not to sound rude, but Scrum is &lt;strong&gt;amazing for clients that change their minds quickly&lt;/strong&gt; and are not sure what exactly they want because development team can easily adapt to that change.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Agile
&lt;/h2&gt;

&lt;p&gt;Every time you think you need a project management concept, think of Agile. No matter for which method you decide to go with, &lt;strong&gt;Agile, as a philosophy, is the way to go.&lt;/strong&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  In the end...
&lt;/h2&gt;

&lt;p&gt;... Agile and Scrum are inseparable. &lt;strong&gt;They go like hamburger and french fries.&lt;/strong&gt; Not from McDonald's. From some fancy restaurant that sells hamburgers. Delicious!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EEmCqNmy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.googleapis.com/kolosekblog/2017/11/edward-franklin-72304-11.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EEmCqNmy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.googleapis.com/kolosekblog/2017/11/edward-franklin-72304-11.jpg" alt="Agile and Scrum-11"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to know more about Agile, also check out &lt;a href="https://kolosek.com/lean-agile-enemies-or-friends/"&gt;our post on Agile and Lean&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Hope you learned something new today.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="//kolosek.com/agile-and-scrum/"&gt;Kolosek blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>agile</category>
      <category>scrum</category>
    </item>
    <item>
      <title>How to Plan and Build a Profitable Mobile App?</title>
      <dc:creator>Nesha Zoric</dc:creator>
      <pubDate>Wed, 22 Apr 2020 09:22:54 +0000</pubDate>
      <link>https://dev.to/neshaz/how-to-plan-and-build-a-profitable-mobile-app-4ood</link>
      <guid>https://dev.to/neshaz/how-to-plan-and-build-a-profitable-mobile-app-4ood</guid>
      <description>&lt;p&gt;There are currently &lt;a href="https://www.statista.com/statistics/276623/number-of-apps-available-in-leading-app-stores/"&gt;almost 10.000.000 mobile apps available in the leading app stores.&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Yes, there are 10 million pieces of software on the market. And there’s always someone thinking about making a new one. An app that’s going to kick the others out of the game, become super popular and make a ton of money in the process. If you’re one of the people with such thoughts on their mind, then this short guide is for you.&lt;/p&gt;

&lt;p&gt;We’ll go through exactly &lt;strong&gt;what you need to think about before even starting the project&lt;/strong&gt;, and then we’ll explain how to start it off on the right foot.&lt;br&gt;
However, if your idea is to build a mobile game, then this post is not for you. The game industry has different rules and nuances you need to learn about. It might be a topic of some other post on this blog, but not this one.&lt;/p&gt;

&lt;p&gt;So, let’s get down to business.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to make sure my mobile app will be successful?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Is your app solving a problem?
&lt;/h3&gt;

&lt;p&gt;This might seem like common business sense, but quite often we see enthusiastic people on their way to build an app they believe in without actual need. What does that mean? Well, either they or someone they know encountered a specific problem, and they feel they could easily solve it with an app.&lt;br&gt;
That’s a great starting point for any business - &lt;strong&gt;identifying a problem, a pain point, that you can find a solution for&lt;/strong&gt;. But, it’s a terribly bad idea if you don’t do a couple of things before running into a demanding venture.&lt;br&gt;
If you think you have a perfect solution for your aunt Gracy’s cat’s problem, first make sure that other cat owners are struggling with the same issues. Your aunt and her friends aren’t a very large user pool. So, once you’ve identified the problem, you need to do your research. &lt;br&gt;
&lt;strong&gt;Are there really enough potential users?&lt;/strong&gt; You don’t need to find 10.000 people, a small relevant sample will do. Find an online venue (Facebook group, Twitter, email list…) where your target group gathers and give them a questionnaire in a form that works best for you. Use this to find out exactly what they’re struggling with and how they’re solving it. You can also use this as an opportunity to gather your &lt;strong&gt;initial user group&lt;/strong&gt;. At the end of the questionnaire, offer to let them know about your launch (or offer a discount) in return for their email address or phone number. This will come in handy since you'll have qualified leads before you even have the final product.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Recap&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is it a real problem?&lt;/li&gt;
&lt;li&gt;Are there enough potential users to make the app profitable?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Who else is solving the same problem?
&lt;/h3&gt;

&lt;p&gt;With millions of mobile apps out there, it's very likely someone else is trying to do the same thing. Find them and research them thoroughly.&lt;br&gt;&lt;br&gt;
How are they approaching the problem? How successful are they? For how long have they existed and how big is their user base?&lt;br&gt;
If they failed, why and how did it happen? You can do the research on &lt;a href="http://startupgraveyard.io/"&gt;Startup graveyard &lt;/a&gt;and &lt;a href="http://autopsy.io/"&gt;autopsy.io.&lt;/a&gt; These two handy websites will give you &lt;strong&gt;a bunch of stories about startup failure&lt;/strong&gt;. They're not meant to demotivate you, but to help you know what to look out for. There's also a &lt;a href="https://www.reddit.com/r/shutdown/"&gt;/r/shutdown&lt;/a&gt; subreddit, if you prefer this platform for getting your information.&lt;br&gt;
&lt;strong&gt;Take a close look at your competitors&lt;/strong&gt; and find their weak points. Are they failing their users in an important area? Is their service excelling at something particular? Use them as a great source of information and gather as much as you can.&lt;br&gt;
Maybe your service will be complementary to theirs and you can actually partner up? Keep your mind open to such options. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Recap&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Go into depth when researching your competitors.&lt;/li&gt;
&lt;li&gt; Keep your mind open to "unconventional" possibilities.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. What is going to hold you down?
&lt;/h3&gt;

&lt;p&gt;Are there any legal implications you should be aware of? If you're tapping into a niche that's rigorously regulated, you need to talk to an expert before you proceed any further. &lt;br&gt;
If you'll intend to collect any personal data from your users, how will you enable security and privacy protection?&lt;br&gt;
No matter what you're doing, &lt;strong&gt;it's good to have a lawyer and an IT security expert at least as consultants&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Recap&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Legal and security aspects are very important.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. How will you monetize it?
&lt;/h3&gt;

&lt;p&gt;It's a decision you need to make early on as it will determine the profitability of your project. &lt;br&gt;
&lt;strong&gt;Are you going to charge for the app?&lt;/strong&gt; Will you go with the free app + paid upgrades? If you're not an expert in the pricing area, then this is something to discuss with your team or a professional consultant. &lt;strong&gt;You need someone who is experienced in the industry.&lt;/strong&gt;&lt;br&gt;
There is more than one tool you can use for this including &lt;a href="https://www.google.com/admob/monetize.html#?monetize-tabset_activeEl=overview"&gt;Google AdMob&lt;/a&gt; and &lt;a href="https://developers.facebook.com/products/app-monetization/audience-network/"&gt;Facebook Audience Network&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Recap&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Think about the money.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. It's a project
&lt;/h3&gt;

&lt;p&gt;Developing an app should be taken as a serious project. And a serious project means there is &lt;strong&gt;serious management&lt;/strong&gt;. You need to plan carefully and find the best team possible. That is not the easiest task if you're just starting out and don't really have much money to throw at this project.&lt;br&gt;
&lt;strong&gt;If you're a developer yourself&lt;/strong&gt;, you'll most likely need a marketing and sales person. Also, another developer for peer review always comes in handy. Make sure you know where you're going with the app and give yourself deadlines. The next step is to actually try and follow those deadlines. Seriously. &lt;br&gt;
&lt;strong&gt;If you're not a developer&lt;/strong&gt;, you'll need at least one, depending on the complexity of the app. Make sure you choose carefully. We wrote about that in our blog post about outsourcing. The same principles can be used if you're a non-tech person who's picking a developer.&lt;br&gt;
Either way, &lt;strong&gt;put it all on paper&lt;/strong&gt;, be honest about what you can(not) do and find the holes you can't fill. Then look for people who could help you on your journey. One can do very little on their own. You DO need a team, no matter how small it is in the beginning.&lt;br&gt;
If you can't pay for them, you can offer them a percentage of ownership. Or you can find a different deal that is going to work for everyone.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Recap&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Take your project seriously.&lt;/li&gt;
&lt;li&gt; Hire a team.&lt;/li&gt;
&lt;li&gt;Try and stick to the deadlines.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;All in all, it is going to be a bumpy ride for you (and your teammates). Buckle up, get ready and good luck!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="//kolosek.com/building-profitable-mobile-app/"&gt;Kolosek blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mobile</category>
      <category>app</category>
      <category>build</category>
    </item>
    <item>
      <title>Delegate in Rails</title>
      <dc:creator>Nesha Zoric</dc:creator>
      <pubDate>Tue, 21 Apr 2020 09:59:23 +0000</pubDate>
      <link>https://dev.to/neshaz/delegate-in-rails-2a4e</link>
      <guid>https://dev.to/neshaz/delegate-in-rails-2a4e</guid>
      <description>&lt;p&gt;A model should only talk to its immediate association. According to the Law of Demeter, you shouldn’t talk to the association’s property or association’s association.&lt;/p&gt;

&lt;p&gt;Here we talk about Rails delegate approach.&lt;/p&gt;

&lt;h2&gt;
  
  
  BAD SMELL
&lt;/h2&gt;

&lt;p&gt;class Profile &amp;lt; ActiveRecord::Base&lt;br&gt;
belongs_to :user&lt;br&gt;
end&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;%= @profile.user.address %&amp;gt;
&amp;lt;%= @profile.user.city %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Rails provides helper method to accomplish delegation, which uses DSL to generate wrapper methods. It can also prevent error call method on nil object if :allow_nil =&amp;gt; true is added.&lt;/p&gt;

&lt;h2&gt;
  
  
  Refactored
&lt;/h2&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Profile &amp;lt; ActiveRecord::Base
  belongs_to :user
  delegate :address, :city, :to =&amp;gt; :user, :prefix =&amp;gt; true, :allow_nil =&amp;gt; true
end
&amp;lt;%= @profile.user_address %&amp;gt;
&amp;lt;%= @profile.user_city %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="//kolosek.com/rails-delegate/"&gt;Kolosek blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>rails</category>
      <category>delegate</category>
    </item>
    <item>
      <title>line-height in CSS</title>
      <dc:creator>Nesha Zoric</dc:creator>
      <pubDate>Wed, 15 Apr 2020 12:54:56 +0000</pubDate>
      <link>https://dev.to/neshaz/line-height-in-css-3k76</link>
      <guid>https://dev.to/neshaz/line-height-in-css-3k76</guid>
      <description>&lt;p&gt;The CSS property &lt;strong&gt;&lt;a href="https://www.w3schools.com/cssref/pr_dim_line-height.asp"&gt;line-height&lt;/a&gt;&lt;/strong&gt; defines the amount of space used for lines, most commonly in the text. &lt;/p&gt;

&lt;p&gt;It is often confused with &lt;strong&gt;line spacing (leading)&lt;/strong&gt; used in Photoshop and similar softwares.&lt;/p&gt;

&lt;p&gt;Leading is a term that describes the distance between the baselines in the text. In the case of defining leading, space is always &lt;strong&gt;added below the text&lt;/strong&gt;. But, when working with line-height property, space is always added &lt;strong&gt;equally above and below the text&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Line-height uses several different types of &lt;strong&gt;units&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;px&lt;/strong&gt;,&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;em&lt;/strong&gt;,&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;%&lt;/strong&gt;,&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;unitless number&lt;/strong&gt;,&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s important to mention that the &lt;strong&gt;unitless value is, basically, just a percentage&lt;/strong&gt;. So, if the line-height has a property of &lt;strong&gt;1.2&lt;/strong&gt;, it means it just has a value of &lt;strong&gt;120%&lt;/strong&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Importance of line-height
&lt;/h2&gt;

&lt;p&gt;The most important use of line-height is &lt;strong&gt;making your text readable&lt;/strong&gt;. It is recommended to use unitless values of any other unit that &lt;strong&gt;isn’t static&lt;/strong&gt; like the px unit. &lt;/p&gt;

&lt;p&gt;If there is a need to set the font size and line-height at the same time, there is a handy CSS &lt;strong&gt;shorthand&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;html {
  font: 24px/1.5 ‘Lato’, sans-serif;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;By using this shorthand you will be able to set 3 elements at the same time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;font-size,&lt;/li&gt;
&lt;li&gt;line-height,&lt;/li&gt;
&lt;li&gt;font-family.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The line-height property applies only to elements that have their display property set to &lt;strong&gt;inline or inline-block&lt;/strong&gt;. If the line-height is set on a block element, there might be some changes, but it is probably just the &lt;strong&gt;inline child&lt;/strong&gt; elements that have been affected. &lt;/p&gt;

&lt;p&gt;If you set the line-height without a unit, the result is the &lt;strong&gt;line-height value multiplied by the element’s font-size&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  Font-family: ‘Lato’, sans-serif;
  Font-size: 14px;
  Line-height: 2 // equals to 28px
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Hope this article helped clarify the meaning and usage of the line-height property.&lt;/p&gt;

&lt;p&gt;Thank you for reading!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="//kolosek.com/css-line-height/"&gt;Kolosek blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>lineheight</category>
      <category>css</category>
    </item>
    <item>
      <title>9 Ruby on Rails Blogs to Follow</title>
      <dc:creator>Nesha Zoric</dc:creator>
      <pubDate>Tue, 14 Apr 2020 08:55:40 +0000</pubDate>
      <link>https://dev.to/neshaz/9-ruby-on-rails-blogs-to-follow-5ck5</link>
      <guid>https://dev.to/neshaz/9-ruby-on-rails-blogs-to-follow-5ck5</guid>
      <description>&lt;p&gt;If you’re a Rails developer (or aspiring to become one), you know how important it is to stay up to date with all Ruby related news. It can sometimes even be overwhelming because there are &lt;strong&gt;so many sources of information online&lt;/strong&gt;. It can be hard to determine which ones are actually legitimate.&lt;br&gt;
Also, every developer appreciates the help of a community. Problems are solved much faster with other people’s experience.&lt;br&gt;
So, here are the best everyday reads for busy a Ruby on Rails developer who wants to keep up.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="http://rubyweekly.com/"&gt;1. Ruby Weekly&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;We all hate boring and spammy newsletters. This is definitely not one of them. Ruby Weekly is very &lt;strong&gt;concise, to the point and current&lt;/strong&gt;. They will deliver one newsletter to your inbox per week, and it will be packed with useful info, no matter what you do with your Ruby code. &lt;br&gt;
There’s a sample issue of the latest newsletter so you can take a look at that before deciding whether you want to give them your email address.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://everydayrails.com/"&gt;2. Everyday Rails&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;This blog has been around for a while now. It’s not updated regularly, but it’s packed with useful stuff, especially if you’re into testing. It also contains a lot of handy tips you can use to &lt;strong&gt;make your workday easier&lt;/strong&gt;.&lt;br&gt;
The blog has a “get things done” approach and that’s probably what we like most about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="http://weblog.rubyonrails.org/"&gt;3. The Official Rails Blog&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Well, of course. We recommend the official RoR blog for timely updates about the framework. It contains all the relevant changelogs for the gems.&lt;br&gt;
There’s also a &lt;strong&gt;“This Week in Rails” section&lt;/strong&gt; with practical tips from developers.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.reddit.com/r/ruby/"&gt;4. /r/ruby&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;If you’re not already using Reddit as a channel for learning about development, it’s high time you got started. &lt;br&gt;
/r/ruby is a lively &lt;strong&gt;community&lt;/strong&gt; full of people who are ready to share their knowledge (and their frustrations)&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.driftingruby.com/episodes"&gt;5. Drifting Ruby&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;This is a screencast and a blog which is updated fairly often. So, if you’re &lt;strong&gt;a fan of learning things visually&lt;/strong&gt;, this is a great place.&lt;br&gt;
The website is run by a Rubyist Dave Kimura.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="http://railscasts.com/"&gt;6. RailsCasts&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;While we’re at screencasts, we have to mention the RailsCasts.&lt;br&gt;
This website hasn’t been running for a while now, but the archives are definitely worth the visit, especially &lt;strong&gt;for someone who’s just starting out&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="http://www.rubyinside.com/"&gt;7. Ruby Inside&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;This is another blog with news and tutorials that haven’t been updated in the past few years. Again, the archive is more than valuable for issues we’re facing today. &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.youtube.com/channel/UCIQmhQxCvLHRr3Beku77tww/featured"&gt;8. Go Rails&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Another one &lt;strong&gt;for visual learners&lt;/strong&gt;. GoRails YouTube channel is updated weekly and contains detailed tutorials. Most videos are just a few minutes long, but the longest you’ll &lt;strong&gt;spend on a single video is around 20 minutes&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;The description of the screencasts states they are there to “fill in the gaps, explain the confusing pieces, and give you an understanding you can't find elsewhere”.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="http://www.rubyflow.com/"&gt;9. Ruby Flow&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;If you enjoy the concept of HackerNews, you’ll like Ruby Flow. It’s just the community, pushing out the content they find most useful. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What should we add to the list?&lt;/strong&gt; Share your favorite blogs, YouTube channels, subreddits or other sources you use for Rails in the comments below.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="//kolosek.com/learn-ruby-on-rails-blogs/"&gt;Kolosek blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>rails</category>
      <category>blog</category>
    </item>
    <item>
      <title>Rails Scaffold</title>
      <dc:creator>Nesha Zoric</dc:creator>
      <pubDate>Thu, 09 Apr 2020 12:19:50 +0000</pubDate>
      <link>https://dev.to/neshaz/rails-scaffold-1bl</link>
      <guid>https://dev.to/neshaz/rails-scaffold-1bl</guid>
      <description>&lt;p&gt;Scaffolding in Ruby on Rails refers to the &lt;strong&gt;auto-generation&lt;/strong&gt; of a set of a model, views and a controller usually used for a single database table.&lt;/p&gt;

&lt;p&gt;For example, you can auto-generate a ready to use controller, model, and views with a full &lt;strong&gt;CRUD&lt;/strong&gt; (&lt;strong&gt;C&lt;/strong&gt;reate, &lt;strong&gt;R&lt;/strong&gt;ead, &lt;strong&gt;U&lt;/strong&gt;pdate, &lt;strong&gt;D&lt;/strong&gt;elete) web interface for the Story table using the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$rails generate scaffold Story title:string content:text&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It's way easier to do this, instead of coding everything yourself, it saves you a lot of time!&lt;/p&gt;

&lt;h2&gt;
  
  
  Scaffold or Models?
&lt;/h2&gt;

&lt;p&gt;Compared to the &lt;strong&gt;scaffold&lt;/strong&gt; that generates everything that you need (and don't need), &lt;strong&gt;models&lt;/strong&gt; create only some related components. The best, and my favorite, way to explain the difference between scaffold and models is by using the following example:&lt;/p&gt;

&lt;h3&gt;
  
  
  Generate models
&lt;/h3&gt;

&lt;p&gt;Once you enter the command &lt;code&gt;$rails generate model Story title:string content:text&lt;/code&gt; you will generate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;invoke  active_record
create    db/migrate/20180205103025_create_stories.rb
create    app/models/story.rb
invoke    test_unit
create      test/models/story_test.rb
create      test/fixtures/stories.yml
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;invoke active_record&lt;/strong&gt; will tie your model to the database, while the next line creates &lt;strong&gt;a migration file&lt;/strong&gt;. Migrations are used to alter your database schema. This migration file creates the database table called 'stories', and database columns for "title" and "content".&lt;/p&gt;

&lt;p&gt;The third line will create a &lt;strong&gt;model&lt;/strong&gt; - a Ruby class that inherits the Active Record. With this, every method that can be called in Active Record can now be called in your model. The last three lines create related &lt;strong&gt;&lt;a href="https://kolosek.com/rails-rspec-setup/"&gt;test files&lt;/a&gt;&lt;/strong&gt; for your model.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;While scaffolding will get you up and running quickly, the code it generates is unlikely to be a perfect fit for your application. You’ll most probably want to customize the generated code. Many experienced Rails developers avoid scaffolding entirely, preferring to write all or most of their source code from scratch. You can read more about this on &lt;a href="http://guides.rubyonrails.org/v3.2/getting_started.html#getting-up-and-running-quickly-with-scaffolding"&gt;RailsGuides&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As you can see, &lt;strong&gt;generate models&lt;/strong&gt; does not create any kind of view to display information on a page. To have a complete, ready to use application, you would need to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;generate controllers&lt;/strong&gt; (which in turn generates views, as well) or&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;generate scaffold&lt;/strong&gt; (which generates your model, views, controller and writes to your routes.rb file).&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you change your mind and decide to use scaffold after already generating the model, you can always run &lt;code&gt;$rails generate scaffold &amp;lt;name&amp;gt;&lt;/code&gt;. It will create all the missing files.&lt;/p&gt;

&lt;h3&gt;
  
  
  Generate scaffold
&lt;/h3&gt;

&lt;p&gt;If you enter the command &lt;code&gt;$rails generate scaffold Story title:string content:text&lt;/code&gt; you will generate the following files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;invoke  active_record
create    db/migrate/20180205103508_create_stories.rb
create    app/models/story.rb
invoke    test_unit
create      test/models/story_test.rb
create      test/fixtures/stories.yml
invoke  resource_route
route    resources :stories
invoke  scaffold_controller
create    app/controllers/stories_controller.rb
invoke    erb
create      app/views/stories
create      app/views/stories/index.html.erb
create      app/views/stories/edit.html.erb
create      app/views/stories/show.html.erb
create      app/views/stories/new.html.erb
create      app/views/stories/_form.html.erb
invoke    test_unit
create      test/controllers/stories_controller_test.rb
invoke    helper
create      app/helpers/stories_helper.rb
invoke      test_unit
invoke    jbuilder
create      app/views/stories/index.json.jbuilder
create      app/views/stories/show.json.jbuilder
create      app/views/stories/_story.json.jbuilder
invoke  assets
invoke    coffee
create      app/assets/javascripts/stories.coffee
invoke    scss
create      app/assets/stylesheets/stories.scss
invoke  scss
create    app/assets/stylesheets/scaffolds.scss
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once model related tests are created, the next line will generate &lt;strong&gt;resource routes&lt;/strong&gt; to your stories. After generating resource routes comes the &lt;strong&gt;controller&lt;/strong&gt; and its actions (index, show, new, edit, create, update and destroy), together with &lt;strong&gt;views&lt;/strong&gt; and &lt;a href="https://kolosek.com/rspec-controller-test/"&gt;controller tests&lt;/a&gt; for each of this actions.&lt;/p&gt;

&lt;p&gt;The Rails router recognizes URLs and connects them to a controller's action. By default, a controller's action will render a view of the same name.&lt;/p&gt;

&lt;h2&gt;
  
  
  Migration
&lt;/h2&gt;

&lt;p&gt;Every time you create a &lt;strong&gt;migration&lt;/strong&gt; using scripts (generate model/generate scaffold) a new migration is added to the correct directory. You use &lt;code&gt;$rake db:migrate&lt;/code&gt; to checks which migrations that have not been added to the database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;== 20180205103508 CreateStories: migrating ====================================
-- create_table(:stories)
   -&amp;gt; 0.0007s
== 20180205103508 CreateStories: migrated (0.0008s) ===========================
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Destroy
&lt;/h2&gt;

&lt;p&gt;Everyone is free to edit and do the necessary changes to their application to work as intended, even if it means completely &lt;strong&gt;removing scaffold&lt;/strong&gt;. You can remove scaffold in the following way:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Generate scaffold: &lt;code&gt;$rails generate scaffold Story&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;If you migrated your files, perform a rollback: &lt;code&gt;$rake db:rollback&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Destroy or undo scaffold: &lt;code&gt;$rails destroy scaffold Story&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By doing this, you will delete all the files created by the scaffold but additional changes that you may have done manually will not be removed.&lt;/p&gt;

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

&lt;p&gt;A scaffold is excellent to use when it comes to &lt;strong&gt;simple examples, quick mockups or testing&lt;/strong&gt;. However, be sure to generate your own models when you decide to develop a new application. Don't forget to always test your application, find out how to do it by using &lt;a href="https://kolosek.com/rails-capybara-setup/"&gt;Capybara&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;We hope you discovered something new today!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://kolosek.com/rails-scaffold/"&gt;Kolosek blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>rails</category>
      <category>scaffold</category>
    </item>
    <item>
      <title>CSS Position Relative vs Position Absolute</title>
      <dc:creator>Nesha Zoric</dc:creator>
      <pubDate>Fri, 03 Apr 2020 08:27:48 +0000</pubDate>
      <link>https://dev.to/neshaz/css-position-relative-vs-position-absolute-26ok</link>
      <guid>https://dev.to/neshaz/css-position-relative-vs-position-absolute-26ok</guid>
      <description>&lt;p&gt;The CSS &lt;a href="https://www.w3schools.com/cssref/pr_class_position.asp" rel="noopener noreferrer"&gt;position&lt;/a&gt; property defines, as the name says, how the element is positioned on the web page. &lt;/p&gt;

&lt;p&gt;If you are interested in reading about the font properties, articles about the &lt;a href="https://kolosek.com/css-relative-font-size/" rel="noopener noreferrer"&gt;relative font size&lt;/a&gt; and &lt;a href="https://kolosek.com/css-columns/" rel="noopener noreferrer"&gt;CSS columns&lt;/a&gt; might be of interest. &lt;/p&gt;

&lt;p&gt;So, there are several types of positioning: &lt;strong&gt;static, relative, absolute, fixed, sticky, initial and inherit&lt;/strong&gt;. First of all, let’s explain what all of these types mean.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Static&lt;/strong&gt; - this is the default value,  all elements are in order as they appear in the document.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Relative&lt;/strong&gt; - the element is positioned relative to its normal position.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Absolute&lt;/strong&gt; - the element is positioned absolutely to its first positioned parent.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fixed&lt;/strong&gt; - the element is positioned related to the browser window.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sticky&lt;/strong&gt; - the element is positioned based on the user’s scroll position. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that we have explained the basics, we will talk more about the two most commonly used position values - &lt;strong&gt;relative and absolute&lt;/strong&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Relative Positioning?
&lt;/h2&gt;

&lt;p&gt;When you set the position &lt;em&gt;relative to an element&lt;/em&gt;, without adding any other positioning attributes (top, bottom, right, left) &lt;strong&gt;nothing will happen&lt;/strong&gt;. When you add an additional position apart from relative, such as left: 20px the element will move 20px to the right from its normal position. Here, you can see that &lt;strong&gt;this element is relative to itself&lt;/strong&gt;. When the element moves, no other element on the layout will be affected. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;There is a thing you should keep in mind while setting position - relative to an element limits the scope of absolutely positioned child elements. This means that any element that is the child of this element can be absolutely positioned within this block.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After this brief explanation, we need to back it up, by showing an example. &lt;/p&gt;

&lt;p&gt;In this example, you will see how the relative positioned element moves when its attributes are changed. The first element moves to the &lt;strong&gt;left&lt;/strong&gt; and &lt;strong&gt;top&lt;/strong&gt; from its normal position, while &lt;strong&gt;the second element stays in the same place&lt;/strong&gt; because none of the additional positioning attributes were changed. &lt;/p&gt;

&lt;h3&gt;
  
  
  HTML
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div id=”first_element”&amp;gt;First element&amp;lt;/div&amp;gt;
&amp;lt;div id=”second_element”&amp;gt;Second element&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  CSS
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#first_element {
  position: relative;
  left: 30px;
  top: 70px;

  width: 500px;
  background-color: #fafafa;
  border: solid 3px #ff7347;
  font-size: 24px;
  text-align: center;
}

#second_element {
   position: relative;

   width: 500px;
   background-color: #fafafa;
   border: solid 3px #ff7347;
   font-size: 24px;
   text-align: center;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fstorage.kraken.io%2Fkk8yWPxzXVfBD3654oMN%2Fcf2f3745c0023aece34ab9ed11eb1051%2Fposition_relative.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fstorage.kraken.io%2Fkk8yWPxzXVfBD3654oMN%2Fcf2f3745c0023aece34ab9ed11eb1051%2Fposition_relative.png" alt="css_position_relative"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Absolute Positioning?
&lt;/h2&gt;

&lt;p&gt;Absolute positioning allows you to &lt;strong&gt;place your element precisely where you want it&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Absolute positioning is done &lt;strong&gt;relative to the first relatively (or absolutely) positioned parent element&lt;/strong&gt;. In the case when there is no positioned parent element, the element that has position set to absolute will be positioned related &lt;strong&gt;directly to the HTML element (the page itself)&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;An important thing to keep in mind while using absolute positioning is to make sure it is &lt;strong&gt;not overused&lt;/strong&gt;, otherwise, it can lead to a maintenance nightmare.&lt;/p&gt;

&lt;p&gt;The next thing, yet again, is to show an example of absolute positioning.&lt;/p&gt;

&lt;p&gt;In the example, the parent element has the position set to relative. Now, when you set the position of the child element to absolute, &lt;strong&gt;any additional positioning will be done relative to the parent element&lt;/strong&gt;. The child element moves relatively to the top of the parent element by 100px and right of the parent element by 40px.&lt;/p&gt;

&lt;h3&gt;
  
  
  HTML
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div id=”parent”&amp;gt;
  &amp;lt;div id=”child”&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  CSS
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#parent {
  position: relative;

  width: 500px; 
  height: 400px;
  background-color: #fafafa;
  border: solid 3px #9e70ba;
  font-size: 24px;
  text-align: center;
}

#child {
  position: absolute;
  right: 40px;
  top: 100px;

  width: 200px;
  height: 200px;
  background-color: #fafafa;
  border: solid 3px #78e382;
  font-size: 24px;
  text-align: center;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fstorage.kraken.io%2Fkk8yWPxzXVfBD3654oMN%2F5ffb6395cad066a2a135d181569d5f8d%2Fposition_absolute.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fstorage.kraken.io%2Fkk8yWPxzXVfBD3654oMN%2F5ffb6395cad066a2a135d181569d5f8d%2Fposition_absolute.png" alt="css_position_absolute"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Through these examples, you have seen differences between absolute and relative positioned elements.&lt;/p&gt;

&lt;p&gt;We hope this article clarified some doubts related to absolute and relative positioning and will help in any future projects.&lt;/p&gt;

&lt;p&gt;Check out other detailed articles related to CSS properties such as this one: &lt;a href="https://kolosek.com/css-position-relative-vs-position-absolute/" rel="noopener noreferrer"&gt;CSS Positions&lt;/a&gt;, &lt;a href="https://kolosek.com/nesting-in-less-and-sass/" rel="noopener noreferrer"&gt;SASS and LESS Nesting&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://kolosek.com/css-position-relative-vs-position-absolute/" rel="noopener noreferrer"&gt;Kolosek blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>positionrelative</category>
      <category>positionabsolute</category>
    </item>
  </channel>
</rss>
