<?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: Khauri</title>
    <description>The latest articles on DEV Community by Khauri (@khauri).</description>
    <link>https://dev.to/khauri</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%2F250363%2F6fdd5ce1-b98a-4666-b911-3279efd03d91.jpg</url>
      <title>DEV Community: Khauri</title>
      <link>https://dev.to/khauri</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/khauri"/>
    <language>en</language>
    <item>
      <title>Marko: A return to the good ol' days of web development</title>
      <dc:creator>Khauri</dc:creator>
      <pubDate>Sat, 14 May 2022 14:57:36 +0000</pubDate>
      <link>https://dev.to/khauri/marko-a-return-to-the-good-ol-days-of-web-development-o10</link>
      <guid>https://dev.to/khauri/marko-a-return-to-the-good-ol-days-of-web-development-o10</guid>
      <description>&lt;p&gt;Let’s get this out of the way first — I understand the fatigue that comes with hearing about the newest framework of the week, but &lt;a href="https://markojs.com/"&gt;Marko&lt;/a&gt; isn’t a new framework. Rather it’s an older, and somewhat lesser known library originally created at eBay that focused on the whole server rendering concept probably long before that was a twinkle in the eyes of some of your current faves. (As a JS dev I'm obligated to say that it's "Blazingly Fast" as well, sorry).&lt;/p&gt;

&lt;p&gt;Recently Marko has announced some exciting new changes that can be seen as similar to the shift from React’s class components to hook-based function components. It’s called the &lt;a href="https://dev.to/ryansolid/introducing-the-marko-tags-api-preview-37o4"&gt;Tags api&lt;/a&gt; and to me it feels like a nostalgic return to form for web development.&lt;/p&gt;

&lt;p&gt;Although this article mainly compares Marko to React, if you’re an average Vue or Svelte enjoyer then you’ll also feel at home with some of these comparisons because Marko:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Enhances HTML with JS instead of enhancing JS with HTML&lt;/li&gt;
&lt;li&gt;Has reactive primitives that “just work”&lt;/li&gt;
&lt;li&gt;Enjoys all the benefits of being a compiled language&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s unpack some of this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enhanced HTML vs JSX
&lt;/h2&gt;

&lt;p&gt;Try to think back to when you were first learning web development. If it was anything like my first time then it involved writing some plain old HTML and JS in notepad.exe and watching elements on the page go brrrr. Or maybe you first got a taste for it making themes for your tumblr or myspace blog. Or maybe you were a PHP dev, in which case, my condolences and also are you okay? &lt;/p&gt;

&lt;p&gt;And in between jQuery and Angular maybe you found out about React + JSX, which looked like the familiar html syntax, but not quite because there were enough rules and variation that gave it quite the learning curve initially. And although you don’t &lt;em&gt;need&lt;/em&gt; to use JSX to use React, let’s face it, if you’re not using JSX you’re going to get bullied. So combine that with learning how hooks work, add in a little redux/mobx, multiply by the amount of bundler and transpilation shenanigans, and then carry the dozen or so css frameworks and...well it really feels like web development took a complicated turn.&lt;/p&gt;

&lt;p&gt;Here's where I want to say "enter Marko, stage left", but Marko was already just kinda standing on the stage dressed as a tree.&lt;/p&gt;

&lt;p&gt;The first thing to like here is that with Marko any valid HTML is also already valid Marko, so if you already know how to write HTML then you’re more than halfway there. As a smaller benefit, attributes are also all interpreted as JS values so there's no need to suffocate them with curly braces either. This is already a much easier transition for the aspiring web developer than hopping right into JSX.&lt;br&gt;
It's easy to take for granted how natural writing JSX becomes after staring at it for 5+ years, but for beginners the pitfalls in the differences between JSX and HTML are deep and often covered with leaves and branches.&lt;/p&gt;

&lt;p&gt;Let’s look at an example of the same basic, non-interactive “Hello, World” in React:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&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;HelloWorld&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello, World&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&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;And also in your standard &lt;code&gt;.marko&lt;/code&gt; file.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KGdy0WwE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1syfvu4avqdsnujku5af.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KGdy0WwE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1syfvu4avqdsnujku5af.png" alt="Code snippet showing a basic hello world in Marko" width="800" height="58"&gt;&lt;/a&gt;&lt;br&gt;
&lt;small&gt;&lt;a href="https://markojs.com/playground/#NobwRAdghgtgpmAXGAlhAJnAHgOhlAJwGsB7MAGjAAcoAXACyTAHoBjEmKkiOCWgZ2ZpMufMTKV2fXrSYAedCgBuAPgAScADaaS5AAQB1EgU3o5zRaoA6EMAF8AukA"&gt;Playground link&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;A lot less boilerplate, that’s for sure, but definitely nothing dramatic. Let's dig deeper.&lt;/p&gt;
&lt;h2&gt;
  
  
  Reactive Primitives vs useState
