<?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: Alan Patrick</title>
    <description>The latest articles on DEV Community by Alan Patrick (@opatrickvico).</description>
    <link>https://dev.to/opatrickvico</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%2F893554%2F980f6aac-684c-41c5-979a-02262833e8d5.jpeg</url>
      <title>DEV Community: Alan Patrick</title>
      <link>https://dev.to/opatrickvico</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/opatrickvico"/>
    <language>en</language>
    <item>
      <title>OOP, the right way: Message Passing and the Four Pillars</title>
      <dc:creator>Alan Patrick</dc:creator>
      <pubDate>Mon, 22 Jan 2024 13:08:06 +0000</pubDate>
      <link>https://dev.to/opatrickvico/oop-the-right-way-message-passing-and-the-four-pillars-oo8</link>
      <guid>https://dev.to/opatrickvico/oop-the-right-way-message-passing-and-the-four-pillars-oo8</guid>
      <description>&lt;p&gt;I just watched &lt;a href="https://www.youtube.com/watch?v=STtOP6d7K_4"&gt;an old video of ThePrimeagen&lt;/a&gt; about message passing in OOP, and I wanted to write an article that explained the topic better. So here we are.&lt;/p&gt;

&lt;p&gt;Message passing, for those who don't know, is essentially a trigger for an object to act. Somehow, "message passing" became "method calls". Javascript, despite not being &lt;a href="https://en.wikipedia.org/wiki/Smalltalk"&gt;Smalltalk&lt;/a&gt;, already has a nice mechanism for messages, though. You can access an object's fields dynamically:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;message&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;](...&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allows you to access the behavior associated with the message. Behavior is not the same as a method call. Behaviors can be many private methods at once, public methods or even reference usage of other objects. What matters is the declarative API that message passing enables. This attains the principle of &lt;code&gt;Abstraction&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;jose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;José&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;jose&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;greet&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]();&lt;/span&gt; &lt;span class="c1"&gt;// prints "Hello, I am José!"&lt;/span&gt;
&lt;span class="nx"&gt;jose&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sum&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// prints "I am bad at math!!!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we give the same message to different objects, what happens? We get &lt;code&gt;Polymorphism&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;jose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;José&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fusca&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Fusca&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pimenta&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Pimenta&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;jose&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;greet&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]();&lt;/span&gt; &lt;span class="c1"&gt;// prints "Hello, I am José!"&lt;/span&gt;
&lt;span class="nx"&gt;fusca&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;greet&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]();&lt;/span&gt; &lt;span class="c1"&gt;// prints "Beep!"&lt;/span&gt;
&lt;span class="nx"&gt;pimenta&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;greet&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]();&lt;/span&gt; &lt;span class="c1"&gt;// prints "Woof!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To teach José some math, we can't simply open José's brain and shove math inside it — it isn't how brains work in real life, so it won't be how we model our system here. José will be properly taught. Let's introduce him to Maria, a teacher:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;jose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;José&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;maria&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Teacher&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Maria&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Note the new class&lt;/span&gt;

&lt;span class="nx"&gt;maria&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;greet&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="nx"&gt;jose&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// prints "Hello, José, I am Maria!"&lt;/span&gt;

&lt;span class="nx"&gt;jose&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;greet-back&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="nx"&gt;maria&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// prints "Hello, Maria, nice to meet you!"&lt;/span&gt;

&lt;span class="c1"&gt;// José even knows how to `greet-back` — how fancy.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See how the &lt;code&gt;greet&lt;/code&gt; message is different this time? Behaviors can be modified with parameters. This is also a great example of the principle of &lt;code&gt;Inheritance&lt;/code&gt;: A teacher is a person, and all persons know how to greet. Maria, being a teacher and person, knows how to greet too.&lt;/p&gt;

&lt;p&gt;Finally, let's teach José some math:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Checking again if José knows math:&lt;/span&gt;

&lt;span class="nx"&gt;jose&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sum&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// prints "I am bad at math!!!" still!&lt;/span&gt;

&lt;span class="c1"&gt;// Nothing new. Let's have Maria to teach him:&lt;/span&gt;
&lt;span class="nx"&gt;maria&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;teach&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="nx"&gt;jose&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;math&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;jose&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sum&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// prints "2 plus 2 is 4."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What happened with José? Did Maria just shove math into his brain? Let's take a look at the &lt;code&gt;teach&lt;/code&gt; behavior below. Since objects cannot change the state of other objects, you must pass the message and let them deal with it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Teacher&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// ... other logic goes here&lt;/span&gt;

  &lt;span class="nf"&gt;teach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;learn&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="nx"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That rule of not touching the internal state of another object is called &lt;code&gt;Encapsulation&lt;/code&gt;. Only José can truly learn — Maria can only help. José is a good student and, now that he knows math, he behaves differently when prompted to sum two numbers.&lt;/p&gt;

&lt;p&gt;And there you have it: We explored the four pillars of Object Oriented Programming through the lenses of Message Passing. &lt;/p&gt;

&lt;p&gt;Hope you enjoyed it!&lt;/p&gt;

