<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ryan Kuruppu</title>
    <description>The latest articles on Forem by Ryan Kuruppu (@aisirachcha21).</description>
    <link>https://forem.com/aisirachcha21</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%2F393319%2F3ca20e57-0384-4b7a-b136-c9a40b908ee5.jpeg</url>
      <title>Forem: Ryan Kuruppu</title>
      <link>https://forem.com/aisirachcha21</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/aisirachcha21"/>
    <language>en</language>
    <item>
      <title>Arc you glad you met me ?</title>
      <dc:creator>Ryan Kuruppu</dc:creator>
      <pubDate>Sat, 09 Dec 2023 10:53:47 +0000</pubDate>
      <link>https://forem.com/aisirachcha21/arcd-you-glad-you-met-me--5fid</link>
      <guid>https://forem.com/aisirachcha21/arcd-you-glad-you-met-me--5fid</guid>
      <description>&lt;p&gt;This isn't a tech article, this isn't a rant about the next JavaScript framework, this isn't even about the fact that I'm finally on break and I was so bored I decided to write about something I totally love.&lt;/p&gt;

&lt;p&gt;This is about the new kid on the block.&lt;/p&gt;

&lt;p&gt;The block which has been dominated by Google for the last millennia (yes, I know what a millennia means but exaggeration makes for content).&lt;/p&gt;

&lt;p&gt;I'm talking about &lt;a href="https://arc.net/" rel="noopener noreferrer"&gt;Arc by TheBrowserCompany.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The latest little big boy that's taking the browser market by storm.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd419iwlas5m47in0t8bz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd419iwlas5m47in0t8bz.png" alt="Arc Browser" width="800" height="517"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now now, don't be put off by the colors.&lt;/p&gt;