&lt;/h2&gt;

&lt;p&gt;Let’s modify these examples to have an input field that will update who we’re saying "Hello" to in real time.&lt;/p&gt;

&lt;p&gt;In React you’d use the &lt;code&gt;useState&lt;/code&gt; hook, which returns the current value along with an updater function as an array that you normally destructure. Then you'd call that updater function with your new value whenever you want to update it. Simple right?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;useState&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="s2"&gt;react&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;HelloWorld&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;world&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="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello, &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;onInput&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&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;In Marko, you use the &lt;code&gt;&amp;lt;let&amp;gt;&lt;/code&gt; tag, which behaves similarly to the &lt;code&gt;let&lt;/code&gt; variable declaration in plain js, and to update it you kinda just…update it?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7xevw9f8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kslijnfv6pb3ll7oueuu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7xevw9f8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kslijnfv6pb3ll7oueuu.png" alt="Code snippet showing value updating in Marko" width="800" height="144"&gt;&lt;/a&gt;&lt;br&gt;
&lt;small&gt;&lt;a href="https://markojs.com/playground/#NobwRAdghgtgpmAXGAlhAJnAHgOhlAJwGsB7MAGjAAcoAXACyTAHoBjEmKkiOCWgZ2ZpMufMTKV2fXrSYAeADZxazAG5QFAVzgACALw6AOmADqJAgvTGdzAHyGIc9ClW2AEnAUKS5HQBIQdS04AF85ZmdXBzk0Kk1aHSDtPSTdbgBJCDjaAAo4AEpAjW19HTgcWkIAc2UcVJC7BzAQgF0gA"&gt;Playground link&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;** Please direct all comments about the syntax to the Marko Discord channel.&lt;/p&gt;

&lt;p&gt;Because we used the &lt;code&gt;&amp;lt;let&amp;gt;&lt;/code&gt; tag here, Marko knows that whenever &lt;code&gt;value&lt;/code&gt; is changed then anything that uses it needs to be re-rendered. No proxies, update functions, or reducers required.&lt;/p&gt;

&lt;p&gt;Using the bind syntax, this example can be made even more concise.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4aACl2iu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o3avn3lwd0xo7tn8mzx5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4aACl2iu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o3avn3lwd0xo7tn8mzx5.png" alt="Code snippet showing marko reactive primitives using the binding syntax" width="800" height="131"&gt;&lt;/a&gt;&lt;br&gt;
&lt;small&gt;&lt;a href="https://markojs.com/playground/#NobwRAdghgtgpmAXGAlhAJnAHgOhlAJwGsB7MAGjAAcoAXACyTAHoBjEmKkiOCWgZ2ZpMufMTKV2fXrSYAeADZxazAG5QFAVzgACALw6A5AHUSBBekM7mAPgA6EOVRsAJOAoUlyOgCQh1WnAAvnLMzg5yaFSatDoB2oh68bq2YEHk4NDwTOyeBDgAVvwU1HSMyGwcXDx8grlmhcWS3LQyTABmmhCstCjcOgRQGACSfAAcABQAlDogDjoDypoEEDoAsmU4BCRd6BMbDFtD6BzTOgBUOgBMAKw3UwDcDkEODthcBLGY7VCaCrGdbq9foAc2UACVjhwAMIkPJnOarRa0ZarAAGBBBACMJn5BiNxtN0r4QPj0KNaJMpsS8ccKVSglM0c8HGkALpAA"&gt;Playground Link&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;And all we really did was enhance some plain old html with a few bits of extra syntax and suddenly we have have state in our component. And that's just the tip of the iceberg because you can create your own tags to grab state from anywhere, such as a global store, indexeddb, or localStorage.&lt;/p&gt;
&lt;h3&gt;
  
  
  Loops without the L
&lt;/h3&gt;