</description>
      <category>oop</category>
      <category>programming</category>
    </item>
    <item>
      <title>OOP do jeito certo: Passagem de Mensagem e os Quatro Pilares</title>
      <dc:creator>Alan Patrick</dc:creator>
      <pubDate>Mon, 22 Jan 2024 13:07:55 +0000</pubDate>
      <link>https://dev.to/opatrickvico/oop-do-jeito-certo-passagem-de-mensagem-e-os-quatro-pillares-287p</link>
      <guid>https://dev.to/opatrickvico/oop-do-jeito-certo-passagem-de-mensagem-e-os-quatro-pillares-287p</guid>
      <description>&lt;p&gt;Acabei de assistir &lt;a href="https://www.youtube.com/watch?v=STtOP6d7K_4"&gt;um vídeo antigo do ThePrimeagen&lt;/a&gt; sobre passagem de mensagens na OOP, e quis escrever um artigo que explicasse melhor o tópico. Enãto aqui estamos.&lt;/p&gt;

&lt;p&gt;Passagem de mensagens, para aqueles que não sabem, é essencialmente um gatilho para um objeto agir. De alguma forma, "passagem de mensagens" tornou-se "evocação de métodos". JavaScript, apesar de não ser &lt;a href="https://pt.wikipedia.org/wiki/Smalltalk"&gt;Smalltalk&lt;/a&gt;, já possui um mecanismo interessante para mensagens. Você pode acessar dinamicamente os campos de um objeto:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mensagem&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;](...&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Isso permite que você acesse o comportamento associado à mensagem. Comportamento não é o mesmo que uma chamada de método. Comportamentos podem ser muitos métodos privados de uma vez, métodos públicos ou até mesmo uso de referência de outros objetos. O importante é a API declarativa que a passagem de mensagens possibilita. Isso enforça o princípio da &lt;code&gt;Abstração&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;jose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Pessoa&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;José&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;jose&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;saudacao&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]();&lt;/span&gt; &lt;span class="c1"&gt;// imprime "Olá, eu sou o José!"&lt;/span&gt;
&lt;span class="nx"&gt;jose&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;soma&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// imprime "Eu sou ruim em matemática!!!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Se dermos a mesma mensagem para diferentes objetos, o que acontece? Obtemos &lt;code&gt;Polimorfismo&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;jose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Pessoa&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;José&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fusca&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Carro&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Fusca&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pimenta&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Cachorro&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Pimenta&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;jose&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;saudacao&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]();&lt;/span&gt; &lt;span class="c1"&gt;// imprime "Olá, eu sou o José!"&lt;/span&gt;
&lt;span class="nx"&gt;fusca&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;saudacao&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]();&lt;/span&gt; &lt;span class="c1"&gt;// imprime "Beep!"&lt;/span&gt;
&lt;span class="nx"&gt;pimenta&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;saudacao&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]();&lt;/span&gt; &lt;span class="c1"&gt;// imprime "Au Au!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Para ensinar matemática a José, não podemos simplesmente abrir o cérebro dele e enfiar matemática lá dentro — não é assim que o cérebro funciona na vida real, então não será assim que modelaremos nosso sistema aqui. José será ensinado corretamente. Vamos apresentá-lo à Maria, uma professora:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;jose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Pessoa&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;José&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;maria&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;uma&lt;/span&gt; &lt;span class="nc"&gt;Professora&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Maria&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Note a nova classe&lt;/span&gt;

&lt;span class="nx"&gt;maria&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;saudacao&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="nx"&gt;jose&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// imprime "Olá, José, eu sou a Maria!"&lt;/span&gt;

&lt;span class="nx"&gt;jose&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;saudacao-de-volta&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="nx"&gt;maria&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// imprime "Olá, Maria, prazer em conhecê-la!"&lt;/span&gt;

&lt;span class="c1"&gt;// José até sabe como `saudar-de-volta` — que chique.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Vê como a mensagem &lt;code&gt;saudacao&lt;/code&gt; é diferente desta vez? Comportamentos podem ser modificados com parâmetros. Este é também um ótimo exemplo do princípio de &lt;code&gt;Herança&lt;/code&gt;: Um professor é uma pessoa, e todas as pessoas sabem como saudar. Maria, sendo professora e pessoa, sabe como saudar também.&lt;/p&gt;

&lt;p&gt;Finalmente, vamos ensinar matemática para José:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Verificando novamente se José sabe matemática:&lt;/span&gt;

&lt;span class="nx"&gt;jose&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;soma&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// imprime "Eu sou ruim em matemática!!!" ainda!&lt;/span&gt;

&lt;span class="c1"&gt;// Nada de novo. Vamos fazer Maria ensiná-lo:&lt;/span&gt;
&lt;span class="nx"&gt;maria&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ensinar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="nx"&gt;jose&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;matemática&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;jose&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;soma&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// imprime "2 mais 2 são 4."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;O que aconteceu com José? Maria simplesmente enfiou matemática em seu cérebro? Vamos dar uma olhada no comportamento &lt;code&gt;ensinar&lt;/code&gt; abaixo. Como objetos não podem mudar o estado de outros objetos, você deve passar a mensagem e deixá-los lidar com isso.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Professor&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Pessoa&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// ... outras lógicas vão aqui&lt;/span&gt;

  &lt;span class="nf"&gt;ensinar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pessoa&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;assunto&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;pessoa&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;aprender&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="nx"&gt;assunto&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Essa regra de não mexer no estado interno de outro objeto é chamada de &lt;code&gt;Encapsulamento&lt;/code&gt;. Apenas José pode realmente aprender — Maria só pode ajudar. José é um bom aluno e, agora que ele sabe matemática, ele se comporta de maneira diferente quando é pedido para somar dois números.&lt;/p&gt;