&lt;p&gt;The Arc team is way more talented than me at writing stuff like this but here I am raving on about it anyway (btw if being an Arc supporter is a cult, I guess I'm &lt;strong&gt;an "arc-anist"&lt;/strong&gt; hehe get it ?... ANYWAY&lt;/p&gt;

&lt;p&gt;I'm just gonna list some of the things I love so hope you're enticed enough to use Arc yourself 🙌🏼&lt;/p&gt;

&lt;h3&gt;
  
  
  A few things to mention
&lt;/h3&gt;

&lt;p&gt;So right now, The Browser Company have only released the Arc browser for MacOS as of right now.&lt;/p&gt;

&lt;p&gt;The Windows Beta is currently live an in testing. You can sign up for that &lt;a href="https://browserco.typeform.com/to/l9lYbJtU?typeform-source=arc.net#source=arcnet" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The mobile app is currently being reworked but they have a mobile companion which is available on the App Store but I would personally wait for the new and improved one to come out.&lt;/p&gt;

&lt;p&gt;But, if you are on Mac and you wanna give it a try, here you go !&lt;br&gt;
&lt;a href="https://arc.net/gift/5808d95d" rel="noopener noreferrer"&gt;https://arc.net/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Theming 🎨
&lt;/h2&gt;

&lt;p&gt;One of Arc's lovely features is the ability to theme your browser to your liking. From the color of your windows to the applications that you use on the browser itself (yes, you can change your application's colors, we'll get to that in a bit)&lt;/p&gt;

&lt;p&gt;Yes I know that other browser's have it too. But Arc's theming blends really well with the rest of the UI in a way that's really pleasing to the eye.&lt;/p&gt;

&lt;p&gt;Arc provides this with a nifty little color swatch you can drag around till you find the color you want to daily drive.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdesivsxl42juah8gwsuh.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdesivsxl42juah8gwsuh.gif" alt="Arc Theming Color Swatch" width="1024" height="1024"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So go ahead my fellow procrastinator, put aside your work and spend 3 hours finding the right color for you Arc window! Cause I know I couldn't stop playing with that damn color swatch.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Workspaces 🗂️
&lt;/h2&gt;

&lt;p&gt;Now what point is there in theming your windows if all of them are just gonna be the same color?&lt;/p&gt;

&lt;p&gt;Introducing Arc's workspaces!&lt;/p&gt;

&lt;p&gt;If you've used multiple profiles on Chrome or Edge, every time you open one of them you end up having a bunch of windows which you have to move through and find just to get the window with the right profile.&lt;/p&gt;

&lt;p&gt;Now the biggest issue I've always had is that I've needed to consistently alt tab between apps or have to look really close to figure out what window I have open. Yes themes did help but when you liked a certain color across all your windows it became more of a hassle to set them up in a way you could figure out what was what.&lt;/p&gt;

&lt;p&gt;Arc's workspaces are similar to profiles but the difference being that they are actually independent from the profiles you create.&lt;/p&gt;

&lt;p&gt;So you could have&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1 space per profile&lt;/li&gt;
&lt;li&gt;Multiple spaces using the same profile&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvrl1y9v3wq4m1eouhgfa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvrl1y9v3wq4m1eouhgfa.png" alt="Arc workspaces" width="800" height="208"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So how do you tell the difference ?&lt;/p&gt;

&lt;p&gt;Well it's a combination of naming and theming.&lt;/p&gt;

&lt;p&gt;For example, this is my Personal workspace.&lt;/p&gt;

&lt;p&gt;It's purple, has the name Personal with a nice lil logo.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwp5qhfx7g5d6vpwiqzha.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwp5qhfx7g5d6vpwiqzha.png" alt="Personal workspace" width="800" height="1964"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And this is my "work" workspace.&lt;/p&gt;

&lt;p&gt;It's gray, it's named Development and also has a logo that I can use to differentiate it&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fitxzfm68oxwjw59rwnge.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fitxzfm68oxwjw59rwnge.png" alt="Work workspace" width="628" height="1272"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;They each have their own histories, cookies, saved logins etc.&lt;/p&gt;

&lt;p&gt;Pretty neat 🥸 and just before you ask me "what makes that such a big deal ? I still have to find the workspaces 😩"&lt;/p&gt;

&lt;p&gt;Yes but no.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F07m5rnaoumqhv0t5p9cp.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F07m5rnaoumqhv0t5p9cp.gif" alt="Moving between workspaces" width="760" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can just slide between them 🤩&lt;/p&gt;

&lt;p&gt;But let's say you don't like that.&lt;/p&gt;

&lt;p&gt;You can use the icons at the bottom of the side bar to switch too !&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4yjtmk5ug5m7d60bbk9e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4yjtmk5ug5m7d60bbk9e.png" alt="Bottom Navigation" width="538" height="234"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can even use &lt;code&gt;control + 1&lt;/code&gt; or &lt;code&gt;control + 2&lt;/code&gt; (on Mac) to switch if you like shortcuts (the number is the order of your workspace)&lt;/p&gt;

&lt;p&gt;Now, in case even THAT wasn't "for you"&lt;/p&gt;

&lt;p&gt;Arc offers another way to switch workspaces, which also happens to lead me to the next feature I think is just an absolute win!&lt;/p&gt;

&lt;h2&gt;
  
  
  3 The command/action bar
&lt;/h2&gt;

&lt;p&gt;TLDR;&lt;br&gt;
Think spotlight on Mac, but for the browser 🤩&lt;/p&gt;

&lt;p&gt;Spotlight on Mac is a magical feature which lets you run actions, search for files, apps and even sites.&lt;/p&gt;

&lt;p&gt;The amazing people at TheBrowserCompany managed to take this little piece of heaven and put it into Arc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdfsglsymxzs7i9drgqkc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdfsglsymxzs7i9drgqkc.png" alt="Arc Spotlight" width="800" height="624"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I love calling this the "Arc Spotlight Search" just because it sounds right!&lt;/p&gt;

&lt;p&gt;Wanna focus on a specific workspace ? Just type &lt;code&gt;Focus on &amp;lt;name-of-your-workspace&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjlbdh4m3akfb6493j0p2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjlbdh4m3akfb6493j0p2.png" alt="Switching workspaces with the Arc Spotlight" width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But now now, don't think the Spotlight search is just for switching workspaces.&lt;/p&gt;

&lt;p&gt;You can still do your normal google searches&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftytxl9cifx8cg8mnk4pz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftytxl9cifx8cg8mnk4pz.png" alt="Google Search" width="800" height="140"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But you can also run &lt;strong&gt;"actions"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What do you mean actions???&lt;/p&gt;

&lt;p&gt;I mean ACTIONS&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fddnz5qlsrcn47cjptbbe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fddnz5qlsrcn47cjptbbe.png" alt="Actions" width="800" height="352"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Simply press &lt;code&gt;Tab&lt;/code&gt; when the spotlight search is open. &lt;br&gt;
This opens up a list of actions that your browser can do like,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Refreshing the page&lt;/li&gt;
&lt;li&gt;Creating a new space&lt;/li&gt;
&lt;li&gt;Archive a tab&lt;/li&gt;
&lt;li&gt;Open notes (yes, notes)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy5391axlscodc8trymzf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy5391axlscodc8trymzf.png" alt="Some actions" width="800" height="346"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And on top of all that ? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhk3wzzxn5raud0xdtd4o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhk3wzzxn5raud0xdtd4o.png" alt="ChatGPT in Search Bar" width="800" height="76"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes. ChatGPT in your search bar 🙌🏼&lt;/p&gt;

&lt;p&gt;Okay I'm getting excited just talking about all this.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Boosts
&lt;/h2&gt;

&lt;p&gt;Okay okay, now out of the number of features I could be talking about, this one is one of my personal favorites but it might not be for everyone.&lt;/p&gt;

&lt;p&gt;So remember how I said at the start that you could even theme your applications? Take a look carefully at the very first image in this blog.&lt;/p&gt;

&lt;p&gt;That's not how Spotify looks isn't it?&lt;/p&gt;

&lt;p&gt;This is enabled by a lovely little feature called boosts in Arc.&lt;/p&gt;

&lt;p&gt;It's a feature which allows you to "permanently" change the theming, look and feel of the sites you visit more often.&lt;/p&gt;

&lt;p&gt;This is all done with the Boost Side Panel&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftj6ox48ai5zf7swtgyfa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftj6ox48ai5zf7swtgyfa.png" alt="Boost Side Panel" width="386" height="1298"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just playing with the swatch, allows me to change a site like YouTube from this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fav9w41xv7dk2rzhb72ty.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fav9w41xv7dk2rzhb72ty.png" alt="Default YouTube dark mode" width="800" height="517"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F52t7v4qttehihkv8iev5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F52t7v4qttehihkv8iev5.png" alt="Boosted YouTube" width="800" height="517"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pretty cool isn't it ?&lt;/p&gt;

&lt;p&gt;Okay now there are a lot more cool features like &lt;/p&gt;

&lt;h3&gt;
  
  
  1.The in-built notes app
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftx7t10gofox47nw25tll.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftx7t10gofox47nw25tll.png" alt="Built-in notes app" width="800" height="517"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2.Split Views
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdreo60tgj7fy23rriaqq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdreo60tgj7fy23rriaqq.png" alt="Split Views" width="800" height="517"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3.Easels and Mood-Boards
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz3iltgghj7urrey7cbi8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz3iltgghj7urrey7cbi8.png" alt="Easels" width="800" height="517"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But I'm going to leave that to your curiosity to try.&lt;/p&gt;

&lt;p&gt;Here's a few I haven't even touched on yet:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;(Arc Max)[&lt;a href="https://arc.net/max" rel="noopener noreferrer"&gt;https://arc.net/max&lt;/a&gt;]&lt;/li&gt;
&lt;li&gt;The types of Tabs in the Side Panel&lt;/li&gt;
&lt;li&gt;(Smart Screenshots)[&lt;a href="https://resources.arc.net/en/articles/8411618-how-do-i-take-a-screenshot-in-arc" rel="noopener noreferrer"&gt;https://resources.arc.net/en/articles/8411618-how-do-i-take-a-screenshot-in-arc&lt;/a&gt;]&lt;/li&gt;
&lt;li&gt;(Air Traffic Control)[&lt;a href="https://resources.arc.net/en/articles/7670020-air-traffic-control-route-links-to-the-right-space-automatically" rel="noopener noreferrer"&gt;https://resources.arc.net/en/articles/7670020-air-traffic-control-route-links-to-the-right-space-automatically&lt;/a&gt;]&lt;/li&gt;
&lt;li&gt;Site Search (yes its in other browsers, but it's just nicer in Arc)&lt;/li&gt;
&lt;li&gt;(Folders)[&lt;a href="https://resources.arc.net/en/articles/6449566-folders-stash-similar-tabs-together" rel="noopener noreferrer"&gt;https://resources.arc.net/en/articles/6449566-folders-stash-similar-tabs-together&lt;/a&gt;]&lt;/li&gt;
&lt;li&gt;(Pinned Tabs (and the amazing Tab Reset feature))[&lt;a href="https://resources.arc.net/en/articles/6449654-pinned-tabs-tabs-you-want-to-stick-around" rel="noopener noreferrer"&gt;https://resources.arc.net/en/articles/6449654-pinned-tabs-tabs-you-want-to-stick-around&lt;/a&gt;]&lt;/li&gt;
&lt;li&gt;Portrait Mode&lt;/li&gt;
&lt;li&gt;Quoted Links&lt;/li&gt;
&lt;li&gt;Workspace/Folder Sharing&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Arc is such a promising browser and a lot of people have asked me why I don't ask them for sponsorship at the rate I talk about them (as a joke of course). I have just been waiting for a browser like this that keeps me interested in using it for more than just what I use a browser for. The integration, the ease of use and simplicity is just incredible.&lt;/p&gt;

&lt;p&gt;It's like waking up to Christmas every Thursday (cause they usually release updates on Thursdays). Arc does the little things right and I honestly want nothing but a better browser for everyone and this is the biggest step I have seen in that direction.&lt;/p&gt;

&lt;p&gt;They have a long way to go but if they keep doing what they're doing I have no doubt in my mind they will be the browser to beat!&lt;/p&gt;

&lt;p&gt;So keep it up Arc! Can't wait to see what you have in store!&lt;/p&gt;

</description>
      <category>tooling</category>
    </item>
    <item>
      <title>React Hooks (useEffect)</title>
      <dc:creator>Ryan Kuruppu</dc:creator>
      <pubDate>Mon, 15 Feb 2021 20:52:12 +0000</pubDate>
      <link>https://forem.com/aisirachcha21/react-hooks-useeffect-5hif</link>
      <guid>https://forem.com/aisirachcha21/react-hooks-useeffect-5hif</guid>
      <description>&lt;h1&gt;
  
  
  🔖 Table of Contents
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;The Task&lt;/li&gt;
&lt;li&gt;Setup&lt;/li&gt;
&lt;li&gt;Adding the useEffect hook&lt;/li&gt;
&lt;li&gt;Structure of the useEffect hook&lt;/li&gt;
&lt;li&gt;The dependency array&lt;/li&gt;
&lt;li&gt;Example with dependencies and cleanup&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So this section of the tutorial is going to speak about the useEffect hook. What it is, how it works and how it fairs compared to the existing 3 class functions given to use by React.&lt;/p&gt;

&lt;h2&gt;
  
  
  ❗ Just for your Information
&lt;/h2&gt;

&lt;p&gt;I won't go into too much detail and I'm going to keep this brief to a point where it'll make sense but I do suggest that after you finish this tutorial. Read the links I attach below for a deeper understanding especially the explanation by Dan Abramov the creator of React.&lt;/p&gt;

&lt;p&gt;There's a bit of reading here but bare with.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is the useEffect hook?
&lt;/h1&gt;

&lt;p&gt;The useEffect hook is a replacement for 3 of React's class-based lifecycle functions namely,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;componentDidMount&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;componentDidUpdate&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;componentWillUnmount&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As of React 16.8 and React Native 0.59, the useEffect hook combines all 3 of these functions into one single function with a cleaner and concise look.&lt;/p&gt;

&lt;p&gt;Just like the 3 earlier functions, you would do side effects like Data Fetching, Subscriptions etc. from within the useEffect hook(s)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note how I said "hook(s)" with an s. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's right! Your functional component can have multiple useEffect hooks to handle different actions within your code.🎉🎉&lt;/p&gt;

&lt;h1&gt;
  
  
  So how is this gonna work?
&lt;/h1&gt;

&lt;p&gt;First I'm gonna describe the task we'll be using to demonstrate the useEffect hook then we'll go through the useEffect hook and its structure and we'll initially write the component in a class component so you understand how it works (also so the beginners understand if any). Then finally we'll talk about the pros and cons of using it compared to your usual class functions.&lt;/p&gt;

&lt;p&gt;So lets get started.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Task &lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;We'll keep it simple. Sweet. Like Music 🎵&lt;/p&gt;

&lt;p&gt;We're simply going to use the site &lt;a href="https://jsonplaceholder.typicode.com/"&gt;JSON placeholder&lt;/a&gt; to generate some random Post (comments, username etc.) data for us and we're going to pull that into our component using class lifecycle functions first and then hooks and display it in our page.&lt;/p&gt;

&lt;p&gt;After this. We're going to demonstrate another use case where we'll be attaching an event listener to our component to monitor the scroll position. This will help us understand the cleanup dependencies a little better.&lt;/p&gt;

&lt;h1&gt;
  
  
  Let's start writing. &lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;We'll start by laying down the foundation for our component. So we'll use our App.js file which comes by default in &lt;a href="https://reactjs.org/tutorial/tutorial.html#setup-option-2-local-development-environment"&gt;create-react-app&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Just make sure your App.js file looks like this.&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="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="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;render&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;&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;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Let's use a state variable like in the &lt;a href="https://dev.to/aisirachcha21/react-hooks-from-class-to-functional-22m6#statefulClassComponentExample"&gt;previous tutorial&lt;/a&gt; to hold all our posts.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;  React from 'react'
&lt;span class="err"&gt;
&lt;/span&gt;  class App extends React.Component{
&lt;span class="gi"&gt;+    constructor(){
+        this.state = {
+            posts = []
+        }
+    }
&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;     render(){
        return &amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;
     }
  }
&lt;span class="err"&gt;
&lt;/span&gt;  export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Now let's fetch the data from JSON Placeholder using ComponentWillMount&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;React from 'react'
&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="p"&gt;class App extends React.Component{
&lt;/span&gt;    constructor(){
        this.state = {
            posts = []
        }
    }
&lt;span class="gi"&gt;+
+   componentDidMount(){
+       fetch("https://jsonplaceholder.typicode.com/posts")
+           .then((response) =&amp;gt; response.json())
+           .then((data)=&amp;gt;this.setState({posts: data})
+   )}
+
&lt;/span&gt;    render(){
&lt;span class="gd"&gt;-     return &amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;
&lt;/span&gt;&lt;span class="gi"&gt;+     return( 
+         &amp;lt;div&amp;gt;
+          {posts.map((p)=&amp;gt;{
+             return (
+                  &amp;lt;div key={p.id}&amp;gt;
+                    &amp;lt;h1&amp;gt;{p.title}&amp;lt;/h1&amp;gt;
+                    &amp;lt;h4&amp;gt;{p.subtitle}&amp;lt;/h4&amp;gt;
+                  &amp;lt;/div&amp;gt;
+              )
+          })}
+          &amp;lt;/div&amp;gt;
+     )
&lt;/span&gt;   }
}
&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="p"&gt;export default App;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Normal so far cause well.. this is how you'd write it in the "Pre-Hook" Era.&lt;/p&gt;

&lt;p&gt;With this you should be able to successfully get data from the frontend.&lt;/p&gt;

&lt;h2&gt;
  
  
  Now lets start changing things up &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;So lets start by changing up the component and it's state to a hook based state like the previous tutorial&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="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&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;posts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setPosts&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&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;&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;h3&gt;
  
  
  Next lets introduce the useEffect hook.
&lt;/h3&gt;

&lt;p&gt;The useEffect hook, like I stated before. Has 3 important parts. This short example will use just 1 part. The Action which in our case is the fetch request for all the posts.&lt;/p&gt;

&lt;p&gt;So let's add it and display them.&lt;a&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="gi"&gt;+ // Import useEffect
&lt;/span&gt; import React, {useState, useEffect} from 'react'
&lt;span class="err"&gt;
&lt;/span&gt;  function App(){
    const [posts, setPosts] = useState([]);
&lt;span class="err"&gt;
&lt;/span&gt;   //Add the useEffect.
&lt;span class="gi"&gt;+   useEffect(()=&amp;gt;{
+      fetch("https://jsonplaceholder.typicode.com/posts")
+        .then((response) =&amp;gt; response.json())
+        .then((data)=&amp;gt; setPosts(data));
+   },[]);
&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;    return (
&lt;span class="gd"&gt;-     &amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;
-   );
&lt;/span&gt;&lt;span class="gi"&gt;+   return(
+     &amp;lt;div&amp;gt;
+       {/* Render Posts */}
+       {posts.map((p)=&amp;gt;(
+           &amp;lt;div&amp;gt;
+             &amp;lt;h1&amp;gt;{p.title}&amp;lt;/h1&amp;gt;
+             &amp;lt;h4&amp;gt;{p.subtitle}&amp;lt;/h4&amp;gt;
+           &amp;lt;/div&amp;gt;
+       )}
+     &amp;lt;/div&amp;gt;
+   )
+ }
&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✨And thats it !!✨&lt;/p&gt;

&lt;p&gt;So let see what we exactly did with the component. &lt;/p&gt;

&lt;p&gt;The useState hook is similar to what we did in the previous tutorial.&lt;/p&gt;

&lt;p&gt;The useEffect is the new part here for us.&lt;/p&gt;

&lt;p&gt;Let's see how it works.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Structure &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzae1wittpb5ytg5o170u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzae1wittpb5ytg5o170u.png" alt="Alt Text" width="800" height="302"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  The callback function (A function which is passed as an argument to another function) is the first argument of the useEffect hook.
&lt;/h4&gt;

&lt;p&gt;It is inside this function that we define our side effect, data fetching calls, subscriptions or listeners. It runs after the component renders so that the component render isn't blocked by the code running within the hook.&lt;/p&gt;

&lt;p&gt;Nothing much to explain there &lt;/p&gt;

&lt;p&gt;The thing we &lt;strong&gt;SHOULD&lt;/strong&gt; notice is the second argument&lt;/p&gt;

&lt;h3&gt;
  
  
  The Dependency Array 😵&lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foy4ga8pv5kbptn2xdhq4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foy4ga8pv5kbptn2xdhq4.png" alt="Alt Text" width="800" height="302"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What the heck is a dependency array? You may ask. &lt;/p&gt;

&lt;p&gt;The dependency array as the name says, is essentially a list of variables that your component will "watch" for changes in. &lt;/p&gt;

&lt;p&gt;When a variable in the dependency array changes, your component will save a snapshot (temporary copy) of your component state and make a new call to the callback function you created inside your useEffect hook essentially leading to a rebuild of you React Component.&lt;/p&gt;

&lt;p&gt;The dependency array is an optional argument and you can omit it but you can also include as many dependency variables as you like. But be smart about it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;However&lt;/strong&gt;, even though the dependency array is optional. Leaving it out will cause an infinite loop of function calls.&lt;/p&gt;

&lt;p&gt;Try it out and see what happens by copying this useEffect into your function and running it.&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="nf"&gt;useEffect&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll notice that in your console. You'll end up causing an infinite loop. This is really confusing which is why I urge you to read &lt;a href="https://overreacted.io/a-complete-guide-to-useeffect/"&gt;this article&lt;/a&gt; by Dan Abramov which I've listed at the end of the tutorial as well.&lt;/p&gt;

&lt;p&gt;Cool. That's fine. So then why does our example above have an empty array? (snippet is below this)&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="nf"&gt;useEffect&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="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://jsonplaceholder.typicode.com/posts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;response&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;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setPosts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&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;Well, simply put. Providing an empty dependency array tells React to only run this specific useEffect hook &lt;strong&gt;ONLY&lt;/strong&gt; on the &lt;strong&gt;FIRST&lt;/strong&gt; Render of our component. This is when the component is mounted into the DOM essentially replacing our &lt;code&gt;componentDidMount&lt;/code&gt; function.&lt;/p&gt;

&lt;h3&gt;
  
  
  Okay so how do I update the UI using useEffect? &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Since you hopefully understood how the useEffect works theoretically. I'll show you the second example I mentioned here&lt;/p&gt;

&lt;p&gt;We'll create a component that monitors the scroll position of the UI using useEffect and useState. &lt;/p&gt;

&lt;p&gt;We'll also go through the "clean up" part of the useEffect hook and what it does.&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;useEffect&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="s1"&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="nf"&gt;ScrollWatcher&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;offsetValue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setOffsetValue&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;useEffect&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="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onScroll&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
          &lt;span class="nf"&gt;setOffsetValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pageYOffset&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;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onScroll&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
       &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pageYOffset&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="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="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1000vh&lt;/span&gt;&lt;span class="dl"&gt;"&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;offsetValue&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;So just to describe what we've done here.&lt;/p&gt;

&lt;p&gt;When the component mounts, we tell our useEffect hook to add a listener to the window scroll event and update the state.&lt;/p&gt;

&lt;p&gt;The points of interest here are again,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Dependency Array&lt;/li&gt;
&lt;li&gt;The return function&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The dependency array now has the window.pageYOffset variable added to it. What this means is that whenever the window.pageYOffset value changes. The useEffect hook will re-run and update the offsetValue state variable.&lt;/p&gt;

&lt;p&gt;The return function here is the action we will carry out when the component is about to unmount. This is the reason we call it the "clean up" function. This is where we will remove any subscriptions or listeners attached to the component or its variables.&lt;/p&gt;

&lt;p&gt;And thats it. It wasn't much of an explanation but hopefully you got the gist of it. Just some final tips before I suggest some articles you should definitely have a look at.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tips
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;You can create multiple useEffect hooks. One for data fetching one for subscriptions for example.&lt;/li&gt;
&lt;li&gt;If you create multiple useEffect hooks, note that they are executed in the order they are written. &lt;/li&gt;
&lt;li&gt;Read as much as you can about the useEffect hook to better understand how this works. It can save you the world of time when debugging your code.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Other than that,&lt;/p&gt;

&lt;h2&gt;
  
  
  Hope you enjoyed !😊
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Let me know what you think in the comments below !
&lt;/h4&gt;

&lt;p&gt;Read my tutorial on the useCallback hook (Will be added in the future)&lt;/p&gt;




&lt;h1&gt;
  
  
  Further Reading
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://overreacted.io/a-complete-guide-to-useeffect/"&gt;A complete guide to useEffect&lt;/a&gt; By Dan Abramov&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://reactjs.org/docs/hooks-effect.html"&gt;Official Docs&lt;/a&gt; by React&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/better-programming/understanding-the-useeffect-dependency-array-2913da504c44"&gt;Understanding the useEffect Dependency Array&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>useeffect</category>
      <category>tutorial</category>
      <category>react</category>
      <category>reactnative</category>
    </item>
    <item>
      <title>React Hooks (from Class to Functional)</title>
      <dc:creator>Ryan Kuruppu</dc:creator>
      <pubDate>Sun, 14 Feb 2021 14:24:55 +0000</pubDate>
      <link>https://forem.com/aisirachcha21/react-hooks-from-class-to-functional-22m6</link>
      <guid>https://forem.com/aisirachcha21/react-hooks-from-class-to-functional-22m6</guid>
      <description>&lt;p&gt;This tutorial will guide you through what React Hooks are and the main changes you'll need in order to shift your React components over from Class Based Components to Hook Based Components.&lt;/p&gt;

&lt;p&gt;The tutorial is broken down into separate pages to make sure that everything isn't clunked up together&lt;/p&gt;

&lt;h1&gt;
  
  
  🔖 Table of Contents
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Pre-Requisites&lt;/li&gt;
&lt;li&gt;What are Hooks&lt;/li&gt;
&lt;li&gt;useState Hook&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/aisirachcha21/react-hooks-useeffect-5hif"&gt;useEffect Hook&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;useMemo Hook (To be made)&lt;/li&gt;
&lt;li&gt;useCallback Hook (To be made)&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Pre-Requisites? &lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Just make sure your React Version is 16.8 or higher.&lt;/p&gt;

&lt;p&gt;If you have react globally installed just check the version by using,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;ls &lt;/span&gt;react-native &lt;span class="nt"&gt;-g&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or check your package.json if you already have a existing project.&lt;/p&gt;

&lt;h1&gt;
  
  
  What are Hooks ?&lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;React hooks are new way of using state and other react features without the need for classes. They stem from the old React way of writing stateless components using normal functions and add features on top of it so that you don't need to write JavaScript(or TypeScript) classes anymore for the features (like stateful components) given to us in React. &lt;/p&gt;

&lt;h2&gt;
  
  
  What hooks are we going to look at
&lt;/h2&gt;

&lt;p&gt;There are 10 hooks given to us by React. But we'll be discussing the more commonly used hooks as well as how to use props in React functional components just in case you're new to using functional components as a whole.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;useState&lt;/li&gt;
&lt;li&gt;useEffect&lt;/li&gt;
&lt;li&gt;useMemo&lt;/li&gt;
&lt;li&gt;useCallback&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can check out the other hooks provided by React &lt;a href="https://reactjs.org/docs/hooks-reference.html" rel="noopener noreferrer"&gt;from the docs&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Functional Components
&lt;/h1&gt;

&lt;p&gt;Let's take a quick look at functional components before we head into the hooks.&lt;/p&gt;

&lt;p&gt;Functional Components in React were initially only used to describe stateless components. Even with the introduction of hooks they can still be used as stateless components by simply leaving out the useState hook from the component.&lt;/p&gt;

&lt;p&gt;Here's what a stateless component looks like in React.&lt;a&gt;&lt;/a&gt;&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="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;

    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;someFunction&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
        &lt;span class="c1"&gt;//...some code&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;button&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="nx"&gt;someFunction&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Click Me&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;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;Button&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pretty simple.&lt;/p&gt;

&lt;p&gt;But now lets convert this to a stateful component by incrementing a number inside the button whenever it's clicked.&lt;/p&gt;

&lt;p&gt;Prior to React 16.8... this is how you would do it.&lt;a&gt;&lt;/a&gt;&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="s1"&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;class&lt;/span&gt; &lt;span class="nc"&gt;Button&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
        &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;increment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&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="nf"&gt;render&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;button&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;increment&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;counter&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;button&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="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;Button&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  As you can probably see
&lt;/h3&gt;

&lt;p&gt;There's quite a bit of boiler plate code including somewhat unnecessary lines like &lt;/p&gt;

&lt;p&gt;&lt;code&gt;this.increment = this.increment.bind(this)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Which can lead to a lot of code pollution as the project gets bigger 😤&lt;/p&gt;




&lt;h2&gt;
  
  
  Hooks to the rescue 😌
&lt;/h2&gt;

&lt;p&gt;So we need to change this class component (called Button) into a new functional component using React's hook implementation.&lt;/p&gt;

&lt;p&gt;Enter the useState hook. 💥&lt;/p&gt;

&lt;h3&gt;
  
  
  useState Hook &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;The useState hook is a function that takes in one optional parameter and returns two values. &lt;/p&gt;

&lt;p&gt;The optional parameter is the &lt;strong&gt;initial state&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The returned values are,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The State Variable&lt;/li&gt;
&lt;li&gt;The setState function for that state variable&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;in the form of a destructured array.&lt;/p&gt;

&lt;p&gt;It looks like this.&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;stateVariableName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setStateVariableName&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So how do we create a functional component?&lt;/p&gt;

&lt;p&gt;Using the stateful component made using the class component from before&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Lets start by importing React and the useState hook at the top of your file.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="gi"&gt;+ import React, {useState} from 'react'
+    
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Then we write a functional component like we did in the earlier stateless component and return a simple button component&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;import React, {useState} from 'react'
&lt;/span&gt;&lt;span class="gi"&gt;+
+ function Button(){
+     return &amp;lt;button&amp;gt;&amp;lt;/button&amp;gt;
+ }
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Then we created the state variable. Using the below method&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5qwxjgil1x98ruycaigi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5qwxjgil1x98ruycaigi.png" alt="Alt Text" width="800" height="332"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;import React, {useState} from 'react'
&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt; function Button(){
&lt;span class="gi"&gt;+
+    const [counter, useCounter] = useState(0);
+
&lt;/span&gt;    return &amp;lt;button&amp;gt;&amp;lt;/button&amp;gt;
}
&lt;span class="err"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We then attach the counter state as the label for the button&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;import React, {useState} from 'react'
&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt; function Button(){
&lt;span class="err"&gt;
&lt;/span&gt;    const [counter, useCounter] = useState(0);
&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="gd"&gt;-   return &amp;lt;button&amp;gt;&amp;lt;/button&amp;gt;
&lt;/span&gt;&lt;span class="gi"&gt;+   return &amp;lt;button&amp;gt; {counter} &amp;lt;/button&amp;gt;
&lt;/span&gt; }
&lt;span class="err"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And finally we created and attached the increment method and used the &lt;code&gt;setCounter&lt;/code&gt; function to update the state&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt; function Button(){
    const [counter, setCounter] = useState(0);
&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="gi"&gt;+   function increment(){
+       setCounter(counter + 1);
+   }
+
&lt;/span&gt;&lt;span class="gd"&gt;-   return &amp;lt;button&amp;gt; {counter} &amp;lt;/button&amp;gt;
&lt;/span&gt;&lt;span class="gi"&gt;+   return &amp;lt;button onclick={increment}&amp;gt; {counter} &amp;lt;/button&amp;gt;
&lt;/span&gt; }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  That's It !!🔥🔥🔥
&lt;/h4&gt;

&lt;p&gt;So what have we done ??&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We've removed the use of the &lt;code&gt;this&lt;/code&gt; keyword&lt;/li&gt;
&lt;li&gt;We've removed a bunch of boiler plate for binding functions and state.&lt;/li&gt;
&lt;li&gt;We've essentially made our code more clean and concise.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Now what?
&lt;/h3&gt;

&lt;p&gt;Well for now, you can read about the useState hook from Reacts Documentation&lt;/p&gt;

&lt;p&gt;Or&lt;/p&gt;

&lt;p&gt;You can go read my article about the useEffect Hook. (To be made)&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactnative</category>
      <category>hooks</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Working with Single-SPA</title>
      <dc:creator>Ryan Kuruppu</dc:creator>
      <pubDate>Sun, 06 Dec 2020 16:50:37 +0000</pubDate>
      <link>https://forem.com/aisirachcha21/working-with-single-spa-4jm6</link>
      <guid>https://forem.com/aisirachcha21/working-with-single-spa-4jm6</guid>
      <description>&lt;p&gt;UPDATE: This article was written with single-spa-react v2.14.0&lt;/p&gt;

&lt;p&gt;Micro-frontends are gradually gaining popularity as a way to separate frontend applications in to small performant and easy to maintain parts doing this can lead to a variety of issues in terms of maintenance but libraries like Single-SPA and Piral make that easier for us.&lt;/p&gt;

&lt;p&gt;This tutorial will cover the steps on how to set up the &lt;strong&gt;single-spa.js&lt;/strong&gt; library and get your micro-frontend setup working.&lt;/p&gt;

&lt;p&gt;If it helps you. Leave a like so I can keep pushing stuff like this for you guys&lt;/p&gt;

&lt;h2&gt;
  
  
  Before you jump in
&lt;/h2&gt;

&lt;p&gt;Before we start working with this I'm going to let you know that as of &lt;strong&gt;Webpack 5&lt;/strong&gt;, a new plugin has been released for webpack to enable &lt;strong&gt;"Module Federation"&lt;/strong&gt; which is Webpack's way of achieving Micro-Frontend Architectures it is usually used as more of a performance enhancer but can be used to achieve the same thing as this.&lt;/p&gt;

&lt;p&gt;To understand the difference between these and what they can do check &lt;a href="https://single-spa.js.org/docs/recommended-setup/#module-federation" rel="noopener noreferrer"&gt;this article snippet&lt;/a&gt; by the single-spa team&lt;/p&gt;

&lt;p&gt;This article simply covers Single-SPA as (what I feel) an easier alternative to Webpack 5's Module Federation. &lt;/p&gt;

&lt;p&gt;So let's get started.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Single-SPA?
&lt;/h3&gt;

&lt;p&gt;The single SPA team refers to it as a &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A javascript router for front-end microservices.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To elaborate on this, Single SPA is a &lt;strong&gt;javascript&lt;/strong&gt; library which allows you to connect together multiple isolated frontend services to look and behave as a single monolith application.&lt;/p&gt;

&lt;p&gt;Read &lt;a href="https://www.mulesoft.com/resources/api/microservices-vs-monolithic#:~:text=A%20monolithic%20application%20is%20built,and%20a%20server%2Dside%20application." rel="noopener noreferrer"&gt;Microservices vs Monolith Application&lt;/a&gt; to learn more the differences.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why use it?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Multiple Frameworks. One single entry point.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;single-spa lets you mix and match supported frameworks or libraries and make them act and appear seamless for example you can use React and Angular to make two sections of the same app and it will look like it was built with just one of the two frameworks.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Performant&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;While this more or less depends on the applications themselves. By using single-spa to join together separate applicaitons. You can reduce the bundle size of any single application and still connect them as you require without any performance loss between apps.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Extremely easy to setup.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Most of the setup is done in the root application and beyond that, the &lt;code&gt;create-single-spa&lt;/code&gt; CLI does most of the work.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lazy Loading enabled by default.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  So how does it work?
&lt;/h3&gt;

&lt;p&gt;I personally think this video gives a great introduction to how Single-SPA works in a really basic way.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/L4jqow7NTVg"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Hopefully you got an idea. If not, read &lt;a href="https://single-spa.js.org/docs/getting-started-overview#javascript-microfrontends" rel="noopener noreferrer"&gt;this article&lt;/a&gt; to understand it a bit better&lt;/p&gt;

&lt;h3&gt;
  
  
  Okay, lets start writing
&lt;/h3&gt;

&lt;p&gt;I'll be using &lt;strong&gt;Visual Studio Code&lt;/strong&gt; as my editor of choice and &lt;strong&gt;React&lt;/strong&gt; as the framework of choice for each micro-frontend application to keep things simple. But you can do the same thing to mix and match with other frameworks as well.&lt;/p&gt;

&lt;p&gt;Single-SPA has two main parts which need to be considered,&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The Root Configuration
  &lt;ul&gt;
    &lt;li&gt;This will contain the HTML page needed for rendering the javascript framework components and the functions responsible for handling the application routing.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/li&gt;
  &lt;li&gt;The Application's Themselves
  &lt;ul&gt;
    &lt;li&gt;These are the application written in frameworks and libraries such as React, Vue, Svelte or even Angular&lt;/li&gt;
  &lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We'll start by setting up the Root Configuration Application using &lt;br&gt;&lt;code&gt;create-single-spa&lt;/code&gt; CLI tool provided by Single-SPA&lt;/p&gt;

&lt;p&gt;Install &lt;code&gt;create-single-spa&lt;/code&gt; tool by installing it through npm or yarn&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; create-single-spa


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Or if you're using yarn&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

yarn global add create-single-spa


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Then follow these steps to do the &lt;code&gt;create-single-spa&lt;/code&gt; setup.
&lt;/h4&gt;

&lt;p&gt;Step 1 : Create the root configuration by using the following command&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

npx create-single-spa


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;After running that, you should see this &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpnp4wh80br2n0nbjdli9.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpnp4wh80br2n0nbjdli9.PNG" alt="Directory Name"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just leave it blank &amp;amp; click enter to use the Current Directory.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Then Choose &lt;code&gt;single-spa root config&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flr2nydv5m4ugf765qebo.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flr2nydv5m4ugf765qebo.PNG" alt="create-single-spa menu"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Choose the package manager of your choice. I'm going to pick &lt;code&gt;yarn&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Choose whether to create the project as a &lt;strong&gt;Typescript or Javascript&lt;/strong&gt; project. I'll be using Javascript.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Decide whether you'll be using Single-SPA's template engine. In this tutorial we won't be using it for the sake of simplicity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, provide an organization name&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;The organization name should be the same across all the applications. This is because single-spa allows module resolution in the browser, it requires the organization name to be the same in order for it to work.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I will use my name (ryank) as the organization for now (This will usually be the name of your application).&lt;/p&gt;

&lt;p&gt;At the this point your config should look like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8wv5r0y0zd702sg8rig0.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8wv5r0y0zd702sg8rig0.PNG" alt="Full Configuration"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just click enter and single-spa should create the required files for your root application.&lt;/p&gt;

&lt;p&gt;Your Folder structure will end up looking like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjw1nn4rays9wsd1xro4u.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjw1nn4rays9wsd1xro4u.PNG" alt="Folder Structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now to see if everything works, just run either &lt;code&gt;yarn start&lt;/code&gt; or &lt;code&gt;npm run start&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you see this page on &lt;code&gt;localhost:9000&lt;/code&gt;, you have successfully setup the root configuration application for single-spa.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fd2t87k8kwhov2dd7mwvn.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fd2t87k8kwhov2dd7mwvn.PNG" alt="Single SPA Welcome Page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  A bit of a run through
&lt;/h3&gt;

&lt;p&gt;Inside the src folder, you will notice 2 files.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;index.ejs&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is the file which will be used as our index.html file after compilation. It will hold important information regarding our micro-frontend applications such as import-maps which our root-config.js file will use to navigate apps as well as the different common modules that each of our applications will use.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;ryank-root-config.js&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is our root configuration file where we will register our micro-frontends to single-spa.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These two files will control a lot in a very little amount of work.&lt;/p&gt;

&lt;h3&gt;
  
  
  So how do I register my app ?
&lt;/h3&gt;

&lt;p&gt;Well in order to do that. We first need to need to create an application so that we can register it to our root component.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 1
&lt;/h4&gt;

&lt;p&gt;Replicate the previous steps but instead of choosing &lt;br&gt;&lt;code&gt;single-spa root-config&lt;/code&gt;&lt;br&gt; We choose &lt;br&gt; &lt;code&gt;single-spa application/parcel&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Like below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh04c40higgv3uaod4fo9.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh04c40higgv3uaod4fo9.PNG" alt="Pick Application from Menu"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2
&lt;/h4&gt;

&lt;p&gt;Choose the framework of your choice. In our case, we'll use &lt;strong&gt;React&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 3
&lt;/h4&gt;

&lt;p&gt;Pick the package manager. We'll stick with &lt;strong&gt;yarn&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 4
&lt;/h4&gt;

&lt;p&gt;Choose whether to use Typescript or not. We'll use &lt;strong&gt;plain Javascript&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 5
&lt;/h4&gt;

&lt;p&gt;Add the same organization name as you did with your root configuration.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 6
&lt;/h4&gt;

&lt;p&gt;Here you need to add the name of your project. So in my case the project name will simply be &lt;code&gt;app1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Your configuration should look similar to this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffk3llt9evzrpme9711nm.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffk3llt9evzrpme9711nm.PNG" alt="Configuration for Application"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After clicking enter again. Single-SPA should create the necessary files and your folder structure should look like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnxxngo7v7x7ofb1bczq9.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnxxngo7v7x7ofb1bczq9.PNG" alt="App1 Folder Structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you see the above structure, check if you app is working by starting your app like below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

yarn start &lt;span class="nt"&gt;--port&lt;/span&gt; 8500


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And visit &lt;a href="http://single-spa-playground.org/playground/instant-test?name=@ryank/app1&amp;amp;url=8500" rel="noopener noreferrer"&gt;http://single-spa-playground.org/playground/instant-test?name=@ryank/app1&amp;amp;url=8500&lt;/a&gt; &lt;br&gt; where "app1" in the url is whatever you named your project and 8500 is the port you used.&lt;/p&gt;

&lt;p&gt;If you see this, you're on the right path&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5unmu7fwfczg8573fytv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5unmu7fwfczg8573fytv.png" alt="App1 Playground"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Now we connect them&lt;/strong&gt;.
&lt;/h3&gt;

&lt;p&gt;To connect your application to single-spa's config you need to do a couple of things. Before that lets introduce some new terms.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Shared Dependencies&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;These are packages/libraries that are used across your micro-frontends. For example, if you were making a bunch of react micro-frontends, you would have to use &lt;code&gt;react&lt;/code&gt; and &lt;code&gt;react-dom&lt;/code&gt; across all of them. But remember that this is conditionally optional based on the requirements of your app.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Import Maps&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Import Maps are a browser specification for aliasing "import specifiers" to a URL. An import specifier is the string indicating which module to load. This will act as sort of an index for single-spa to follow when looking for apps to run.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;SystemJS&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Please read single-spa's description of &lt;a href="https://single-spa.js.org/docs/recommended-setup/#systemjs" rel="noopener noreferrer"&gt;SystemJS&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Public Path&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Public Path is the public location of your application. This could be your local host or even a hosted URL from google cloud, AWS or Azure.
We use the &lt;code&gt;setPublicPath&lt;/code&gt;function inside &lt;code&gt;set-public-path.js&lt;/code&gt;to set this. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Alright now that that's done, let's connect our react app to our root app.&lt;/p&gt;

&lt;p&gt;Remember, we are working on the context that all our microfrontends are built in react.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 1 : Configuring the Root App
&lt;/h4&gt;

&lt;p&gt;Navigate to your root application and open up the index.ejs file.&lt;/p&gt;

&lt;p&gt;Then copy these CDN's providing us with &lt;code&gt;react&lt;/code&gt; and &lt;code&gt;react-dom&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

"react": "https://cdn.jsdelivr.net/npm/react@16.13.1/umd/react.production.min.js",
"react-dom": "https://cdn.jsdelivr.net/npm/react-dom@16.13.1/umd/react-dom.production.min.js"


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Locate this code snippet&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;systemjs-importmap&lt;/span&gt;&lt;span class="dl"&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;imports&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;single-spa&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;https://cdn.jsdelivr.net/npm/single-spa@5.5.5/lib/system/single-spa.min.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And add the CDN's you copied after the single-spa CDN seperated by commas like this &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="err"&gt;

&lt;/span&gt;&amp;lt;script type="systemjs-importmap"&amp;gt;
    {
      "imports": {
&lt;span class="gd"&gt;-        "single-spa": "https://cdn.jsdelivr.net/npm/single-spa@5.5.5/lib/system/single-spa.min.js"
&lt;/span&gt;&lt;span class="gi"&gt;+        "single-spa": "https://cdn.jsdelivr.net/npm/single-spa@5.5.5/lib/system/single-spa.min.js",
+        "react": "https://cdn.jsdelivr.net/npm/react@16.13.1/umd/react.production.min.js",
+        "react-dom": "https://cdn.jsdelivr.net/npm/react-dom@16.13.1/umd/react-dom.production.min.js"
&lt;/span&gt;      }
    }
&amp;lt;/script&amp;gt;
&lt;span class="err"&gt;

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This is done so that &lt;code&gt;react&lt;/code&gt; and &lt;code&gt;react-dom&lt;/code&gt; will be used across any of the new micro-frontends that we add.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2 : Registering the New App
&lt;/h4&gt;

&lt;p&gt;To register the app, you need to first&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to your microfrontend app (app1 in our case)&lt;/li&gt;
&lt;li&gt;Navigate to &lt;code&gt;src/set-public-path.js&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Copy the text inside the &lt;code&gt;setPublicPath()&lt;/code&gt; function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The text inside is a combination of your organization name and project name in the following format &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

@organization/project


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After copying the text. Head back to your root config file and open the ryank-root-config.js file (ryank will be whatever your organization name is)&lt;/p&gt;

&lt;p&gt;You should see a file like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnl5hn17xpm1q5m0yr9tl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnl5hn17xpm1q5m0yr9tl.png" alt="ryank-root-config.js"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;registerApplication()&lt;/code&gt; function is what will help us register our app to single-spa. It takes 3 arguments

&lt;ol&gt;
&lt;li&gt;name : This is your project identifier which has a format of &lt;code&gt;@organization/project&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;app: This is a SystemJS import call that make a call to your app in order to bring it into the root application&lt;/li&gt;
&lt;li&gt;activeWhen: This is either an array of strings which denote the path or a function that returns a string. This tell single-spa when your application should be active and when it shouldn't show.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To register &lt;code&gt;app1&lt;/code&gt; to single spa,&lt;/p&gt;

&lt;p&gt;Uncomment the commented code and replace it so that it looks like the following.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="err"&gt;

&lt;/span&gt;&lt;span class="p"&gt;import { registerApplication, start } from "single-spa";
&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="p"&gt;registerApplication({
&lt;/span&gt;  name: "@single-spa/welcome",
  app: () =&amp;gt;
    System.import(
      "https://unpkg.com/single-spa-welcome/dist/single-spa-welcome.js"
    ),
  activeWhen: ["/"],
});
&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="gd"&gt;-// registerApplication({
-//   name: "@ryank/navbar",
-//   app: () =&amp;gt; System.import("@ryank/navbar"),
-//   activeWhen: ["/"]
-// });
&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="gi"&gt;+ registerApplication({
+   name: "@ryank/app1",
+   app: () =&amp;gt; System.import("@ryank/app1"),
+   activeWhen: ["/app1"]
+ });
&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="p"&gt;start({
&lt;/span&gt;  urlRerouteOnly: true,
});
&lt;span class="err"&gt;


&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This will tell single-spa to render &lt;code&gt;app1&lt;/code&gt; when we navigate to &lt;code&gt;http://localhost:9000/app1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After this we need to one more thing and that is adding your application to the import map.&lt;/p&gt;

&lt;p&gt;To do this. You need to find this section of code in your index.ejs file&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="o"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isLocal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;systemjs-importmap&lt;/span&gt;&lt;span class="dl"&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;imports&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@ryank/root-config&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;//localhost:9000/ryank-root-config.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&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="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;and then add your application url to it&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="err"&gt;

&lt;/span&gt;&amp;lt;% if (isLocal) { %&amp;gt;
  &amp;lt;script type="systemjs-importmap"&amp;gt;
    {
      "imports": {
        "@ryank/root-config": "//localhost:9000/ryank-root-config.js"
&lt;span class="gi"&gt;+       "@ryank/app1":"//localhost:8500/ryank-app1.js"
&lt;/span&gt;      }
    }
  &amp;lt;/script&amp;gt;
&amp;lt;% } %&amp;gt;
&lt;span class="err"&gt;


&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The reason we need to add this to two places (index.ejs and root-config.js) is because single-spa runs the &lt;code&gt;registerApplication&lt;/code&gt; function and then calls SystemJS which in turn refers to the import map located in your index.ejs file to find the relevant location of your micro-frontends.&lt;/p&gt;

&lt;p&gt;If you followed these steps correctly your app should show up when you navigate to &lt;code&gt;http://localhost:9000/app1&lt;/code&gt; and you should see something like this : &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F10s4duryc4xrqrgdicz5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F10s4duryc4xrqrgdicz5.png" alt="Mounted App"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The are surrounded in red is your app.&lt;/p&gt;

&lt;p&gt;But if you notice both the Home Page (at &lt;code&gt;localhost:9000&lt;/code&gt;) and your app (at &lt;code&gt;localhost:9000/app1&lt;/code&gt;) are rendered in the same page. &lt;/p&gt;

&lt;p&gt;This is single-spa's normal behavior so there's nothing to worry but we can change it by making a small change to the &lt;code&gt;registerApplication&lt;/code&gt; function holding the home page.&lt;/p&gt;

&lt;p&gt;To do this, navigate to your root-config.js file and change your file like the following&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="err"&gt;

&lt;/span&gt;&lt;span class="p"&gt;import { registerApplication, start } from "single-spa";
&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="gd"&gt;- registerApplication({
-  name: "@single-spa/welcome",
-  app: () =&amp;gt;
-    System.import(
-      "https://unpkg.com/single-spa-welcome/dist/single-spa-welcome.js"
-    ),
-  activeWhen: ['/'],
-});
&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="gi"&gt;+ registerApplication(
+   "@single-spa/welcome",
+   () =&amp;gt;
+     System.import("https://unpkg.com/single-spa-welcome/dist/single-spa-welcome.js"
+    ),
+    (location) =&amp;gt; location.pathname.endsWith('/'),
+);
&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="p"&gt;registerApplication({
&lt;/span&gt;  name: "@ryank/app1",
  app: () =&amp;gt; System.import("@ryank/app1"),
  activeWhen: ["/app1"]
});
&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="p"&gt;start({
&lt;/span&gt;  urlRerouteOnly: true,
});
&lt;span class="err"&gt;


&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you navigate to &lt;code&gt;http://localhost:9000/app1&lt;/code&gt; you'll see that it will only say &lt;code&gt;@ryank/app1&lt;/code&gt; is mounted. And your app routes are now properly separated.&lt;/p&gt;

&lt;p&gt;Just in case you don't see the apps. Make sure that both apps (app1 and root) are running before you navigate to the page&lt;/p&gt;

&lt;p&gt;Congrats !! You've setup Single-SPA and run it with your own app. Best way to get used to it now is to carry on your own side project and try implementing it again.&lt;/p&gt;

&lt;p&gt;Hopefully this article helped you out in setting up your single-spa project.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://single-spa.js.org/" rel="noopener noreferrer"&gt;single-spa.js&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>microfrontends</category>
      <category>singlespa</category>
      <category>react</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