&lt;p&gt;As we know, everyone’s favorite part of React is rendering multiple children in a loop. I think it’s the ugliness and reliance on beginner-unfriendly looking JS that really draws the crowd you know? I mean just look at this beauty?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&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;Countries&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;countries&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sudan&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Chile&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Japan&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="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;countries&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;country&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;country&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;country&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&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;Let’s compare that to Marko though…&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C7Gnxr3f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uvm9q3phk0sblu38vzd9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C7Gnxr3f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uvm9q3phk0sblu38vzd9.png" alt="Code snippet showing nested state variables in Marko" width="800" height="164"&gt;&lt;/a&gt;&lt;br&gt;
&lt;small&gt;&lt;a href="https://markojs.com/playground/#NobwRAdghgtgpmAXGAlhAJnAHgOhlAJwGsB7MAGjAAcoAXACyTAHoBjEmKkiOCWgZ2ZpMufMTKV2fXrSYAeKf1psSAVz4EUcfgAIAvDuAAdMAGVV6KBBPkdJgML0UAGzg27YAFJQa1sAF0dZgA+Iwg5ADMSAgAfdnVaAgBPGJ0SCL14jS1+UIgdHTkqYIASECzEpIBfOWZisNqogmCwKv8gA"&gt;Playground Link&lt;/a&gt;&lt;/small&gt; &lt;/p&gt;

&lt;p&gt;I mean, this comparison isn’t too bad right? But let's say I want to make it so that when you click on a country, that country’s color changes to some random color? Well in React, I would probably want to create a new component and manage the state separately:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="nx"&gt;react&lt;/span&gt;&lt;span class="err"&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;getRandomColor&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;colors&lt;/span&gt;&lt;span class="err"&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;Country&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="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&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;setColor&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&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;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&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="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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="nx"&gt;setColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;getRandomColor&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Countries&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;countries&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sudan&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Chile&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Japan&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="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;countries&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;country&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;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Country&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;country&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&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;Here's where Marko starts to gain the advantage over Svelte and Vue. In Marko you can create a reactive value at any point in the tree, including inside loops, and it’ll still work just how you’d expect.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Knezu5yh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5hymltl9t4d7au43o4p5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Knezu5yh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5hymltl9t4d7au43o4p5.png" alt="Code snippet showing an interactive loop in Marko" width="800" height="220"&gt;&lt;/a&gt;&lt;br&gt;
&lt;small&gt;&lt;a href="https://markojs.com/playground/#NobwRAdghgtgpmAXGAlhAJnAHgOhlAJwGsB7MAGjAAcoAXACyTAHoBjEmKkiOCWgZ2ZpMufMTKV2fXrSYpOJArQAEAczi0ASlAwcAwiQA2i5QDMCHZQB0wONkcU2A3FYiuAPFP617AVz4EKHD8ygC8ysA2AMq+6Do25NZgevQohnAJSQBSUDRuYAC6yswAfB6migA+7P60BACelcokpqE1AUH8ZRDKyu7pPuzGBKEQvoaGxd297lTK3vXpoSBDigC+zRB6hiisRAAUAJQrDgRhahraujAGw0drJQAkJ7UNa+7MVN0fFQQlYGtyOBoPAmKsCDgAFb8CjUOiMZD2BQ8PiCcFQmGSbi0GRMUz+Vi0FDcZQEHToACSfAAHEdlCBXL0CBpfAQegBZeE4Cz+dD7TkMbnkjh0gBUygATABWKWHFwQNauVzYLhKZSYUxQcYqfEQQnEnrqLTCm6nOkMnqklls5QAAwIqgARvtnmSMFTaLTDoDlK7yR6vT6-e6afdDrbXIqIACCkA"&gt;Playground Link&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;I didn’t extract it out to a new component or do anything particularly complicated in order to add a bit of state. This is what Marko calls &lt;a href="https://dev.to/ryansolid/marko-compiling-fine-grained-reactivity-4lk4"&gt;Fine Grained Reactivity&lt;/a&gt;. Of course you can create components in Marko as well, but Marko doesn’t force you to do so at the first sign of slightly complex behavior, or readability issues, or even for technical limitations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Crying about components
&lt;/h2&gt;

&lt;p&gt;Components are really a developer tool for organizing the developer's mind, and not something that your framework should force upon you when you don't really need it. And yet components in traditional frameworks are themselves seen as entirely stateful or stateless and you have to now learn terms like "Dumb", "Smart", and "Pure" and think hard about how to best optimize the type of component you use for the task at hand. Sometimes you even have to manually memoize entire components to get them to not render multiple times.&lt;/p&gt;