&lt;p&gt;E aí está: exploramos os quatro pilares da Programação Orientada a Objetos através da Passagem de Mensagens.&lt;/p&gt;

&lt;p&gt;Espero que tenha gostado!&lt;/p&gt;

</description>
      <category>oop</category>
      <category>programming</category>
    </item>
    <item>
      <title>From a Zettelkasten noob to another: Just Start</title>
      <dc:creator>Alan Patrick</dc:creator>
      <pubDate>Wed, 10 Jan 2024 13:38:57 +0000</pubDate>
      <link>https://dev.to/opatrickvico/from-a-zettelkasten-noob-to-another-just-start-1m5a</link>
      <guid>https://dev.to/opatrickvico/from-a-zettelkasten-noob-to-another-just-start-1m5a</guid>
      <description>&lt;p&gt;I have been thinking about how to approach my zettelkasten journey. I got the impression that creating more metadata was a good move. It would allow me to manipulate and organize notes better, as well as understand the full context of the aggregate of notes I built.&lt;/p&gt;

&lt;p&gt;More metadata means more complexity. More cognitive overhead. More time away from the notes that truly matter. For example, I started thinking about creating a whole new piece of software, that used clever database shenanigans for dynamic tag editing and retroactive metadata updates. This is a lot of stuff. Do I really need it?&lt;/p&gt;

&lt;p&gt;I started to pay more attention to what I believe is the essence of the workflow of zettelkasten:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Write one note.&lt;/li&gt;
&lt;li&gt;Write another note.&lt;/li&gt;
&lt;li&gt;If the two notes are related, link them.&lt;/li&gt;
&lt;li&gt;Keep on linking all notes that are related.&lt;/li&gt;
&lt;li&gt;Write index notes to indirectly link notes that are related, but not necessarily connected.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This understanding may be a little flawed, but showed me that you need very little for a successful zettelkasten. All you need are notes that reference others notes. No tags, no project-related-link, nada.&lt;/p&gt;

&lt;p&gt;And another thing: Thinking too deeply about this things paralises you with analysis. This paralysis stops you from messing up. Messing up is a vital component in your learning journey. The desire to avoid messing up is understandable, but you can't avoid it. Messing up is how you learn. Don't run from that, embrace it. &lt;/p&gt;

&lt;p&gt;If the way you take notes changes across time, embrace that as an exciting view on how you evolve. Keep things simple. Don't avoid messing up. Appreciate your development journey.&lt;/p&gt;

&lt;p&gt;Just write a damn note and stop overthinking things, you damn nerd!&lt;/p&gt;




&lt;p&gt;What do you guys think? What tips do you have? Please share!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freepik.com/free-vector/business-workplace-sketch-concept_9581255.htm#query=notebook%20art&amp;amp;position=7&amp;amp;from_view=keyword&amp;amp;track=ais&amp;amp;uuid=fb2e17f0-7c75-4461-87aa-381d36f25f06"&gt;Image by macrovector&lt;/a&gt; on Freepik&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Minha experiência com meditação</title>
      <dc:creator>Alan Patrick</dc:creator>
      <pubDate>Fri, 15 Sep 2023 20:03:06 +0000</pubDate>
      <link>https://dev.to/opatrickvico/minha-experiencia-com-meditacao-5he6</link>
      <guid>https://dev.to/opatrickvico/minha-experiencia-com-meditacao-5he6</guid>
      <description>&lt;p&gt;Meditação é difícil. Especialmente sem mentores por perto. A internet possui tanta informação que é fácil se perder e você precisa de tempo para se achar. Eu li uns livros. Livros de budismo, zen, até Tolle. Sentei em lotus e tive a perna formigando. Comecei, desisiti, recomecei, redesisti. Meditei de 30 segundos a 20 minutos. Não cheguei a usar mantras, mas tenho bastante conhecimento de como minha respiração funciona.&lt;/p&gt;

&lt;p&gt;Conclusão? Vale a pena. Não é milagroso, mas é um avanço na qualidade de vida. Um avanço tímido e sutil. Consigo me pegar em momentos que a mente tomaria conta e, em vez de fazer besteira, respiro fundo. Espero que melhore minha vida ainda mais, quando tiver mais prática. Quero ficar mais sereno e silencioso por mais tempo.&lt;/p&gt;

&lt;p&gt;Uma coisa esquisita que percebi é como posso usar meditação ao meu favor. Estou no processo de cortar uso excessivo de tecnologia e a meditação ajuda nisso. Agora, em vez de abrir o youtube ou o (antigo) twitter, olho pro teto. Em vez de ler enquanto faço uma refeição, o plano é simplesmente soltar a mente e prestar atenção na comida.&lt;/p&gt;

&lt;p&gt;Quando não se está distraído o tempo todo, a vida tem um aspecto diferente, inquietante. Especialmente se não tiver ninguém por perto, apenas você e o lugar. Meditação é difícil. Mas vale a pena.&lt;/p&gt;

</description>
      <category>mindfulness</category>
    </item>
    <item>
      <title>Crie um sistema automático de backup no Ubuntu com bash e crontab</title>
      <dc:creator>Alan Patrick</dc:creator>
      <pubDate>Sun, 25 Dec 2022 23:17:55 +0000</pubDate>
      <link>https://dev.to/opatrickvico/crie-um-sistema-automatico-de-backup-no-ubuntu-com-bash-e-crontab-57bk</link>
      <guid>https://dev.to/opatrickvico/crie-um-sistema-automatico-de-backup-no-ubuntu-com-bash-e-crontab-57bk</guid>
      <description>&lt;p&gt;Existe um monte de coisas legais que podem ser feitas com scripts! Uma coisa que sempre quis fazer é criar um sistema de backup que roda automaticamente em um certo ponto do dia. Agora que descobri como fazer, vou lhes mostar como criar um script com os comandos&lt;code&gt;rsync&lt;/code&gt; e &lt;code&gt;crontab&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Passo 0: Tudo começa com um BANG
&lt;/h2&gt;

&lt;p&gt;Crie um script chamado &lt;code&gt;fazBackup.sh&lt;/code&gt;, contendo algo assim:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="nb"&gt;echo &lt;/span&gt;Inicializando script de backup.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;O comentário &lt;code&gt;#!/bin/bash&lt;/code&gt; é uma diretiva que anuncia que interpretador deve ser usado. Neste caso, o interpretador é o &lt;code&gt;bash&lt;/code&gt;, mas poderia ser &lt;code&gt;python&lt;/code&gt; ou &lt;code&gt;node&lt;/code&gt;. Tal diretiva é chamada de &lt;code&gt;shebang&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Precisamos de um script &lt;em&gt;executável&lt;/em&gt;, o que significa a necessidade de permissão para execução. Para modificar tal política, usamos o comando &lt;code&gt;chmod&lt;/code&gt;. Este comando tem duas formas de adotar novas políticas: números e letras. Aqui será usado a forma de letras e todos os usuários serão capazes de executar o script. (Para saber mais sobre o &lt;code&gt;chmod&lt;/code&gt;, &lt;a href="https://www.howtogeek.com/437958/how-to-use-the-chmod-command-on-linux/"&gt;aqui&lt;/a&gt;) está a documentação em inglês.)&lt;/p&gt;

&lt;p&gt;No terminal, escreva:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;a+x makebackup.sh
&lt;span class="c"&gt;# a means all users&lt;/span&gt;
&lt;span class="c"&gt;# + means adding a permission (a minus (-) would be removing it).&lt;/span&gt;
&lt;span class="c"&gt;# x means permission to execute&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Passo 1: De onde veio, pra onde foi
&lt;/h2&gt;

&lt;p&gt;Nós usaremos o &lt;code&gt;rsync&lt;/code&gt; para copiar os items, porém você poderia usar outras ferramentas, como o commando &lt;code&gt;cp&lt;/code&gt;. Para aprender mais sobre o &lt;code&gt;rsync&lt;/code&gt;, &lt;a href="https://www.digitalocean.com/community/tutorials/how-to-use-rsync-to-sync-local-and-remote-directories"&gt;leia esse tutorial&lt;/a&gt; (em inglês).&lt;/p&gt;

&lt;p&gt;Dentro do &lt;code&gt;fazBackup.sh&lt;/code&gt;, escreva o seguinte:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="nb"&gt;echo &lt;/span&gt;Inicializando script de backup.

rsync &lt;span class="o"&gt;[&lt;/span&gt;Fontes] /caminho/para/[Destino]/
&lt;span class="c"&gt;# Fontes são todos os arquivos e pastas a serem guardados&lt;/span&gt;
&lt;span class="c"&gt;# Destino é a pasta onde o backup será guardado&lt;/span&gt;

&lt;span class="nb"&gt;echo &lt;/span&gt;Backup finalizado. Teminando script.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lembrete! A pasta de [Destino] não precisa existir previamente, pois &lt;code&gt;rsync&lt;/code&gt; cria a pasta no diretório. Tudo o que precisa fazer é colocar o nome desejado, seguindo por uma barra ('/').&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Tenho um trabalho pra você
&lt;/h2&gt;

&lt;p&gt;Antes de configurar o cronjob, você precisa definir a agenda. Quando que o backup deve ser feito? Use a ferramenta &lt;a href="https://crontab.guru/#50_9_*_*_FRI"&gt;Crontab Guru&lt;/a&gt; para decidir quando você quer o trabalho feito — diariamente, semanalmente, mensalment, etc.&lt;/p&gt;

&lt;p&gt;Depois, você configura o cronjob, que é bem fácil! Digite &lt;code&gt;crontab -e&lt;/code&gt; no terminal, e ele abrirá um crontab com umas informações bacanas — vale a pena dar uma olhada. Dentro desse arquivo, vá ao final, cole a data que você criou no &lt;a href="https://crontab.guru/#50_9_*_*_FRI"&gt;Crontab Guru&lt;/a&gt;, e escreva todo o caminho absoluto para o script executável. Algo assim:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Crontab file&lt;/span&gt;
00 10 &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; /caminho/para/fazBackup.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Passo 3: E fim
&lt;/h2&gt;

&lt;p&gt;E pronto! Teu script de backup está automatizado.&lt;/p&gt;

&lt;h3&gt;
  
  
  Uns avisos e considerações
&lt;/h3&gt;

&lt;p&gt;O serviço &lt;code&gt;cron&lt;/code&gt; leva um ou dois minutos para atualizar, então se você quiser testar imediatamente, mantenha o timing em mente: coloque a execução do script uns 3 minutos depois de salvar o crontab.&lt;/p&gt;