&lt;p&gt;Marko's Tags api is a paradigm shift that takes away the burden of having to worry about most of the complexities of the framework itself and most other frameworks frankly seem too far along to copy it. It does so by allowing you to put state not on the component level, but wherever you want or need it to be.&lt;/p&gt;

&lt;p&gt;And I know a lot of people will probably see the ability to add state anywhere in your tag as an easy way to write messy code, but I personally see it as a great method of prototyping complex functionality without having to worry about splitting tiny little parts of your project into separate components first. These tiny parts can always be slapped into a new component almost as easily as copy-pasting it into a new file, and at the end of the day whether you use components or inline it all into one big mega component, the html output should look more-or-less the same because the components are "compiled away" into only the truly reactive sections of the page. And you as a developer, in theory, don't have to worry about any of that. And with Marko's built-in server side rendering focus you won't even have to do any special setup to provide an optimized experience to the end-user.&lt;/p&gt;

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

&lt;p&gt;This of course isn’t a full tutorial on Marko or the Tags api and I’ve really only lightly grazed the surface of what’s possible here. There are a few other tags that are comparable to React's hooks such as the &lt;code&gt;&amp;lt;effect&amp;gt;&lt;/code&gt; tag for running effects when variables change as well as the &lt;code&gt;&amp;lt;set&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;get&amp;gt;&lt;/code&gt; tags for context passing.&lt;/p&gt;

&lt;p&gt;The Tags api is still in the development phase and won't be fully released until Marko 6, but my team and I have been using the &lt;a href="https://github.com/marko-js/tags-api-preview"&gt;Tags api preview&lt;/a&gt; in production for a few months and have been reaping quite a few benefits already. But the possibilities here are like this pandemic: endless. For example imagine a tumblr/myspace/wordpress like website where writing extensions or widgets is as easy and simple as writing plain html and then "enhancing" it with a bit of functionality. It could get a whole new generation of youth into web development.&lt;/p&gt;

&lt;p&gt;Between the Tags api's easy html-like syntax, fine grained reactivity, and built-in SSR, Marko may shape up to be a key player in the framework wars in the near future, so my suggestion? Invest in the stonk.&lt;/p&gt;

</description>
      <category>marko</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>html</category>
    </item>
    <item>
      <title>How To Code On Your Smartphone (With A Terminal)</title>
      <dc:creator>Khauri</dc:creator>
      <pubDate>Sun, 03 May 2020 03:25:18 +0000</pubDate>
      <link>https://dev.to/khauri/how-to-code-on-your-smartphone-with-a-terminal-d21</link>
      <guid>https://dev.to/khauri/how-to-code-on-your-smartphone-with-a-terminal-d21</guid>
      <description>&lt;h3&gt;
  
  
  Overview
&lt;/h3&gt;

&lt;p&gt;In this article I'm going to show you how to use &lt;a href="https://termux.com/"&gt;Termux&lt;/a&gt; to install nodejs, set up a react app with create-react-app, and edit the files from a separate coding app all from your android smartphone.&lt;/p&gt;

&lt;p&gt;This tutorial assumes some very basic knowledge of the command line and unix.&lt;/p&gt;

&lt;h3&gt;
  
  
  Motivation
&lt;/h3&gt;

&lt;p&gt;A smartphone obviously isn't most people's first choice when it comes to coding, but for a lot of people it's simply their only choice. I wanted to see for myself how difficult it would be to create a full-stack, production ready, version controlled application completely from my Android phone, but after doing a little first page of Google research I learned that most mobile coding apps were lacking most of the features I was used to...namely integration with some kind of terminal. And as we all know, it is every developer's right of passage to struggle with the command line. Fortunately for us, with a little bit of work, we can make everyone's lives slightly harder.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Do It
&lt;/h2&gt;

&lt;p&gt;All we need is a terminal app and a decent code editor app.&lt;/p&gt;

&lt;p&gt;The terminal app that I'll be using is &lt;a href="https://play.google.com/store/apps/details?id=com.termux&amp;amp;hl=en_US"&gt;Termux&lt;/a&gt;. It's free and does not require your phone to be rooted.&lt;/p&gt;

&lt;p&gt;For the code editor I will be using the free version of &lt;a href="https://play.google.com/store/apps/details?id=com.foxdebug.acodefree&amp;amp;hl=en_US"&gt;Acode&lt;/a&gt;. Feel free to use whatever editor you like as long as it supports FTP (leave your suggestions in the comments). I'm using Acode because it was on the first page of my Google search. &lt;/p&gt;