&lt;p&gt;Outra coisa a saber: você poderia agendar o comando &lt;code&gt;tar&lt;/code&gt;, em vez de criar um script personalizado. Ficaria algo como:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Crontab&lt;/span&gt;
&lt;span class="c"&gt;# at 10:30 am, everyday, do&lt;/span&gt;
30 10 &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;tar &lt;/span&gt;cvzf /caminho/para/arquivo_de_saida.tar.gz /caminho/para/diretorio_de_entrada/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Espero que este artigo tenha ajudado! O serviço &lt;code&gt;cron&lt;/code&gt; é bastante poderoso, assim como é o scripting em &lt;code&gt;bash&lt;/code&gt;. Você pode criar todos tipos de tarefas agendadas e tornar sua máquina linux num mordomo pessoal! Se tiver ideas do que mais pode ser feito com &lt;code&gt;cron&lt;/code&gt; ou sugestões de melhoria para este artigo, comente abaixo!&lt;/p&gt;

</description>
      <category>bash</category>
      <category>iniciante</category>
    </item>
    <item>
      <title>Create an automatic backup system on Ubuntu with bash, rsync and crontab</title>
      <dc:creator>Alan Patrick</dc:creator>
      <pubDate>Sun, 25 Dec 2022 23:14:35 +0000</pubDate>
      <link>https://dev.to/opatrickvico/create-an-automatic-backup-system-on-ubuntu-with-bash-rsync-and-crontab-3l78</link>
      <guid>https://dev.to/opatrickvico/create-an-automatic-backup-system-on-ubuntu-with-bash-rsync-and-crontab-3l78</guid>
      <description>&lt;p&gt;There is a lot of cool things you can do with scripts! One thing I always wanted to do is create a backup system that runs automatically at a certain point of the day. Here is how I made the script using &lt;code&gt;rsync&lt;/code&gt; and &lt;code&gt;crontab&lt;/code&gt; commands.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 0: It all starts with a BANG
&lt;/h2&gt;

&lt;p&gt;Create a script named &lt;code&gt;makebackup.sh&lt;/code&gt; like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="nb"&gt;echo &lt;/span&gt;Initializing backup script.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;#!/bin/bash&lt;/code&gt; comment is a directive that announces which interpreter to use. In this case, the interpreter is &lt;code&gt;bash&lt;/code&gt;, but could be others, like &lt;code&gt;python&lt;/code&gt; or &lt;code&gt;node&lt;/code&gt;. This directive is called a &lt;code&gt;shebang&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We need an &lt;em&gt;executable&lt;/em&gt; script, which means it needs permission to be executed. To change the permissions of a file, you need the &lt;code&gt;chmod&lt;/code&gt; command. This command has two ways of receiving new permission policies: numbers and letters. We will use the letter system, and let all users to be capable of executing the script. (There is a good guide for &lt;code&gt;chmod&lt;/code&gt; &lt;a href="https://www.howtogeek.com/437958/how-to-use-the-chmod-command-on-linux/" rel="noopener noreferrer"&gt;here&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;On the terminal, write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;a+x makebackup.sh
&lt;span class="c"&gt;# a means all users&lt;/span&gt;
&lt;span class="c"&gt;# + means adding a permission (a minus (-) would be removing it).&lt;/span&gt;
&lt;span class="c"&gt;# x means permission to execute&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 1: Where will it come from, where will it go
&lt;/h2&gt;

&lt;p&gt;We will be using &lt;code&gt;rsync&lt;/code&gt; for copying the items, but you could use other tools, like the &lt;code&gt;cp&lt;/code&gt; command. To learn more about &lt;code&gt;rsync&lt;/code&gt;, &lt;a href="https://www.digitalocean.com/community/tutorials/how-to-use-rsync-to-sync-local-and-remote-directories" rel="noopener noreferrer"&gt;click here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Within the &lt;code&gt;makebackup.sh&lt;/code&gt; script, write the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="nb"&gt;echo &lt;/span&gt;Initializing backup script

rsync &lt;span class="o"&gt;[&lt;/span&gt;Sources] /path/to/[Destination]/
&lt;span class="c"&gt;# Sources are all files and folders to back up&lt;/span&gt;
&lt;span class="c"&gt;# Destination is the folder to store the backups&lt;/span&gt;

&lt;span class="nb"&gt;echo &lt;/span&gt;Backup finised. Exiting script.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep in mind! The [Destination] folder doesn't need to already be there, because &lt;code&gt;rsync&lt;/code&gt; creates it for you, if inexistent. All you need is to name the desired output directory. Do not forget the forward slash at the end, though, to indicate that it is a folder.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: I got a job for you
&lt;/h2&gt;

&lt;p&gt;Before you set up the cronjob, you have to decide on the schedule. When should things be backed up? Use the &lt;a href="https://crontab.guru/#50_9_*_*_FRI" rel="noopener noreferrer"&gt;Crontab Guru&lt;/a&gt; tool for deciding when you want the job done — daily, weekly, monthly, etc.&lt;/p&gt;

&lt;p&gt;Then, you set up cronjob, which is really easy! Type &lt;code&gt;crontab -e&lt;/code&gt; on the terminal, and it will open a crontab with some nice information — do skim it, at least. Within the file, go to the bottom, paste the schedule you got from &lt;a href="https://crontab.guru/#50_9_*_*_FRI" rel="noopener noreferrer"&gt;Crontab Guru&lt;/a&gt;, and type out the full path to your executable script. Something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Crontab file&lt;/span&gt;
00 10 &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; /path/to/makebackup.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: The End
&lt;/h2&gt;

&lt;p&gt;And this is it! Your backup script is automated.&lt;/p&gt;

&lt;h3&gt;
  
  
  Some warnings and considerations
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;cron&lt;/code&gt; service takes 1 or 2 minutes to reload, so if you want to test immediately, keep the timing in mind: set the execution of the cronjob for at least 3 minutes from saving the crontab file.&lt;/p&gt;

&lt;p&gt;Another thing to keep in mind is this: you could schedule a &lt;code&gt;tar&lt;/code&gt; command, instead of creating a custom script. It would look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Crontab&lt;/span&gt;
&lt;span class="c"&gt;# at 10:30 am, everyday, do&lt;/span&gt;
30 10 &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;tar &lt;/span&gt;cvzf /path/to/archive_name.tar.gz /path/to/input_directory/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;I hope this was helpful! The &lt;code&gt;cron&lt;/code&gt; service is really powerful, and so is &lt;code&gt;bash&lt;/code&gt; scripting. You can create all kinds of scheduled tasks and make your ubuntu machine to be a personal butler! If you have any ideas of what else can be done with &lt;code&gt;cron&lt;/code&gt; or suggestions for improving this article, please comment below!&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Three concepts of the styled-components library</title>
      <dc:creator>Alan Patrick</dc:creator>
      <pubDate>Mon, 25 Jul 2022 18:49:03 +0000</pubDate>
      <link>https://dev.to/opatrickvico/three-concepts-of-the-styled-components-library-2n50</link>
      <guid>https://dev.to/opatrickvico/three-concepts-of-the-styled-components-library-2n50</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Lately, I've been playing with &lt;a href="https://styled-components.com/"&gt;styled-components&lt;/a&gt;. It is a CSS-in-JS library that uses &lt;a href="https://codeburst.io/javascript-what-are-tag-functions-97682f29521b"&gt;tagged template literals&lt;/a&gt;. I want to talk about three concepts that I got puzzled by: &lt;strong&gt;&lt;code&gt;Interpolation&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;GlobalStyle&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;ThemeProvider&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Interpolation?
&lt;/h2&gt;