&lt;p&gt;Note: &lt;em&gt;Acode is &lt;a href="https://github.com/deadlyjack/code-editor"&gt;fully open source&lt;/a&gt; which means you can vent any and all frustrations directly at the developer(s) in the form of github issues or show them some support, it's up to you really.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The first thing to do is to open Termux and install &lt;code&gt;nodejs&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pkg &lt;span class="nb"&gt;install &lt;/span&gt;nodejs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need to make a folder to store all of our projects. I'll just do this in my home directory so that it's easy to find later.&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;cd&lt;/span&gt; &lt;span class="nv"&gt;$HOME&lt;/span&gt;
&lt;span class="nb"&gt;mkdir &lt;/span&gt;projects
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now I'll go inside the projects folder and create a react app using &lt;a href="https://reactjs.org/docs/create-a-new-react-app.html"&gt;create-react-app&lt;/a&gt;, almost as if I was doing this on an actual computer.&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;cd &lt;/span&gt;projects
npx create-react-app my-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will take a bit of time but ultimately will automatically create a folder named &lt;code&gt;my-app&lt;/code&gt; in your projects folder. You can start the development server by changing directory to the my-app folder and then running the start script:&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;cd &lt;/span&gt;my-app
npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should automatically open your browser to &lt;code&gt;localhost:3000&lt;/code&gt; where you'll see the react starter template. Exciting stuff so far, but how about editing stuff?&lt;/p&gt;

&lt;p&gt;In order to edit your project files in Acode (or your FTP editor of choice) we will have to serve them over an ftp server. I promise this isn't as hard as it sounds.&lt;/p&gt;

&lt;p&gt;But wait, why? Well Android apps, for security reasons, have all of their files isolated from each other, meaning files you create in Acode can't be &lt;em&gt;directly&lt;/em&gt; opened with Termux and vice versa...with one exception -- they both have access to a virtual shared storage folder. The bad news is that you cannot create symlinks in this shared folder, which means that most &lt;code&gt;npm install&lt;/code&gt; commands will fail if you try them. Trust me, it's a headache.&lt;/p&gt;

&lt;p&gt;The good news is that Acode has a feature that allows you to access and modify files from an FTP server and in Termux it's easy to set one up.&lt;/p&gt;

&lt;p&gt;First open a new terminal session by swiping from the right and then pressing "new session" at the bottom. Then run this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tcpsvd &lt;span class="nt"&gt;-vE&lt;/span&gt; 0.0.0.0 1024 ftpd &lt;span class="nt"&gt;-w&lt;/span&gt; &lt;span class="nv"&gt;$HOME&lt;/span&gt;/projects
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;******&lt;/p&gt;

&lt;h3&gt;
  
  
  EDIT
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;tcpsvd&lt;/code&gt; apparently no longer comes pre-installed on Termux so you may get an error when you try this. &lt;code&gt;tcpsvd&lt;/code&gt; and many other great tools are available through the &lt;code&gt;busybox&lt;/code&gt; binary. You can install busybox and then create a link to specifically the &lt;code&gt;tcpsvd&lt;/code&gt; command with the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pkg install busybox
ln -s busybox $PREFIX/bin/tcpsvd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;******&lt;br&gt;
This opens up a server on port 1024 and serves up everything inside the projects folder. If port 1024 is already in use, feel free to use any other number as long as it's larger than 1024. &lt;/p&gt;

&lt;p&gt;Now open Acode and select "FTP" from the three vertical dots menu in the top-right corner, and then "Add FTP Account." For the hostname field put &lt;code&gt;127.0.0.1&lt;/code&gt; (this is also known as localhost). Now all the way at the bottom edit the port to &lt;code&gt;1024&lt;/code&gt; (it might sometimes already be filled in as &lt;code&gt;21&lt;/code&gt;). &lt;/p&gt;

&lt;p&gt;Fill in any optional fields you want, click OK, and then click the newly created entry to boot 'er up. Now click the hamburger menu to see a folder with all your files. From here you can go into the src folder, edit &lt;code&gt;App.js&lt;/code&gt;, click the save button, and then go back to your browser to see the changes applied immediately.&lt;/p&gt;

&lt;p&gt;And that's it. Now you can even do things such as experiment with making an express backend, running redis, postgres, and using up all your phone's storage.&lt;/p&gt;

&lt;p&gt;And remember to kill your server when you're done developing or you'll likely see high battery usage.&lt;/p&gt;

</description>
      <category>android</category>
      <category>react</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