&lt;p&gt;Interpolation is adapting a component based on the props passed to it; meaning, you can inject values through props. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MockElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="s2"&gt;`
  --size: &lt;/span&gt;&lt;span class="p"&gt;${(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;big&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;100px&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;50px&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;;
  width: var(--size);
  height: var(--size);
  background-color: yellowgreen;
`&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="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="c1"&gt;// This renders a 50x50 square, because there was no "big" prop&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MockElement&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="c1"&gt;// This renders a 100x100 square, because "big" was passed&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MockElement&lt;/span&gt; &lt;span class="nx"&gt;big&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;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So you can use props as truthy values. What about custom values? That works too!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MockElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="s2"&gt;`
  background-color: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;yellowgreen&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;;

  --size: &lt;/span&gt;&lt;span class="p"&gt;${(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;big&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;100px&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;50px&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;;
  width: var(--size);
  height: var(--size);
`&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="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="c1"&gt;// This renders a blue square&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MockElement&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="c1"&gt;// This renders... no color??&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MockElement&lt;/span&gt; &lt;span class="nx"&gt;color&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;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Styled props are truthy by default, but since no value was passed, nothing gets rendered. To use the default value with this technique, you either skip the prop entirely, or you pass a &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But &lt;strong&gt;BEWARE!&lt;/strong&gt; You must pass a function when interpolating a value, or the code breaks. Something like the following wouldn't work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MockElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="s2"&gt;`
  background-color: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;; /* It must be a function */
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Must the function be inline? No! You can simply pass any function as a callback:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;declaredFunction&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;factor&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;px`&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;scale&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;MockElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="s2"&gt;`
  --size: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;declaredFunction&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;;
  width: var(--size);
  height: var(--size);
  background-color: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;yellowgreen&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;;
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;render&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="c1"&gt;// This renders a 150x150, yellowgreen square&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MockElement&lt;/span&gt; &lt;span class="nx"&gt;big&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="o"&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="nx"&gt;factor&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="sr"&gt;/&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;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This marks the end of exploring &lt;code&gt;interpolation&lt;/code&gt;. On to the next!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is GlobalStyle?
&lt;/h2&gt;

&lt;p&gt;Self-explanatory as the name is, a GlobalStyle component is used to define general styling rules for the application. &lt;strong&gt;A close comparison would be using an &lt;code&gt;index.css&lt;/code&gt; file that gets imported and bundled before all other stylesheets&lt;/strong&gt;, thus being overwritten by css modules that follow it later.&lt;/p&gt;

&lt;p&gt;Using a global style is fairly simple! First, you must create the &lt;code&gt;GlobalStyle.js&lt;/code&gt; file, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createGlobalStyle&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;style-components&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;GlobalStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createGlobalStyle&lt;/span&gt;&lt;span class="s2"&gt;`
  /* Insert global styling here */
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;GlobalStyle&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, put the component...anywhere, really. At least, in the few tests I did, I put the component anywhere within the project and it worked just fine. However, for the sake of organization, I've put in my routing system (with react-router), like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;GlobalStyle&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./utils/GlobalStyle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&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;BrowserRouter&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;GlobalStyle&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;Routes&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/*The routes and elements go here*/&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;/Routes&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;/BrowserRouter&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;Cool! On to the final topic: &lt;code&gt;ThemeProvider&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is ThemeProvider?
&lt;/h2&gt;

&lt;p&gt;ThemeProvider is a source of universal props to all its children. You must put the component at the root of your project, if you want all components to have access to it.&lt;/p&gt;

&lt;p&gt;So, if you use &lt;code&gt;App.js&lt;/code&gt; as your root, you could do something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ThemeProvider&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;styled-components&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;themeObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;button&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;primary&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lightblue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;white&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;secondary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="cm"&gt;/* other keywords*/&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&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;ThemeProvider&lt;/span&gt; &lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;themeObject&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;CoolButton&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="sr"&gt;/ThemeProvider&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;That &lt;code&gt;themeObject&lt;/code&gt; becomes accessible to all objects that are children of &lt;code&gt;ThemeProvider&lt;/code&gt;. You use the &lt;code&gt;theme&lt;/code&gt; prop through &lt;code&gt;interpolation&lt;/code&gt;, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;CoolButton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;styled-components&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CoolButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="s2"&gt;`
  background-color: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;primary&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;background&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;;
  /* As seen above and below, you just need to access the string from the theme object */
  color: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;primary&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;;
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also combine all three components, by making &lt;code&gt;GlobalComponent&lt;/code&gt; a child of &lt;code&gt;ThemeProvider&lt;/code&gt; and interpolating values as needed. One useful example is setting the font family.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;theme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;heading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Cool Heading&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;subHeading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Cute Heading&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;GlobalStyle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createGlobalStyle&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;styled-components&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;coolFontPath&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./font-file1.woff&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;cuteFontPath&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./font-file2.woff&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;GlobalStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createGlobalStyle&lt;/span&gt;&lt;span class="s2"&gt;`
  @font-face {
    font-family: 'Cool Heading';
    src: url(&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;coolFontPath&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;;
  }

  @font-face {
    font-family: 'Cute Heading';
    src: url(&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;cuteFontPath&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;;
  }

  h1 {
    font-family: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;heading&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;;
  }

  span.subheading {
    font-family: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subHeading&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
  }
`&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;GlobalStyle&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;GlobalStyle&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./GlobalStyle.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;theme&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./theme.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ThemeProvider&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;styled-components&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="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;ThemeProvider&lt;/span&gt; &lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;theme&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;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;I&lt;/span&gt; &lt;span class="nx"&gt;belong&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;Cool&lt;/span&gt; &lt;span class="nx"&gt;Heading&lt;/span&gt; &lt;span class="nx"&gt;family&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&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;span&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;subheading&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nx"&gt;I&lt;/span&gt; &lt;span class="nx"&gt;belong&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;Cute&lt;/span&gt; &lt;span class="nx"&gt;Heading&lt;/span&gt; &lt;span class="nx"&gt;family&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&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;/ThemeProvider&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;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;So there you have it! This was the exploration of three important concepts of the styled-library: &lt;code&gt;Interpolation&lt;/code&gt;, &lt;code&gt;GlobalStyling&lt;/code&gt; and &lt;code&gt;ThemeProvider&lt;/code&gt;. Hope it was of use!&lt;/p&gt;

</description>
      <category>react</category>
      <category>styledcomponents</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Folder Structure of a React Project</title>
      <dc:creator>Alan Patrick</dc:creator>
      <pubDate>Fri, 22 Jul 2022 12:50:07 +0000</pubDate>
      <link>https://dev.to/opatrickvico/folder-structure-of-a-react-project-2k6c</link>
      <guid>https://dev.to/opatrickvico/folder-structure-of-a-react-project-2k6c</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;This is a guide for organizing your code when using React and &lt;a href="https://styled-components.com/docs"&gt;styled-components&lt;/a&gt;, which is a CSS-IN-JS library, meaning you write the styling in a javascript file. There are other options for CSS solutions and their trade-offs, but that is topic for a different time.&lt;/p&gt;

&lt;p&gt;Throughout the doing my projects, I felt the need of some structure for scaling my development. With a bit of luck and exploration, I stumbled upon the concepts of &lt;code&gt;Directory-per-Component&lt;/code&gt; and &lt;code&gt;Directory-per-view&lt;/code&gt;. There is a great resource talking about this structure at &lt;a href="https://survivejs.com/react/advanced-techniques/structuring-react-projects/"&gt;Survive.js&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Folder structure — How to organize the whole
&lt;/h2&gt;

&lt;p&gt;The basic folder structure should follow something like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;src/

&lt;ul&gt;
&lt;li&gt;components/&lt;/li&gt;
&lt;li&gt;pages/&lt;/li&gt;
&lt;li&gt;assets/&lt;/li&gt;
&lt;li&gt;images/&lt;/li&gt;
&lt;li&gt;fonts/&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The components folder is meant for any element that is reusable throughout the project. Headers, footers, styled buttons, etc. The pages folder is meant for... well, pages, like the ones links point to. The assets folder is in the source folder because adding them through javascript has some benefits, like bundling resources for fewer network requests (which speeds up the site). Check out the &lt;a href="https://create-react-app.dev/docs/using-the-public-folder/#adding-assets-outside-of-the-module-system"&gt;create-react-app documentation&lt;/a&gt; for a full explanation.&lt;/p&gt;

&lt;h2&gt;
  
  
  File structure — How to organize each piece
&lt;/h2&gt;

&lt;p&gt;The basic file structure has two versions — state-full or state-less. This is an oversimplification (and probably a bad one), so I accept suggestions for replacements.&lt;/p&gt;

&lt;h3&gt;
  
  
  Stateless Elements
&lt;/h3&gt;

&lt;p&gt;The state-less file structure is meant for elements not responsible for any logic within themselves, but still require styling. Examples would be simple containers, links, images and even buttons. These are components that would work in static pages.&lt;/p&gt;

&lt;p&gt;These elements are often reusable and should be put under the components folder. They would require two files: the &lt;code&gt;component.styled.js&lt;/code&gt; and &lt;code&gt;index.js&lt;/code&gt;. They would be under the &lt;code&gt;components&lt;/code&gt; folder. It would go something like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;src/

&lt;ul&gt;
&lt;li&gt;components/&lt;/li&gt;
&lt;li&gt;CoolButton/

&lt;ul&gt;
&lt;li&gt;CoolButton.styled.js&lt;/li&gt;
&lt;li&gt;index.js&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  WHY?
&lt;/h4&gt;

&lt;p&gt;Using the index structure allows you to omit the the element being imported. This eliminates the &lt;code&gt;./components/CoolButton/CoolButton.component&lt;/code&gt; import path. Instead you get &lt;code&gt;./components/CoolButton&lt;/code&gt; with implied index. (More on this later.) Also, using the &lt;code&gt;CoolButton.styled.js&lt;/code&gt; indicates (to you and others) that file is about styling.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What about using a separate css file instead? It does the same thing!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Styled-components eliminates the necessity to worry about class names. Less decisions equals more brain power! Check out &lt;a href="https://en.wikipedia.org/wiki/Decision_fatigue"&gt;decision-making fatigue&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What about losing the class selectors? How do you reference elements then?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In that case, you could just add the class names later, as a prop to the component. However, this will likely be unnecessary, due to useRef hooks and the Testing Library grabbing elements by their accessible features.&lt;/p&gt;

&lt;h4&gt;
  
  
  Small note about index exports
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/64187120/default-import-index-js-file"&gt;As explained&lt;/a&gt;, the &lt;code&gt;index.js&lt;/code&gt; is a default entry point of node.js — the thing used by webpack to bundle your project.&lt;/p&gt;

&lt;p&gt;An interesting tool for automating index creation is &lt;a href="https://github.com/gajus/create-index"&gt;create-index&lt;/a&gt;. I haven't tested yet, but I will give it a try.&lt;/p&gt;

&lt;h3&gt;
  
  
  Stateful Elements
&lt;/h3&gt;

&lt;p&gt;Stateful elements are likely to be pages (or views, or routes), where components are combined and logic is implemented.&lt;/p&gt;

&lt;p&gt;The structure would be something like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;src/

&lt;ul&gt;
&lt;li&gt;page/&lt;/li&gt;
&lt;li&gt;DataModal/

&lt;ul&gt;
&lt;li&gt;DataModal.styled.js&lt;/li&gt;
&lt;li&gt;DataModal.js&lt;/li&gt;
&lt;li&gt;index.js&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While statefull elements closely resemble stateless ones in their file structure, there is an addition to the mix — the &lt;code&gt;DataModal.js&lt;/code&gt; logic file. This is where you make use of the styled components created at &lt;code&gt;DataModal.styled.js&lt;/code&gt; and give them behaviors. If the styled file creates a doll, the logic files gives the doll strings and turns it into a puppet.&lt;/p&gt;

&lt;h2&gt;
  
  
  How would those files look like?
&lt;/h2&gt;

&lt;p&gt;With this structure, there is the basic pattern of &lt;code&gt;Component.styled.js - index.js - Component.js&lt;/code&gt;. Of course, it won't be limited to that (where do tests fit in?!), but it is a nice start.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Component.styled.js&lt;/code&gt;: Here is where the styling comes into place. You will create the stateless components by using the styled-components tag functions like this:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;styled-components&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ModalFrame&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="s2"&gt;`
  background-color: lightblue;
  font-family: Lato, sans-serif;
  /* --- more styling -- */
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// As you can see, it looks just like css, but in js! :D&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ModalFrame&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Component.js&lt;/code&gt;: Here you make use of stateless components to build stateful ones, like so:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ModalFrame&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./Component.styled.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;DataModal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ModalFrame&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/*Some logic inside*/&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;/ModalFrame&amp;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;export&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;DataModal&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;index.js&lt;/code&gt;: It is where the default exporting actually happens. All you need to do is:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;DataModal&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./Component&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// './Component.styled' would also work&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;All what would be left is to import the component! Since &lt;code&gt;index.js&lt;/code&gt; is the default entry point (as seen before), you can just import the directory directly (sorry, I had to):
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;SomeView&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;DataModal&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/Datamodal&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Look at that nice import!&lt;/span&gt;
&lt;span class="c1"&gt;// Rest of code&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;So, there you have it: a structured way of organizing your project, together with a tiny introduction to styled-components. It is what I will be using for a while now — though I have had my eyes on tailwind for a while. We'll see!&lt;/p&gt;

&lt;p&gt;This is my first time writing about software development, so I'm accepting every feedback you guys may have!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
