<?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: Per</title>
    <description>The latest articles on Forem by Per (@perborgen).</description>
    <link>https://forem.com/perborgen</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%2F1929%2Fimage.jpg</url>
      <title>Forem: Per</title>
      <link>https://forem.com/perborgen</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/perborgen"/>
    <language>en</language>
    <item>
      <title>Introducing Scrimba Fullstack</title>
      <dc:creator>Per</dc:creator>
      <pubDate>Fri, 11 Apr 2025 07:29:25 +0000</pubDate>
      <link>https://forem.com/scrimba/introducing-scrimba-fullstack-m5p</link>
      <guid>https://forem.com/scrimba/introducing-scrimba-fullstack-m5p</guid>
      <description>&lt;p&gt;Over the last few years, &lt;a href="https://scrimba.com" rel="noopener noreferrer"&gt;Scrimba&lt;/a&gt; has grown into a community of nearly two million learners focused on mastering frontend development. But there’s one question we've heard again and again: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"When will you offer backend courses?".&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This makes a lot of sense, as you need both backend and frontend in order to build fully functional apps. It also drastically improves your hireability if you understand the entire stack, as the job market has moved towards fullstack roles.&lt;/p&gt;

&lt;p&gt;So today, we’re happy to share that you can finally learn &lt;strong&gt;fullstack development&lt;/strong&gt; on our platform, with six free courses ready straight out of the gate. These cover subjects like Node.js, Express.js, Next.js, SQL, the command line, and more. &lt;/p&gt;

&lt;p&gt;Click &lt;a href="https://scrimba.com/t0fullstack" rel="noopener noreferrer"&gt;here&lt;/a&gt; to see all of them.&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%2Fxaz4n53rbyp419xeclpn.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%2Fxaz4n53rbyp419xeclpn.png" alt="The fullstack topic page on Scrimba" width="800" height="519"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These fullstack courses run entirely in the browser, meaning you don’t have to set up your dev environment locally, nor pay for credits on a remote container that runs the project for you. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You'll be able to jump seamlessly between the video and the IDE, as they have been fused into a unified learning experience.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/s0kmcarts1" rel="noopener noreferrer"&gt;Click here to watch a scrim&lt;/a&gt; that explains how it works in more detail.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/s0kmcarts1" rel="noopener noreferrer"&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%2Fhj6denrrq3f76zkzawyi.png" width="800" height="445"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How the fullstack support works under the hood
&lt;/h2&gt;

&lt;p&gt;To offer truly interactive fullstack learning experiences, we considered multiple approaches. Most in-browser code editors spin up remote server containers for backend code execution, but these can quickly become expensive, leading to limits on usage. In addition, network latency can be a drag on performance.&lt;/p&gt;

&lt;p&gt;Another possibility we explored was using building our own solution using &lt;a href="https://webassembly.org/" rel="noopener noreferrer"&gt;WebAssembly&lt;/a&gt;, which lets you run a range of programming languages within the browser. However, this would be huge undertaking for our development team, who have plenty of other important tasks to focus on.&lt;/p&gt;

&lt;p&gt;Luckily though, StackBlitz has done much of this heavylifting already, and launched it as a product called WebContainer. This allows complete Node.js environments to run directly in your browser, providing instant setup without installations, local configurations, or performance compromises. WebContainers is now fully integrated it into our scrims.&lt;/p&gt;

&lt;h2&gt;
  
  
  How we make the “videos” interactive
&lt;/h2&gt;

&lt;p&gt;Speaking of which, developers often ask how we’ve built the scrim format. So let’s have a look at that as well. &lt;/p&gt;

&lt;p&gt;The easiest way to describe it is that is a mix between the IDE and a video. &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%2Fj6ettpu8revy5y4khpm9.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%2Fj6ettpu8revy5y4khpm9.png" alt="Meme of how scrimba is a mix of VS Code and YouTube" width="800" height="601"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The main thing to understand about the scrim format is that is is event-based, as opposed videos, which are pixel-based. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;So whereas a 24 FPS (frames per second) video contains 24 images stacked on top of each other, a scrim instead records the underlying events, which could be “edit code”, “move cursor”, “open file”, or so forth.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here is a screenshot that visualizes the difference.&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%2Fj4cjrphlepepgi676aod.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%2Fj4cjrphlepepgi676aod.png" alt="Comparison between a video and a scrim" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you watch a scrim, we simply re-create these events in the IDE, while layering the audio from the teacher on top. Much of the complexity in Scrimba arises from having to apply these events in the correct order in the IDE, and thus creating a timeline that reliably can be scrubbed back and forth.&lt;/p&gt;

&lt;p&gt;These events are optimized like crazy, meaning they require little bandwidth to be streamed to your computer. Actually, a scrim usually weights 100 times less than its equivalent video.&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%2F7mbuavj01gpej1iuicgx.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%2F7mbuavj01gpej1iuicgx.png" alt="File size of a video versus a scrim" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Which courses are available?
&lt;/h2&gt;

&lt;p&gt;Our teachers have been working around the clock the last few months to ensure you can learn a range of full-stack technologies from the start, learning essential skills like building APIs, working with databases, controlling the terminal, and more. Here are the courses you can enroll into for free right away:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Learn Node.js&lt;/li&gt;
&lt;li&gt;Learn Express.js&lt;/li&gt;
&lt;li&gt;Learn Next.js&lt;/li&gt;
&lt;li&gt;Intro to SQL&lt;/li&gt;
&lt;li&gt;Command Line Basics&lt;/li&gt;
&lt;li&gt;Intro to Vite&lt;/li&gt;
&lt;li&gt;Intro to Supabase&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Several of the courses above have been created in collaboration with the library maintainers, giving us feedback on best-practices and common hurdles beginners feel when learning their stack. &lt;/p&gt;

&lt;p&gt;And in well-known Scrimba style, they all take full advance of the interactivity, giving you coding challenges around every corner. By the time you’d taken either of these courses, you’ll have written a lot of code in the given technology.&lt;/p&gt;

&lt;p&gt;And this is just the start. Over the coming months, we’ll release additional courses including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Intro to Nest.js&lt;/li&gt;
&lt;li&gt;Intro to Nuxt&lt;/li&gt;
&lt;li&gt;Intro to Vitest&lt;/li&gt;
&lt;li&gt;Learn Vue&lt;/li&gt;
&lt;li&gt;RAG &amp;amp; AI agents&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you have suggestions for a course you’d like us to create, or if you’re an open-source maintainer who’d like to see a course about your technology on Scrimba, please email me at &lt;a href="mailto:per@scrimba.com"&gt;per@scrimba.com&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Can I record my own scrims?
&lt;/h2&gt;

&lt;p&gt;Yes, you can! It’s quite simple, as everything is done in the browser, so you don't even have to download an app. Once a scrim has been recorded, it will be listed on your profile, or can be shared via a link.&lt;/p&gt;

&lt;p&gt;Most likely, you’ll have to edit your scrim a bit to cut away pauses, mistakes, and so forth. So we’ve create a simple editing interface as well.&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%2Fr98q0r78sby7a8px54tg.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%2Fr98q0r78sby7a8px54tg.png" alt="The timeline editing interface on Scrimba" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’re a teacher or developer looking to record content with &lt;br&gt;
Scrimba, please reach out!&lt;/p&gt;

&lt;h2&gt;
  
  
  Can I embed scrims into my website?
&lt;/h2&gt;

&lt;p&gt;Yes, you can do that! Several partners of ours are doing this, like MDN, Coursera, and freeCodeCamp. &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%2F5ftc16aq2e18erqyzl3c.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%2F5ftc16aq2e18erqyzl3c.png" alt="An embedded scrim on MDN" width="800" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It'll enable your users to get an unique and differentiated learning experience.&lt;/p&gt;

&lt;p&gt;When are actively looking for partnerships these days, and have an affiliate program where you’ll get a generous share of the revenue from any traffic your send us. This program has generated hundreds of thousands of dollars in revenue since we started ramping it up in the second half of 2024.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>node</category>
      <category>nextjs</category>
      <category>programming</category>
      <category>learning</category>
    </item>
    <item>
      <title>Learn JavaScript - A Free 7-hour Interactive Tutorial</title>
      <dc:creator>Per</dc:creator>
      <pubDate>Thu, 27 May 2021 15:15:47 +0000</pubDate>
      <link>https://forem.com/scrimba/learn-javascript-a-free-7-hour-interactive-tutorial-1ai2</link>
      <guid>https://forem.com/scrimba/learn-javascript-a-free-7-hour-interactive-tutorial-1ai2</guid>
      <description>&lt;p&gt;Over the last four months, I have recorded what is probably the most interactive &lt;a href="https://scrimba.com/learn/learnjavascript?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=learn_javascript_dev_to_article"&gt;JavaScript course&lt;/a&gt; that has ever been created.&lt;/p&gt;

&lt;p&gt;The reason I have done this is because I often see new coders fall into the same pitfalls again and again when trying to learn JavaScript, with the most dangerous ones being these three 👇&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Not being able to go from watching JS tutorials to building JS projects 🛠&lt;/li&gt;
&lt;li&gt;Losing motivation because they get bored 🥱&lt;/li&gt;
&lt;li&gt;Not being able to move forward because the learning curve is too steep 🧗&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, very few courses seem to take these pitfalls seriously enough. So this course is meant for anyone who has experienced any of the above issues when learning JavaScript.&lt;/p&gt;

&lt;p&gt;In this article, I'll explain how &lt;a href="https://scrimba.com/learn/learnjavascript?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=learn_javascript_dev_to_article"&gt;the course&lt;/a&gt; works so that you can decide whether or not you think it is something for you. &lt;/p&gt;

&lt;p&gt;If you you're sold already, just click on the image below 👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/learn/learnjavascript?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=learn_javascript_dev_to_article"&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%2Fuploads%2Farticles%2F69b2tq7lbxthhbs8t3ik.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Hyper Interactivity is Important
&lt;/h2&gt;

&lt;p&gt;The course is built around 140+ interactive challenges. This means that there's no point in binge-watching it. The whole purpose of it is to get you to code, to build up your JavaScript muscle memory. And in order to achieve that, you must solve the challenges.&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%2Fuploads%2Farticles%2Fx0fecsxhuavx1quuhxa8.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%2Fuploads%2Farticles%2Fx0fecsxhuavx1quuhxa8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Don't worry though – each challenge is byte-sized and fast to solve, so you will feel like you are progressing quickly.&lt;/p&gt;

&lt;p&gt;This level of interactivity would be clunky to achieve using regular videos, as you would need to jump between the video player and the code editor 140+ times throughout the course. Not to mention opening up new starter files for many of the challenges.&lt;/p&gt;

&lt;p&gt;To combat this issue, I created this course using Scrimba, which makes the experience much smoother.&lt;/p&gt;

&lt;p&gt;When you are inside a scrim, you can instantly jump between watching the teacher's explanation and coding up your own solution.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Imagine if VS Code and the video format had a child. That's Scrimba. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can both watch the tutorial and edit with the code inside the same frame.&lt;/p&gt;

&lt;p&gt;People often struggle to understand what a scrim is before they've seen it, so I'd recommend that you watch through &lt;a href="https://scrimba.com/scrim/c8gp4WfE" rel="noopener noreferrer"&gt;this 1-minute scrim&lt;/a&gt; to get ahold of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  "Just-in-time" Learning
&lt;/h2&gt;

&lt;p&gt;Another thing that separates this course from most other JavaScript courses is that it spreads the theoretical lessons evenly out across the entire course. Just in time when you need to learn it, and not a second before.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This means that you won't get long and boring lectures about abstract concepts before you start building projects.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Instead, we will dive head-first into building projects. And when we hit a road block, I will introduce you to the piece of theory we need in order to overcome it. This way, you will intuitively understand why you need to learn the theory.&lt;/p&gt;

&lt;p&gt;However, don't be fooled to think that we will skip any theory. My course goes through the same important theory as any other good JavaScript course. But instead of squeezing it in all up-front, it is spread out evenly from start to end. Just it time when you need to learn it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Learning by Doing
&lt;/h2&gt;

&lt;p&gt;This tight integration between theory and practice means that most of your time will be spend building products. Here are the three projects you will build:&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%2Fuploads%2Farticles%2Fd73d3z96lbut5pw72y6p.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%2Fuploads%2Farticles%2Fd73d3z96lbut5pw72y6p.png" alt="The projects you will build in the course"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Project 1: Passenger Counter
&lt;/h3&gt;

&lt;p&gt;You'll start out by building a passenger counter app. This might seem like a bit of a contrived example, but counting passengers at the metro was my actually my full-time job for a time when I was 19 years old.&lt;/p&gt;

&lt;p&gt;What's important here is that you are building an actual product from day one. You are combining JavaScript with HTML and CSS, so that you can learn JavaScript in the context of a real user interface in the browser.&lt;/p&gt;

&lt;p&gt;This makes it a lot more fun than simply seeing your output in the console. While this adds a little bit of complexity, it it well worth it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Project 2: Blackjack game
&lt;/h3&gt;

&lt;p&gt;Next, you will build your very first JavaScript game – Blackjack!&lt;/p&gt;

&lt;p&gt;This is the first time you will code something that can also entertain you, which I think is important.&lt;/p&gt;

&lt;p&gt;Blackjack is one of the most iconic Casino games ever, and this marks your first step into the world of game development.&lt;/p&gt;

&lt;h3&gt;
  
  
  Project 2: Chrome Extension
&lt;/h3&gt;

&lt;p&gt;Finally, you will build a Chrome Extension that we are going deploy to your Chrome browser, so that you can use it out in the wild. This is exciting, as you'll really understand the super power you have gotten at this point.&lt;/p&gt;

&lt;p&gt;The extension is called "Lead Tracker" and it is a tool for sales representatives. It allows them to browse the web and collect promising leads.&lt;/p&gt;

&lt;p&gt;Check out the intro scrim for it to learn it a bit more:&lt;/p&gt;

&lt;h3&gt;
  
  
  Practice sections
&lt;/h3&gt;

&lt;p&gt;After each of these project sections, I will stress-test your knowledge with dedicated challenge sections. This will also give you the necessary repetition you need in order to progress to the next project. I have tried to make all the challenges as real-world as possible so that they are fun to solve.&lt;/p&gt;

&lt;p&gt;If you struggle to solve these challenges, then I would recommend that you revisit the scrims from the project sections as well. So these sections serve as gateways for progressing with the course.&lt;/p&gt;

&lt;h3&gt;
  
  
  You can enroll for free right now
&lt;/h3&gt;

&lt;p&gt;I hope this gave you the background you needed in order to decide whether or not you'd like to try this course out. It's 100% free, and will be so forever. If you are interested, just &lt;a href="https://scrimba.com/learn/learnjavascript?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=learn_javascript_dev_to_article"&gt;click this link&lt;/a&gt; and you can get started immediately.&lt;/p&gt;

&lt;p&gt;Finally, if you would like to help us spread the course, you can retweet my launch tweet. &lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1395359456335106048-220" src="https://platform.twitter.com/embed/Tweet.html?id=1395359456335106048"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1395359456335106048-220');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1395359456335106048&amp;amp;theme=dark"
  }



&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>css</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>It's the first day of Scrimba's #JavaScriptmas Advent Calendar! 🎄 Let's take a look at challenge number 1. 🎅🏻</title>
      <dc:creator>Per</dc:creator>
      <pubDate>Tue, 01 Dec 2020 16:48:37 +0000</pubDate>
      <link>https://forem.com/scrimba/it-s-the-first-day-of-scrimba-s-javascriptmas-advent-calendar-let-s-take-a-look-at-challenge-number-1-n3f</link>
      <guid>https://forem.com/scrimba/it-s-the-first-day-of-scrimba-s-javascriptmas-advent-calendar-let-s-take-a-look-at-challenge-number-1-n3f</guid>
      <description>&lt;p&gt;If you haven't already heard, Scrimba has launched &lt;a href="https://scrimba.com/learn/adventcalendar?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gadventcalendar_day1_article"&gt;&lt;strong&gt;24 Days of #JavaScriptmas&lt;/strong&gt;&lt;/a&gt; - an "advent calendar" of code challenges which gives you the chance to put your coding skills to the test and win prizes every day until Christmas Eve!&lt;/p&gt;

&lt;p&gt;The #JavaScriptmas challenges have been created by Scrimba's popular teacher, Dylan 'Claus' Israel. You might know Dylan from his YouTube channel CodingTutorials360, but what you probably didn't know is that he moves to the North Pole every December and takes on a completely different job...creating advent calendars for code enthusiasts like you! 🎅🏻 &lt;/p&gt;

&lt;p&gt;The #JavaScriptmas calendar contains challenges of increasing difficulty, so if you take part, you'll give yourself a good chance of becoming a Javascript maestro in time for Christmas!&lt;/p&gt;

&lt;h2&gt;
  
  
  Time for the challenge!
&lt;/h2&gt;

&lt;p&gt;Now let's take a look at the very first coding conundrum, a task all about dividing candies equally, which could come in handy over the holidays!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/learn/adventcalendar/-javascript-challenge-candies-introduction-cLkqvpcQ?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gadventcalendar_day1_article"&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%2F44re6i1o5t7euq5jh5zv.png" alt="description of candies challenge"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Click the image to access the challenge.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Some skeleton code is provided in the screencast, so it's super easy to get started:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;candies&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;candy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//  write code here.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As it's the season for giving, Dylan also spoils us with a handy hint to help us along the way, and that is to consider using &lt;code&gt;Math.floor()&lt;/code&gt;. However, this is a recommendation and not a requirement. If you come up with a different solution, by all means share it with the community. &lt;/p&gt;

&lt;p&gt;Speaking of sharing with the community, that's exactly what you should do if you'd like to be in with a chance of bagging one of the daily prizes. Simply share your solution on Twitter with the #JavaScriptmas hashtag and you'll automatically be entered into Scrimba's prize draw. Better still, Scrimba has installed a 'Share Your Solution' button into every challenge to take the leg-work out of Tweet-writing.&lt;/p&gt;

&lt;p&gt;If you haven't signed up to the advent calendar yet, it's not too late! Head over to &lt;a href="https://scrimba.com/learn/adventcalendar?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gadventcalendar_day1_article"&gt;the 24 Days of #JavaScriptmas&lt;/a&gt; page and hit enrol - you'll then receive each day's challenge directly to your email inbox every day until Christmas Eve!&lt;/p&gt;

&lt;p&gt;Merry challenging! 🎄&lt;/p&gt;

</description>
      <category>scrimba</category>
      <category>javascript</category>
    </item>
    <item>
      <title>A Free Advent Calendar To Sharpen Your JavaScript Skills And Win Daily Prizes 🎁</title>
      <dc:creator>Per</dc:creator>
      <pubDate>Tue, 01 Dec 2020 06:05:24 +0000</pubDate>
      <link>https://forem.com/scrimba/an-advent-calendar-to-level-up-your-javascript-skills-c42</link>
      <guid>https://forem.com/scrimba/an-advent-calendar-to-level-up-your-javascript-skills-c42</guid>
      <description>&lt;p&gt;&lt;strong&gt;Welcome to &lt;a href="https://scrimba.com/learn/adventcalendar?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=dev_to_launch_article"&gt;24 Days of #JavaScriptmas&lt;/a&gt;, a fun-packed advent calendar that gives you the chance to win daily prizes while sharpening your JavaScript skills.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How does #JavaScriptmas work?
&lt;/h2&gt;

&lt;p&gt;Each day from today until December 24th, we'll release a brand-new challenge for you to solve. To join, simply head to the &lt;a href="https://scrimba.com/learn/adventcalendar?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=dev_to_launch_article"&gt;24 days of #JavaScriptmas page&lt;/a&gt; (👈link🔗) and enroll right now. You'll receive a daily email notifying you of the latest challenge, plus the previous day's solution.&lt;/p&gt;

&lt;p&gt;The challenges come in the form of interactive screencasts. So you don't have to read a tons of instructions to understand them. Just watch a one-minute screencast and start coding your solution directly inside the &lt;em&gt;scrim&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What can I win? 🎁
&lt;/h2&gt;

&lt;p&gt;Santa will reach into his sack and give out a year of free Scrimba Pro (worth $150) to one lucky winner every single day until December 23rd.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;On Christmas Eve, we'll select a winner who gets Scrimba Pro for life plus 1000 USD in cash💰&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To learn more about the prizes and the competition, check out our launch video:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/CsoujaMhl4g"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  What level are the challenges? 📊
&lt;/h2&gt;

&lt;p&gt;The challenges start off easy and become harder as the month goes on. If you stick at it, you'll be a JavaScript master in time for Christmas!&lt;/p&gt;

&lt;p&gt;With 24 days to fill, there will be plenty of topics covered, including Math.floor(), slice(), sort(), every(), split(), push(), Math.pow() and many more.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I'd recommend you to start on Day 1 and see how long you can keep up. This is a great way of challenging yourself.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  How do I enter the competition?
&lt;/h2&gt;

&lt;p&gt;Once you've completed your daily challenge, just tweet a link to your solution with the &lt;strong&gt;#JavaScriptmas&lt;/strong&gt; hashtag. That's all there is to it!&lt;/p&gt;

&lt;p&gt;We will pick the winners randomly,  as we want everyone to have a chance at winning prizes. Plus, we don't want you to compete with other participants. We want you to compete against yourself. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The point with this calendar is to kick-start the year of 2021 with strong JavaScript skills, as that's the best way to future-proof your career.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  How do I maximize my chances of winning? 🏆
&lt;/h2&gt;

&lt;p&gt;You maximize your chance of winning by submitting a solution on Twitter every single day.  This will give you 23 shots at winning a daily prize (annual Scrimba Pro membership). &lt;/p&gt;

&lt;p&gt;This will also maximize your chance of winning the Grand Prize ($1000 and a lifetime Scrimba membership), as every solution you have submitted counts as a "lottery ticket" towards the Grand Prize.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who has created the challenges?
&lt;/h2&gt;

&lt;p&gt;All the challenges have been created by Dylan Israel. He runs the popular CodingTutorials360 channel over at YouTube, so you might already know Dylan.&lt;/p&gt;

&lt;p&gt;But what you probably didn't know is that Dylan takes on a completely different job at the end of each year, as proven by the picture 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%2Fkd97nh6a4ujphrj9dzm3.jpg" 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%2Fkd97nh6a4ujphrj9dzm3.jpg" alt="Dylan "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Best of luck, and Merry JavaScriptmas! 🎅🏻&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>100daysofcode</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Proven advice to secure your first developer job</title>
      <dc:creator>Per</dc:creator>
      <pubDate>Fri, 30 Oct 2020 10:21:48 +0000</pubDate>
      <link>https://forem.com/scrimba/proven-advice-to-secure-your-first-developer-job-548i</link>
      <guid>https://forem.com/scrimba/proven-advice-to-secure-your-first-developer-job-548i</guid>
      <description>&lt;p&gt;Meet &lt;strong&gt;Austėja Kazlauskytė&lt;/strong&gt; :&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%2Fl96vyu0v49wvzkt73k3b.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%2Fl96vyu0v49wvzkt73k3b.png" alt="austeja"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Austėja is a new mom, law graduate, and “mom-and-pop” entrepreneur turned full-time frontend developer 🎉 &lt;/p&gt;

&lt;p&gt;She managed to get a job despite soul-crushing odds👇&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;No formal education&lt;/li&gt;
&lt;li&gt;No professional coding experience&lt;/li&gt;
&lt;li&gt;No portfolio &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And as if that wasn't enough, she was also raising a child &lt;em&gt;and&lt;/em&gt; facing a worldwide pandemic this whole time 😱&lt;/p&gt;

&lt;p&gt;So in this article - and corresponding podcast episode - you will learn how she conquered her fears, took risks, and learned to navigate JavaScript, CSS, React, and eventually nailed the dreaded technical interview.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you'll learn 👨‍🏫
&lt;/h2&gt;

&lt;p&gt;Here are some of the specific takeaways you'll have from her story:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Transitioning careers (law 👉 entrepreneurship 👉 coding)&lt;/li&gt;
&lt;li&gt;Making time to learn to code as a new mom 👶🏻&lt;/li&gt;
&lt;li&gt;A winning job-hunting strategy you can copy 🎉&lt;/li&gt;
&lt;li&gt;Motivation and drive during a pandemic 🦠&lt;/li&gt;
&lt;li&gt;Smashing the technical interview 👊&lt;/li&gt;
&lt;li&gt;Salary negotiation  💸&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Podcast links 🎧
&lt;/h2&gt;

&lt;p&gt;If you'd like to bring this story with you as you commute, clean your house, or whatever you prefer, just click on one of the links below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://open.spotify.com/episode/6d3HpvCerPyfe51YwRG3L6?si=2kzKKYgWTe-Oh8KUAGCtiw" rel="noopener noreferrer"&gt;Listen on Spotify&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://podcasts.apple.com/gb/podcast/aust%C4%97ja-kazlauskyt%C4%97/id1537632252?i=1000496253066" rel="noopener noreferrer"&gt;Listen on Apple Podcasts&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Interview 👇
&lt;/h2&gt;

&lt;p&gt;If you prefer reading over listening, we have extracted some of the most interesting parts of the interview below. However, if you like this read, I'd recommend you to also listed to the podcast, as you'll get a more in-depth.&lt;/p&gt;

&lt;p&gt;And if you'd like to try the online course Austeja used to ramp up her skills, you can check out Scrimba &lt;a href="https://scrimba.com/learn/frontend?utm_source=dev.to&amp;amp;utm_medium=body&amp;amp;utm_campaign=austeja-interview"&gt;Frontend Developer Career Path.&lt;/a&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;em&gt;Welcome to #StoriesByScrimba, Austėja! Could you start by telling us about your background?&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;Sure 😀&lt;/p&gt;

&lt;p&gt;I didn't know what I wanted to do when I was 18. I was good with languages and history and - to be honest - not so good with math. Since my parents worked in pharmacy, they told me it's law or medicine, you know? I chose law.&lt;/p&gt;

&lt;p&gt;I did 5 years in law school. I have masters in legal philosophy, and have a little bit of legal experience working with IT law! But I never really enjoyed it 😔  I thought it was so boring. So when I could, I switched to events, then sales, and this is what I did for work after graduation.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Then I married and had a baby 👶🏻  and then - you know - many questions arose around what I want to do in my life because I had time, and I felt I wasn't professionally fulfilled.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After seeing many positive examples of my friends who transitioned from law to testing and development, I chose a testing at first but shortly after, I decided that I wanted to be a developer and I took a full-stack Java course and that I took the Scrimba &lt;a href="https://scrimba.com/learn/frontend?utm_source=dev.to&amp;amp;utm_medium=body&amp;amp;utm_campaign=austeja-interview"&gt;Frontend Developer Career Path.&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I started in September 2019. Today is October 2020. And now I work at a company called DevBridge which was my really dream career choice. It's one of the best companies in Poland and Lithuania.&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%2F2wyo708ehi5box44hs5f.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%2F2wyo708ehi5box44hs5f.png" alt="timeline"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;When they chose me, I thought it must be something magical ✨ But the technical interview went well. Scrimba helped me a lot there. I'm in my third week right now and my job title is full-stack Junior Software Engineer.&lt;/p&gt;

&lt;p&gt;You mentioned you took a Java bootcamp before Scrimba. How did you decide where to begin?&lt;/p&gt;

&lt;p&gt;I didn't have any contacts in coding. I didn't have engineer friends who could be my mentors so I Googled the web. Eventually, I found a few schools on-site.&lt;/p&gt;

&lt;p&gt;I was so scared of online courses. I thought it was only on-site things that would teach you effectively. I was wrong.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I went to the full-stack Java course. When I signed up, I didn't know what Java was, to be honest 😂&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I thought Java was a good choice because it was a very popular. I Googled it well.&lt;/p&gt;

&lt;p&gt;The on-site Java course was ~7 months every weekend - like a course. You go to a classroom with 10 other classmates and there was a teacher and you do the tasks. In the end, you have a project which involves basic CRUD operations (&lt;em&gt;EDITOR NOTE: CRUD is an acronym for Create, Read, Update, Delete - four common database operations you must eventually learn&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;When I was learning Java, I decided those courses were not enough for me to learn to code so I did a little course on CodeGym.cc - they have really good software for Java.&lt;/p&gt;

&lt;p&gt;Eventually, I realised I want to be a really good frontend developer. So I enrolled in Scrimba's &lt;a href="https://scrimba.com/learn/frontend?utm_source=dev.to&amp;amp;utm_medium=body&amp;amp;utm_campaign=austeja-interview"&gt;Frontend Developer Career Path.&lt;/a&gt; 🙌&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%2Fd98gjqg1pnn1nidgzsfp.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%2Fd98gjqg1pnn1nidgzsfp.png" alt="Screenshot 2020-10-30 at 10.09.33"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;What would you say to someone who's deciding between frontend or backend development?&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;I think it doesn't matter because the main struggle I  face every day is how to think like a programmer. Syntax doesn't matter.&lt;/p&gt;

&lt;p&gt;I could easily switch to C# (&lt;em&gt;EDITOR NOTE: C# is a programming language by Microsoft&lt;/em&gt;) one day because if you know how to think like a programmer, you can Google out new syntax fast but it's very hard to Google out logic.&lt;/p&gt;

&lt;p&gt;My approach and my tips - and my tips for myself because I'm just starting - would be to concentrate on learning logic. Syntax doesn't matter. You can switch languages fast. And if, for example, you work for an agency like DevBridge you get a client that wants, for example, backend in PHP and frontend in JavaScript... It would be terrible for you to say "I'm not going to learn PHP because I'm a JavaScript developer 😭"&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Language doesn't matter. What matters is that you want to learn to think like an engineer and an engineer likes to play with things, mess with things and learn new concepts.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Remember, React didn't exist 10 years ago. Angular angler didn't exist 10 years ago either! So what will happen in five years?&lt;/p&gt;

&lt;h3&gt;
  
  
  When you decided to learn to code, could you study all day? Maybe your other obligations meant you had to learn on the side.
&lt;/h3&gt;

&lt;p&gt;I couldn't actually.&lt;/p&gt;

&lt;p&gt;I was running a little business, but my main focus was my baby 👶🏻. So I was like a full time mom who has like a little business to keep my mind sane.&lt;/p&gt;

&lt;p&gt;I remember the things that I bought my baby - I bought a new tricycle that I can navigate with one hand because with my other hand, I was holding my phone and I was reading about Java. It was that extreme 😱&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You know, when we're out in the park, I'm always coding. When baby naps, I'm always coding. Late nights, I'm always coding.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If I cannot code late at night, I would wake up at 5.00AM or 4.30AM and I would go 'til 6.00AM because that was the only free time I had.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;You must have been very driven. What motivated you?&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;I thought that it was something I could feel good about myself - that I could establish my roots as a professional because when I was in my twenties, I didn't know what I wanted to do. I was pushed towards law because I was good with languages.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What I later realised is that IT is closer to languages than it is to maths or physics. I feel like a linguist, you know? To me, Java/JavaScript feels like English/French.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I feel like I am grounded in my professional roots and that I'm expressing myself as a professional because other parts of my life are well done. I have a family -I'm really happy 😀! But professionally, I didn't know what I wanted to do until I started to code.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;From law, to motherhood, to your own business, now code. You're a lifelong learner. Did you have an idea about the way to learn that was most efficient for you?&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;No, it was so completely different when I was learning law.&lt;/p&gt;

&lt;p&gt;In law, I was learning from theory or in discussion mode. For me, coding is closer to fixing the car, sewing, or making something out of clay!&lt;/p&gt;

&lt;p&gt;I think that for learning to code, the most important thing is mentorship. That personal mentor doesn't have to be on-site.&lt;/p&gt;

&lt;p&gt;My biggest mistake was that I chose on-site courses that were really, really, really expensive and not much of use. I think you'll learn more from Scrimba or online coaching.&lt;/p&gt;

&lt;p&gt;On-site courses take a lot, a lot of your time. You are expected to work in the group, but people come from different backgrounds and different motivation.&lt;/p&gt;

&lt;p&gt;If I could start everything from scratch, I wouldn't go to on-site courses. I would take online courses and I would look for online mentors.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Take online courses, never go to university - I would never think of going to informatics and pursuing another master's degree or something. That's totally a waste of time.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;We remember when you were participating in the &lt;a href="https://scrimba.com/learn/frontend?utm_source=dev.to&amp;amp;utm_medium=body&amp;amp;utm_campaign=austeja-interview"&gt;Frontend Developer Career Path&lt;/a&gt; you joined a study group on Discord and frequently helped others.&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;I was consciously taking other people's problems to solve on my own because what I lacked was experience. And if somebody asks me, "how would you make this logo fit in something?" I say, "okay, let me think about that". So I would take my time, Googling about that, coming up with a solution and presenting them to people.&lt;/p&gt;

&lt;p&gt;Being completely honest with you, it's not about helping them, but it was how I gathered my experience.&lt;/p&gt;

&lt;p&gt;When I was participating in my technical interview, I had more stories to tell. Interviewers are interested about stories and about the challenges you've faced and solved. I made an impression that I'd solved more problems than I have for my own projects.&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%2Fihbwe5es8yuk1d4azfsm.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%2Fihbwe5es8yuk1d4azfsm.png" alt="Screenshot 2020-10-30 at 10.43.22"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;When did you know you were ready to start applying for jobs?&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;I wasn't ready.... And many times during my day, I'm not feeling ready 😂&lt;/p&gt;

&lt;p&gt;I was referred by one of my teachers and someone else from DevBridge. The call from the company was a little bit unexpected because I was thinking of joining their academy that is happening this fall and winter to be "more ready". As it  happened, I was referred earlier, before the academy.&lt;/p&gt;

&lt;p&gt;I didn't have a chance to think of "being ready" or not being ready. But yeah, many times throughout the day when I am facing tough tasks, I question myself, "am I ready to work here?" And the answer is "no never ready" - still working on it!&lt;/p&gt;

&lt;p&gt;I think that for many people, it might sound like a miracle and sometimes it sounds like a miracle for me, myself. But I did lots of research and homework. I Googled a lot about the company, I attended the open day events the company hosted. I prepared a lot - for almost 6 months, I was gathering information about this company and about 2 more companies - they were my plan B and plan C. I was actively researching and trying to understand what technology stack the companies are using when they are hiring (because some companies hire in January or do massive hires or in summer, for example).&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;When you received the call, were they inviting you to interview?&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;They invited me to HR inter interview with the HR partner and the squad lead.&lt;/p&gt;

&lt;p&gt;We talked about why I wanted to be a programmer and my background. They asked me what tasks have I solved before. It was very soft. It was a mild interview, not a technical interview. And then a week later, they invited me for the technical interview that was conducted by 2 developers 🎉&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Would you tell us the story about that day? I bet it was exciting and nerve-racking 😬 How long did it take? What did they ask you? What was the process like?&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;The process was... All the interviews were conducted online through Zoom because of COVID 🦠. They didn't want to perform interviews on-site.&lt;/p&gt;

&lt;p&gt;I was nervous and the worst part: the interview was scheduled for 3:00 PM so I had the whole day to feel nervous 😬. If the interview was at 9.00 AM, you just get up and you do it 😂.  I was nervous throughout the whole day and the week before because there were 7 days between the soft and technical interview.&lt;/p&gt;

&lt;p&gt;During those 7 days, I was studying like mad! That week reminded me of the weeks before legal exams when you don't count the pages you have to read, but you count the centimeters, you know, the inches of the papers!&lt;/p&gt;

&lt;p&gt;I Googled out maybe 200, maybe more interview questions for frontend developers from junior to senior level.&lt;/p&gt;

&lt;p&gt;I Googled out the answers from various places. I rehearsed myself explaining the concepts - like explaining BEM (&lt;em&gt;EDITOR NOTE: BEM is an acronym for Block, Element, Modifier and is an advanced naming convention for classes in HTML and CSS&lt;/em&gt;). I practiced explaining  CSS - what a selector does, how preprocessors work, and more.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Of those 200 interview questions you practiced, how many came up?&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;All of them. Not 200! But all the questions that I received, I was more or less familiar with.&lt;/p&gt;

&lt;p&gt;Many concepts I couldn't explain thoroughly because I didn't have any hands-on experience but I knew it from theory.&lt;/p&gt;

&lt;p&gt;There wasn't a question that I couldn't say a sentence about. There were some questions I could talk about for 10 minutes (I didn't have that much time 😂) but for other questions, I could only talk a little - I could explain the concepts in like 2 or 3 sentences, but I was showing that I can understand what they're asking me. What, in general, the concept is, but how many questions in numbers? I don't remember, but the interview lasted for about an hour.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Sounds like you prepared really well. You must have been feeling pretty confident, right 😏?&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;No, I thought they wouldn't take me!&lt;/p&gt;

&lt;p&gt;I was expecting that DevBridge would instead invite me to join the academy because I know that they don't typically hire juniors without experience unless they finish that  of 3-4 months. In the academy, they teach you the stack and they evaluate if you can work in a large team because the projects this company is working on are HUGE.&lt;/p&gt;

&lt;p&gt;I thought that they wouldn't hire me. I thought they would offer me to, to take part in the internship courses (the academy).&lt;/p&gt;

&lt;p&gt;But they did hire you! How did they present the job offer to you?&lt;/p&gt;

&lt;p&gt;The interview was Friday at 3:00 PM and the squad leader called me Monday during the first part of the day. I only had to wait for a couple of days 😌&lt;/p&gt;

&lt;p&gt;They said that it's normal to be contacted in 2 weeks so I was expecting that I will have like 2 weeks of  doing Scrimba 😂, But they called me earlier. I was really, really happy about that. And the onboarding process was really quick, really fast. They  know what they're doing. They have systems. So far, it's been very smooth.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Did you attempt to negotiate your salary?&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;I received such a good offer that went beyond my financial expectations for a Junior Software Engineer  and so I was just like.. "okay 🙌!!". I didn't negotiate.&lt;/p&gt;

&lt;p&gt;I was out of my mind! And I am aware of the benefits system here - it is very transparent.&lt;/p&gt;

&lt;p&gt;Once I can be confident about my performance and see that I'm bringing value to the company.... Because right now I'm in a position to learn from other colleagues and I understand how much time are they spending on me - explaining the concepts, how the projects are structured... I know that I will have to negotiate one day, but one step at a time.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Well, when you're the lead developer in a few months (or even sooner) we can chat about it then 😉 What was your first day at DevBridge like? Were you excited?&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;Oh, yes! I was excited 🎉!&lt;/p&gt;

&lt;p&gt;It was so very well organized. It was me and 2 other people who were joining the company that same day. So we had a tour in the office and we both received a  T-shirt and backpack with cool stuff inside.&lt;/p&gt;

&lt;p&gt;We were taught how to set up the computer. We received clear instructions via email about how to do that. And I just started setting up and my new colleagues helped me out. It was really stress-free and everyone was unintrusive. They gave me time to unpack then little by little, they came in to ask about me, to talk about me. They asked me out for lunch, we had coffee with new people, so it was smooth, but it was intense! I didn't have time to check my phone or something.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;To close us out, can you summarise why you succeeded?&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;I was thinking about that myself because I received many positive messages.  I think it's related to that Scrimba posted something about me and people were asking me, "how did you get a job?" It made me think myself...&lt;/p&gt;

&lt;p&gt;I think that it was the preparation and the efforts I put forth. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I wasn't only learning to code, but I tried to get familiar with the industry, find friends in the tech world, attend the events, read the blogs, follow the bloggers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I tried to understand the technology world and the rules of this new game I'm entering.&lt;/p&gt;

&lt;p&gt;I worked a little bit with myself with marketing.  I had a LinkedIn page that was always up to date. I optimised my LinkedIn for SEO so that the HR team could find me more easily - this is what they did I was thinking "if nobody could find me, I will never be offered anything", so I worked on that.&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%2Ffpl8oaodpelt0xuzq1w0.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%2Ffpl8oaodpelt0xuzq1w0.png" alt="austeja linkedin"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Also, learning every day. I used to code every day. I still code every day, no matter if I'm tired or if it's a bad day. Every day, I open my laptop. Sometimes for five minutes, sometimes five hours, but it has to be every day.&lt;/p&gt;




&lt;p&gt;I hope you enojoyed the read! 😁 &lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>beginners</category>
      <category>career</category>
      <category>motivation</category>
    </item>
    <item>
      <title>Learn Svelte in 5 Minutes</title>
      <dc:creator>Per</dc:creator>
      <pubDate>Thu, 18 Jun 2020 13:38:35 +0000</pubDate>
      <link>https://forem.com/scrimba/learn-svelte-in-5-minutes-53i4</link>
      <guid>https://forem.com/scrimba/learn-svelte-in-5-minutes-53i4</guid>
      <description>&lt;p&gt;This article gives you a lightning-speed overview of Svelte - a Javascript framework which lets you write less code, uses no virtual DOM and create truly reactive apps.&lt;/p&gt;

&lt;p&gt;As if that's not enough, Svelte is super-intuitive too! Built with developers in mind, it is designed to make coding easier, bug-squashing quicker and a developer's work-life generally happier. If that sounds right up your street, then read on!&lt;/p&gt;

&lt;p&gt;While 5 minutes won't be enough to teach you Svelte in-depth, it does allow for a solid overview of the basics, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Components&lt;/li&gt;
&lt;li&gt;Importing and Exporting&lt;/li&gt;
&lt;li&gt;Templating&lt;/li&gt;
&lt;li&gt;Event handling&lt;/li&gt;
&lt;li&gt;Event dispatching&lt;/li&gt;
&lt;li&gt;Reactivity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to find out more about Svelte after reading this article, check out &lt;a href="https://scrimba.com/course/glearnsvelte?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=glearnsvelte_5_minute_article"&gt;the full course&lt;/a&gt; over on Scrimba. There, you'll learn about even more Svelte features and have the chance to road test your new skills with a bunch of interactive challenges.&lt;/p&gt;

&lt;p&gt;For now, let's get started on the basics!&lt;/p&gt;

&lt;h2&gt;
  
  
  Components
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pG6X6UG/cNDg9yHB?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=glearnsvelte_5_minute_article"&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%2Fe8ej7929dpa3u9tzsm0u.png" alt="DOM displaying Svelte component"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;(Click the image to access the course.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;First, we'll take a look at how to build a Svelte component, which can contain three parts; &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt;, which contains Javascript, &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt;, which contains CSS and the HTML, which uses the JS from the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;say&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hi&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/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="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;red&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;/style&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;Say&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;say&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The bare minimum needed for a Svelte component is the HTML, so the app will still work without the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tags.&lt;/p&gt;

&lt;h2&gt;
  
  
  Importing and Exporting
&lt;/h2&gt;

&lt;p&gt;One big benefit of using frameworks is the ability to modularise code by splitting it into separate components. Components are then imported into the main app using &lt;code&gt;import&lt;/code&gt; keyword:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Face&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;./Face.svelte&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unlike with other frameworks, the &lt;code&gt;export&lt;/code&gt; keyword is not required to use a component elsewhere in an app. Instead, it is used to pass parameters, or props, from parent elements to their children.&lt;/p&gt;

&lt;p&gt;For example, we can set a size prop with a default size in our component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;size&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="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="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;font-size: {size}em&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allows us to easily adjust the size of the imported component over in our &lt;code&gt;App.svelte&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Face&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;./Face.svelte&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/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="nx"&gt;Face&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;4&lt;/span&gt;&lt;span class="dl"&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;Face&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10&lt;/span&gt;&lt;span class="dl"&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;Face&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;The various sizes appear on the DOM as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pG6X6UG/cbDNVncg?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=glearnsvelte_5_minute_article"&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%2F3aecnw1qq3xpcck19agr.png" alt="component imported with various sizes using props"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;(Click the image to access the course.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Head over to &lt;a href="https://scrimba.com/p/pG6X6UG/cbDNVncg?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=glearnsvelte_5_minute_article"&gt;the course on Scrimba&lt;/a&gt; to view and play around with the full code.&lt;/p&gt;
&lt;h2&gt;
  
  
  Templating
&lt;/h2&gt;

&lt;p&gt;The Svelte &lt;a href="https://scrimba.com/p/pG6X6UG/cMZrQds2?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=glearnsvelte_5_minute_article"&gt;templating syntax&lt;/a&gt; is a great feature which lets us add if statements and for loops to our HTML.&lt;/p&gt;

&lt;p&gt;The syntax for an if statement looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Container&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nx"&gt;say&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nx"&gt;Hi&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sr"&gt;/if&lt;/span&gt;&lt;span class="err"&gt;}
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Container&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;While a for loop is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;each&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&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="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;faceIndex&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Face&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;faceIndex&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sr"&gt;/each&lt;/span&gt;&lt;span class="err"&gt;}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Event handling
&lt;/h2&gt;

&lt;p&gt;To allow the user to interact with our app, we need event handlers. In &lt;a href="https://scrimba.com/p/pG6X6UG/caZ3J6U3?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=glearnsvelte_5_minute_article"&gt;this scrim&lt;/a&gt;, we see how to add a simple &lt;code&gt;on:click&lt;/code&gt; to a &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; to show our app's header:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;
    &lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;click&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;showHeader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&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="nx"&gt;show&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And what a header it is..!&lt;br&gt;
&lt;a href="https://scrimba.com/p/pG6X6UG/caZ3J6U3?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=glearnsvelte_5_minute_article"&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%2Fczgdba1dpkzu552kq2hq.png" alt="header made visible on the DOM with an event handler"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;(Click the image to access the course.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There is a gotcha with this, though - it only works with the native HTML &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; tag and not imported components called &lt;code&gt;&amp;lt;Button&amp;gt;&lt;/code&gt;. Luckily, we can work around this by using &lt;strong&gt;event forwarding&lt;/strong&gt;, i.e. adding an &lt;code&gt;on:click&lt;/code&gt; to the native &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; tag in its component file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;click&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;slot&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/slot&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Event dispatching
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pG6X6UG/cD4bKDuD?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=glearnsvelte_5_minute_article"&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%2Fw203a2wxgn1brk5ss6i4.png" alt="Hide and show buttons created with event dispatcher"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;(Click the image to access the course.)&lt;/em&gt;&lt;br&gt;
Event dispatching is a great feature of Svelte which increases code usability by allowing us to use the same element for more than one action.&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://scrimba.com/p/pG6X6UG/cD4bKDuD?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=glearnsvelte_5_minute_article"&gt;this scrim&lt;/a&gt;, we learn how to use one &lt;code&gt;&amp;lt;Button&amp;gt;&lt;/code&gt; component to both show and hide an element.&lt;/p&gt;

&lt;p&gt;We create an event dispatcher in the &lt;code&gt;&amp;lt;Button&amp;gt;&lt;/code&gt; component file like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;createEventDispatcher&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;svelte&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dispatch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="nf"&gt;createEventDispatcher&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;We then add the dispatcher to our native HTML &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;click&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;show&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;Show&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;click&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hide&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;Hide&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lastly, we declare the button's functionality options in the &lt;code&gt;App.svelte&lt;/code&gt; file as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Buttons&lt;/span&gt;
    &lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;show&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;showHeader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}}&lt;/span&gt;
    &lt;span class="nl"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;hide&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;showHeader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}}&lt;/span&gt;
&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can refactor this by passing values up through the dispatch using the event variable (&lt;code&gt;e&lt;/code&gt;). In this case, the &lt;code&gt;&amp;lt;Button&amp;gt;&lt;/code&gt; in our &lt;code&gt;App.svelte&lt;/code&gt; file looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Buttons&lt;/span&gt;
    &lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;click&lt;/span&gt;&lt;span class="o"&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="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;showHeader&lt;/span&gt; &lt;span class="o"&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;detail&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}}&lt;/span&gt;
&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While the native HTML &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt;s in our component file look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;click&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&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;Show&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;click&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&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;Hide&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reactivity
&lt;/h2&gt;

&lt;p&gt;If you want a piece of code to rerun every time its associated variable is updated, then Svelte's unique feature, &lt;a href="https://scrimba.com/p/pG6X6UG/caZ3yBAB?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=glearnsvelte_5_minute_article"&gt;the reactive statement&lt;/a&gt;, is for you. We declare a reactive statement with &lt;code&gt;$:&lt;/code&gt; as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;score&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="nl"&gt;$&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;smileySays&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi there, your score is: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's also possible to run if statements inside reactive statements. The code to do so looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;score&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="nl"&gt;$&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;smileySays&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi there, your score is: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;$&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;smileySays&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Wow your score is low!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's about all the features we can cram into our 5-minute tour of Svelte. I hope you found it useful and are inspired to try out the framework for yourself and test your new-found skills. Don't forget to check out the full course &lt;a href="https://scrimba.com/course/glearnsvelte?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=glearnsvelte_5_minute_article"&gt;over at Scrimba&lt;/a&gt; to find out about even more Svelte features and give the coding challenges a try.&lt;/p&gt;

&lt;p&gt;Wherever your coding journey takes you next, happy learning :)&lt;/p&gt;

</description>
      <category>svelte</category>
      <category>scrimba</category>
    </item>
    <item>
      <title>The Working Developer's Guide To Algorithms</title>
      <dc:creator>Per</dc:creator>
      <pubDate>Mon, 15 Jun 2020 09:45:06 +0000</pubDate>
      <link>https://forem.com/scrimba/the-working-developer-s-guide-to-algorithms-4327</link>
      <guid>https://forem.com/scrimba/the-working-developer-s-guide-to-algorithms-4327</guid>
      <description>&lt;p&gt;If you're looking to gain new problem-solving skills and level up your Computer Science knowledge, look no further than Scrimba's free one-hour course, &lt;a href="https://scrimba.com/course/galgorithmsguide?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=galgorithmsguide_launch_article"&gt;The Working Developer's Guide To Algorithms&lt;/a&gt;. It was designed for those who don't have a background in Computer Science and feel they would benefit from learning to think algorithmically.&lt;/p&gt;

&lt;h2&gt;
  
  
  What does the course do?
&lt;/h2&gt;

&lt;p&gt;Our guide takes you through how to craft six different binary search algorithms. In classic Scrimba style, it contains a bunch of challenges along the way, so you'll gain the muscle memory you need to improve your skills as a software developer and work better with algorithms going forward.&lt;/p&gt;

&lt;p&gt;You'll learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Binary Search&lt;/li&gt;
&lt;li&gt;Big O notation&lt;/li&gt;
&lt;li&gt;Imperative code&lt;/li&gt;
&lt;li&gt;Recursion&lt;/li&gt;
&lt;li&gt;Tail recursion&lt;/li&gt;
&lt;li&gt;Array splitting&lt;/li&gt;
&lt;li&gt;Array view&lt;/li&gt;
&lt;li&gt;Partition&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each algorithm is taught in three stages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Walkthrough:&lt;/strong&gt; Jonathan introduces the algorithm conceptually.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Implementation:&lt;/strong&gt; We get our hands dirty by crafting our own versions of the algorithm.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Solution:&lt;/strong&gt; Jonathan shows us his implementation for comparison.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;You'll get the most out of this course if you have a good understanding of Javascript and are ideally already working as a developer or are a Bootcamp graduate. If you're not there yet, check out Scrimba's great free tutorials &lt;a href="https://scrimba.com/course/gintrotojavascript?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=galgorithmsguide_launch_article"&gt;Introduction to JavaScript&lt;/a&gt; and &lt;a href="https://scrimba.com/course/gintrotoes6?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=galgorithmsguide_launch_article"&gt;Introduction to ES6+&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Intro to the instructor
&lt;/h2&gt;

&lt;p&gt;Jonathan Lee Martin is a software developer, web educator, speaker, and author. He helps other developers achieve their professional and personal goals through writing, speaking, immersive Bootcamps, workshops, and online tutorials. With clients including companies such as NASA and HP, he's just the person to take you through the learning journey. So let's get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  Binary Search
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pk57XHz/cPJqarfK?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=galgorithmsguide_launch_article"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N0rrIKaT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/iphh9m8t8a0jgq94w926.png" alt="Graph of Sweeper vs Splitter searches."&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Click the image to access the course.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://scrimba.com/p/pk57XHz/cPJqarfK?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=galgorithmsguide_launch_article"&gt;the first cast&lt;/a&gt;, Jonathan introduces to the concepts of &lt;strong&gt;Big-O notation&lt;/strong&gt; and &lt;strong&gt;binary search&lt;/strong&gt;, the algorithm we'll be working with.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Big-O notation&lt;/strong&gt; is a means of describing the worst-case performance of an algorithm. A Big O of O(n) says that if an array has a length of n elements, the run time will be proportional to n. In other words, an array of seven entries will take 7 lookups in the worst case, just as an array of 7 million entries will take 7 million entries in the worst case. We can also say this algorithm's runtime is linear, as illustrated in the graph above.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Binary search&lt;/strong&gt; is one of several strategies for answering the question "Where does this element appear in a list?"&lt;/p&gt;

&lt;p&gt;When answering the question, there are two main approaches:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sweeper&lt;/strong&gt;: Checking through each item in the list until the correct item is found.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Splitter&lt;/strong&gt; / &lt;strong&gt;Binary Search&lt;/strong&gt;: Splitting the list in half, checking whether you have gone too far or not far enough to locate the item, searching either right or left side respectively and repeating until the item is located.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can think of these approaches in terms of checking an old-school paper phone book. The sweeper approach would involve looking through each and every entry from the start until the correct one is located, while the splitter approach is the one most people would use; opening the book randomly and seeing whether you need to go forwards or back until the entry is located&lt;/p&gt;

&lt;p&gt;Binary Search is more efficient than the sweeper approach, particularly for larger lists, however, it only works when the list has already been sorted. While the sweeper approach has a linear runtime (see graph above) and Big O of O(n), the splitter approach has a sub-linear runtime and a Big O of O(log n).&lt;/p&gt;
&lt;h2&gt;
  
  
  Imperative
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pk57XHz/czkBGrtD?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=galgorithmsguide_launch_article"&gt;In the first challenge cast&lt;/a&gt;, Jonathan encourages us to get our hands dirty by implementing binary search in a traditional style, that is with a Big O of O(n), using a fixed amount of memory and loops.&lt;/p&gt;

&lt;p&gt;Jonathan provides us with a test suite we can use to ensure our solution is successful and encourages us to try the challenge ourselves before checking out his implementation. No spoilers here, so head over to the cast to give it try yourself.&lt;/p&gt;

&lt;p&gt;While this solution is short and close to the original formulation of binary search, you've probably noticed that the solution was difficult to write and not the best solution from a software craftsmanship point of view. Read on to find out ways to level up the solution...&lt;/p&gt;
&lt;h2&gt;
  
  
  Recursion
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pk57XHz/c2Pr87c4?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=galgorithmsguide_launch_article"&gt;In this cast&lt;/a&gt;, we look at improving our binary search by implementing a new version with a few constraints. While our solution should still have a Big O of O(n), it should not use loops and must use recursion. All variables should be initialized with the &lt;code&gt;const&lt;/code&gt; operator so they can't be mutated.&lt;/p&gt;

&lt;p&gt;Jonanthan kicks us off with a skeleton version of the solution and then encourages us to try the challenge on our own:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;binarySearchWithRecursion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;compare&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;defaultCompare&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;-&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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;binarySearchWithRecursion&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you've completed this challenge, you've probably seen that this solution is a lot easier to read but is quite verbose. In the worst case, it can also result in infinite recursion. Continue with the course to see whether there are ways of streamlining the solution...&lt;/p&gt;

&lt;h2&gt;
  
  
  Tail Recursion
&lt;/h2&gt;

&lt;p&gt;The challenge for &lt;a href="https://scrimba.com/p/pk57XHz/ceMQgZTB?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=galgorithmsguide_launch_article"&gt;the next cast&lt;/a&gt; is to improve our previous implementation by reducing duplication.&lt;/p&gt;

&lt;p&gt;Jonathan warns us that the solution will look worse than the previous two solutions, however, it sets us up for some better optimizations further down the line. Head over to the course now to try the challenge for yourself and see Jonathan's solution.&lt;/p&gt;

&lt;h2&gt;
  
  
  Array Splitting
&lt;/h2&gt;

&lt;p&gt;If you completed the previous challenge, you may have felt that we're still passing a lot of extra information into our binary search via recursion. &lt;a href="https://scrimba.com/p/pk57XHz/cEKyndHw?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=galgorithmsguide_launch_article"&gt;This cast&lt;/a&gt; looks at a way of cleaning that up called &lt;strong&gt;array splitting&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We can think of array splitting in terms of our phone book example from earlier - whenever we decide that half the phone book is irrelevant, we just tear it off and throw it away. Similarly, our next solution should disregard any parts of the array which don't include our desired entry.&lt;/p&gt;

&lt;p&gt;To help us achieve this, Jonathan starts us off with some skeleton code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;binarySearchWithArraySplitting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;compare&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;defaultCompare&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;-&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then, as usual, he gives us free rein to try to the solution for ourselves before walking us through his own implementation.&lt;/p&gt;

&lt;p&gt;Although this is an elegant method of binary search, because it involves making a copy of part of the array, it no longer has a Big O of O(n) and has a higher memory usage and slower run time. Continue with the course to find out whether there is a way to regain a higher performance with a similar code solution...&lt;/p&gt;

&lt;h2&gt;
  
  
  Array View
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pk57XHz/cmdvdnhb?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=galgorithmsguide_launch_article"&gt;In this cast&lt;/a&gt;, we look for ways of merging the higher performance of our previous solutions with the elegance of array splitting. To do this, we create an array-like object that responds to the same methods as an array. We'll then inject this object in place of the original array.&lt;/p&gt;

&lt;p&gt;Jonathan gets us started by initializing a function &lt;code&gt;ArrayView&lt;/code&gt; which returns an object that expects three arguments: &lt;code&gt;array&lt;/code&gt;, &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt;. When invoked, &lt;code&gt;ArrayView&lt;/code&gt; should return an object with four methods, &lt;code&gt;length&lt;/code&gt;, &lt;code&gt;toArray&lt;/code&gt;, &lt;code&gt;slice&lt;/code&gt; and &lt;code&gt;get&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;ArrayView&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="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="na"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;toArray&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="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;slice&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="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;get&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="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;binarySearchWithArrayView&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;args&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;binarySearchWithArraySplitting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ArrayView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Our challenge is to implement the &lt;code&gt;slice&lt;/code&gt; and &lt;code&gt;get&lt;/code&gt; methods of &lt;code&gt;ArrayView&lt;/code&gt; without making a copy of the original array. Click through to try it out and then view Jonathan's walkthrough.&lt;/p&gt;

&lt;p&gt;Although this solution produces better, more readable code, it is longer than some of our previous solutions. Continue with the course to find out if we can retain the benefits of &lt;code&gt;ArrayView&lt;/code&gt; while lifting even more of the logic out of binary search code...&lt;/p&gt;

&lt;h2&gt;
  
  
  Array Partition
&lt;/h2&gt;

&lt;p&gt;In &lt;a href="https://scrimba.com/p/pk57XHz/c8rZqEsV?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=galgorithmsguide_launch_article"&gt;the final challenge cast&lt;/a&gt; of the course, Jonathan gives us a goal of extracting some of the cryptic bounce logic in our previous version into a data structure.&lt;/p&gt;

&lt;p&gt;For this, we need a simple data structure which returns the middle, left or right part of an array. To start us off, Jonathan sets up a function &lt;code&gt;ArrayPartition&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;ArrayPartition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pivot&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="na"&gt;left&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="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&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="nx"&gt;pivot&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;middle&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="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pivot&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;right&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="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pivot&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="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next, Jonathan sets up a new version of binary search called &lt;code&gt;binarySearchWithPartition&lt;/code&gt;, which has a starting signature the same as &lt;code&gt;binarySearchWithArraySplitting&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;binarySearchWithPartition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;compare&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;defaultCompare&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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;return&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;middle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&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;comparison&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;compare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;middle&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;comparison&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;return&lt;/span&gt; &lt;span class="nx"&gt;middle&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;//bounce logic&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;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
        &lt;span class="nx"&gt;comparison&lt;/span&gt; &lt;span class="o"&gt;===&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="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;middle&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="nx"&gt;middle&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="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="c1"&gt;//end of bounce logic&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;subIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;binarySearchWithArraySplitting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nx"&gt;compare&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;subIndex&lt;/span&gt; &lt;span class="o"&gt;===&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="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="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;subIndex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;binarySearchWithPartitionAndView&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;args&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;binarySearchWithPartition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ArrayView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Our challenge now is to rewrite &lt;code&gt;binarySearchWithPartition&lt;/code&gt; with none of the &lt;code&gt;bounce&lt;/code&gt; logic highlighted above, instead of creating an array partition and making calls to its left, middle and right methods.&lt;/p&gt;

&lt;p&gt;Head over to the course now to try the challenge for yourself. As Jonathan points out, this challenge is tricky, so it's ok to skip to his solution if you get stuck for too long but give it a go first on your own.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap-Up
&lt;/h2&gt;

&lt;p&gt;You've made it to the end of the course - great work! We've covered several approaches to binary search, all with their own benefits and drawbacks, and built some great muscle memory for working effectively with algorithms. Now that you've seen six different approaches to binary search, you'll probably notice it pop up in many different places in programming.&lt;/p&gt;

&lt;p&gt;Jonathan's full course featuring 10 algorithms will be coming out at the end of the year, but in the meantime, I hope you can put your newfound binary search skills to good use.&lt;/p&gt;

&lt;p&gt;Happy coding :)&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/v684EuCrPAM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>cs</category>
      <category>algorithms</category>
      <category>scrimba</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Learn React in 1 Hour by Building a Movie Search App</title>
      <dc:creator>Per</dc:creator>
      <pubDate>Sat, 06 Jun 2020 14:18:44 +0000</pubDate>
      <link>https://forem.com/scrimba/learn-react-in-1-hour-by-building-a-movie-search-app-21gc</link>
      <guid>https://forem.com/scrimba/learn-react-in-1-hour-by-building-a-movie-search-app-21gc</guid>
      <description>&lt;p&gt;If you've been meaning to learn React but unsure of where to start, Scrimba's brand new &lt;a href="https://scrimba.com/course/greactmovie?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&gt;Build a Movie Search App&lt;/a&gt; course is perfect for you! You'll be guided through the app's creation from start to finish in just one hour, with interactive challenges helping you gain the muscle memory you need to become an effective React developer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why learn React?
&lt;/h2&gt;

&lt;p&gt;React is the world's most popular front-end framework. As &lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;the docs&lt;/a&gt; state, React makes it painless to create interactive UIs and more predictable code which is easier to debug. With React, you can produce complex UIs through constructing reusable components that manage their own state.&lt;/p&gt;

&lt;h2&gt;
  
  
  What does this course do?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/course/greactmovie?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&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%2Fmspewise511f3ub7eyn9.png" alt="Styled movie cards"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This learning journey takes you through 11 interactive screencasts, showing you the following core concepts of modern React:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to get an API key&lt;/li&gt;
&lt;li&gt;Adding base styles&lt;/li&gt;
&lt;li&gt;Creating and styling components&lt;/li&gt;
&lt;li&gt;Creating functions&lt;/li&gt;
&lt;li&gt;Managing state using hooks&lt;/li&gt;
&lt;li&gt;Displaying information&lt;/li&gt;
&lt;li&gt;Creating and styling cards&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Intro to the teacher
&lt;/h2&gt;

&lt;p&gt;This tutorial is led by James Q. Quick, a full-stack Web Developer who regularly speaks at community events and participates in Hackathons. He also runs a YouTube channel teaching web development. His motto 'Learn. Build. Teach.' makes him the perfect teacher for this practical course.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;To study this course effectively, you should have basic knowledge of HTML, CSS, and JavaScript. You'll also find it useful to have seen some React code before, but it's not a must-have. If you need a bit more background knowledge, take a look at these fantastic free Scrimba courses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://scrimba.com/course/ghtmlcss?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&gt;HTML and CSS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://scrimba.com/course/gintrotojavascript?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&gt;Javascript&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://scrimba.com/learn/learnreact?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&gt;Learn React for Free&lt;/a&gt; with Bob Ziroll&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're ready to hit the ground running with React, let's get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  Course Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pZaznUL/cdVKdrtr?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&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%2Fn0xmel3r6k0qiazx8v0p.png" alt="Build a Movie Search App Course front title slide"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://scrimba.com/p/pZaznUL/cdVKdrtr?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&gt;the first scrim&lt;/a&gt;, James runs us through a few of the key features of the app we'll be building and gives us a quick rundown of how the app works. Lastly, James introduces us to the API we'll use - &lt;a href="https://www.themoviedb.org/" rel="noopener noreferrer"&gt;themoviedb.org&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Get Your Movie DB API Key
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pZaznUL/cdVKdLSk?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&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%2Fxe8kqht68qhkbpn6bvo5.png" alt="Generating a MovieDB API key"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://scrimba.com/p/pZaznUL/cdVKdLSk?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&gt;this short cast&lt;/a&gt;, James gives us the lowdown on how to get a Movie DB API Key by signing up with a free account. This is super straightforward and takes just a few minutes. Click the image above to access the course.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add Base Styles to Your App
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pZaznUL/cNDyQvc2?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&gt;Next up&lt;/a&gt;, James shows us the basic React application he has instantiated for us:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&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-dom&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;Main&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="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="nx"&gt;world&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;ReactDOM&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Main&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;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We then add some base styles to our &lt;code&gt;style.css&lt;/code&gt; file including margins and padding, title styles and, the Holy Grail of CSS - centering the app's contents. &lt;a href="https://scrimba.com/p/pZaznUL/cNDyQvc2?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&gt;Click here&lt;/a&gt; to check out the styles for yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Your First Component
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pZaznUL/caZvgqTk?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&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%2Favats2r0wi0mz89mivbr.png" alt="Our first React app in action"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pZaznUL/caZvgqTk?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&gt;In this scrim&lt;/a&gt;, we have our first challenge - to create a React component. James uses a &lt;code&gt;test.js&lt;/code&gt; file to give us a brief preview of what's needed before breaking down the task into manageable chunks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;//to create the SearchMovies component //form with a class of form //label with
htmlFor="query" and a class of Label //input of type text with a name of "query"
and a placeholder //button class of button and a type of submit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Click through to the link or image above to get your hands dirty and give the challenge a try.&lt;/p&gt;

&lt;h2&gt;
  
  
  Style the Search Movies Component
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pZaznUL/c6WdV7Ap?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&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%2F752w2eczfd6vo21o1b1j.png" alt="Our first React app with styles added"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pZaznUL/c6WdV7Ap?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&gt;Next up&lt;/a&gt;, it's time to style our new app. James suggests some styles for our &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;label&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; and adds a media query to adjust the styles on larger screens:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;786px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;.form&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="py"&gt;grid-gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nc"&gt;.input&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;margin-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't forget that Scrimba is fully interactive, so you can be as creative as you like with the styles - these ideas are just some possibilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create the Search Movies Function
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&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="nf"&gt;SearchMovies&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;searchMovies&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &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="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="nf"&gt;preventDefault&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;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Jurassic Park&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`https://api.themoviedb.org/3/search/movie?api_key=5dcf7f28a88be0edc01bbbde06f024ab&amp;amp;language=en-US&amp;amp;query=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;amp;page=1&amp;amp;include_adult=false`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;try&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;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&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;data&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;res&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="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="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&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;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In &lt;a href="https://scrimba.com/p/pZaznUL/cdVQEGh9?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&gt;this screencast&lt;/a&gt;, we create an async function that will use the Fetch API to retrieve the movie information from the Movie DB API. Hit the link to see how it's done.&lt;/p&gt;

&lt;h2&gt;
  
  
  Manage State with React useState Hook
&lt;/h2&gt;

&lt;p&gt;In &lt;a href="https://scrimba.com/p/pZaznUL/c73GVeS4?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&gt;this scrim&lt;/a&gt;, James shows us how to use state to track the user's query with the &lt;code&gt;useState&lt;/code&gt; hook:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setQuery&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="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we set the &lt;code&gt;onChange&lt;/code&gt; on our &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; to bind it to that state:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;
    &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;"&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;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;query&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="nx"&gt;placeholder&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;i.e. Jurassic Park&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;onChange&lt;/span&gt;&lt;span class="o"&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="nf"&gt;setQuery&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="sr"&gt;/&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;Then it's time for our second challenge - to create the state for movie information and update that state as appropriate. Hop on over to the tutorial to try it out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Display Movie Information
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pZaznUL/cgKVEEf4?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&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%2Fwv0o08oujgigzbi3h8jz.png" alt="App displaying movie info"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we can search for our movies, it's time to &lt;a href="https://scrimba.com/p/pZaznUL/cgKVEEf4?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&gt;display the information&lt;/a&gt; to the user. Click the link or image to see how it's done!&lt;/p&gt;

&lt;h2&gt;
  
  
  Style the Movie Cards
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pZaznUL/c9qaG6sD?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&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%2Fmspewise511f3ub7eyn9.png" alt="Styled movie cards"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pZaznUL/c9qaG6sD?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&gt;Next up&lt;/a&gt;, James shows us how to style our movie cards to create an attractive, user-friendly app. We start with our card container &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;card&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="nx"&gt;rem&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="nx"&gt;rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;border&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="nx"&gt;px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;box&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;shadow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;px&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;px&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="nx"&gt;px&lt;/span&gt; &lt;span class="nf"&gt;rgba&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="mi"&gt;0&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="mf"&gt;0.25&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;margin&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="nx"&gt;rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;background&lt;/span&gt;&lt;span class="o"&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;white&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;With that done, we move onto our titles and images. Click the link or image above to get the lowdown.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create the Movie Card Component (Challenge)
&lt;/h2&gt;

&lt;p&gt;Our &lt;a href="https://scrimba.com/p/pZaznUL/cE9N3nsw?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&gt;final task&lt;/a&gt; is to create a separate component to display the movie card. This ensures maintainability should our project grow, and is a good habit to get into in preparation for bigger projects.&lt;/p&gt;

&lt;p&gt;In true Scrimba style, James presents this challenge and then walks us through his solution. Head over to the cast now to try for yourself. &lt;strong&gt;Note:&lt;/strong&gt; Props are needed for this, but James gives a quick how-to in the task explanation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;Congratulations on completing the Movie Search app! You now know how to build a fully functional app using core React concepts including functional components, hooks, fetch requests, styling, and reusable components.&lt;/p&gt;

&lt;p&gt;I hope that you gained a lot from this course and feel inspired to continue your learning journey. To find out more about React, head over to Scrimba's free, six-hour &lt;a href="https://scrimba.com/course/glearnreact?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&gt;Learn React for Free&lt;/a&gt; course.&lt;/p&gt;

&lt;p&gt;After that, why not check out all the other great courses available over on &lt;a href="https://scrimba.com/?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactmovie_launch_article"&gt;Scrimba&lt;/a&gt; to see where you'll go next?&lt;/p&gt;

&lt;p&gt;Wherever your journey takes you, happy coding :)&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/UKmsNUk7RxM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>react</category>
      <category>scrimba</category>
    </item>
    <item>
      <title>Learn Vuex in 5 minutes.</title>
      <dc:creator>Per</dc:creator>
      <pubDate>Fri, 05 Jun 2020 17:07:21 +0000</pubDate>
      <link>https://forem.com/scrimba/learn-vuex-in-5-minutes-29ja</link>
      <guid>https://forem.com/scrimba/learn-vuex-in-5-minutes-29ja</guid>
      <description>&lt;p&gt;This tutorial will give you a basic understanding of Vuex by building a plan-making application. A user can type in activities and then vote how much they like/dislike them.&lt;/p&gt;

&lt;p&gt;Once you've read this tutorial, you can check out our &lt;a href="https://scrimba.com/g/gvuex?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuex_5_minute_article"&gt;free Vuex course on Scrimba&lt;/a&gt;, if you're interested in learning more.&lt;/p&gt;

&lt;p&gt;What is Vuex? From &lt;a href="https://vuex.vuejs.org" rel="noopener noreferrer"&gt;Vue's official documentation&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Vuex is a state management pattern + library for Vue.js applications.
It serves as a centralized store for all the components in an application, with rules ensuring that the state can only be mutated in a predictable fashion.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This course assumes that you're somewhat familiar with Vue and we will briefly touch on features like &lt;code&gt;props&lt;/code&gt;, components and bindings, but will not review them in great detail. If you'd like to have a quick primer on Vue, feel free to &lt;a href="https://scrimba.com/p/pXKqta?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuex_5_minute_article"&gt;check out this course on Scrimba&lt;/a&gt;.&lt;/p&gt;
&lt;h1&gt;
  
  
  The setup
&lt;/h1&gt;

&lt;p&gt;At Scrimba, complicated setups are something we just don't do.&lt;br&gt;
For this tutorial, we've created a simple HTML file where everything can be written. Feel free to write your own CSS or just copy it from &lt;a href="https://scrimba.com/c/c66qG4uG?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuex_5_minute_article"&gt;this playground&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Vue and Vuex libraries are imported via CDN using &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Activity Voter&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdn.jsdelivr.net/npm/vue/dist/vue.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdn.jsdelivr.net/npm/vuex/dist/vuex.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="c"&gt;/*
        ADD CSS HERE
      */&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="cm"&gt;/*
      ADD VUE CODE HERE
    */&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Alternatively, you can also experiment with the code in &lt;a href="https://scrimba.com/c/cqRNMEcG?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuex_5_minute_article"&gt;this Vue Scrimba playground&lt;/a&gt; **&lt;strong&gt;&lt;em&gt;RELINK PLAYGROUND TO YOUR OWN ACCOUNT&lt;/em&gt;&lt;/strong&gt;**.&lt;/p&gt;
&lt;h1&gt;
  
  
  App plan
&lt;/h1&gt;

&lt;p&gt;We're going to build a voting app, that works especially well when you're in a group of friends not knowing what to do and you have to consider all the options.&lt;/p&gt;

&lt;p&gt;The functionality will consist of a user being able to type in an activity and then each activity will have a vote up and down button to count up the totals.&lt;/p&gt;
&lt;h1&gt;
  
  
  Getting started
&lt;/h1&gt;

&lt;p&gt;First, let's quickly mock our app up in HTML. We will use this layout to then extract into a separate component and we will add functionality for the layout to come to life.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Activity voter&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;form&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"Add Activity"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Add Activity&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;span&amp;gt;&lt;/span&gt;
Go Snowboarding&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;span&amp;gt;&lt;/span&gt;🤩&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;👎&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
        5
        &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;👍&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F42ixhwdzkncbibp1m210.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F42ixhwdzkncbibp1m210.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Add Vuex store with some basic data
&lt;/h1&gt;

&lt;p&gt;Vuex starts with the store. The store is where we keep (store) our state.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Vuex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vuex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;

&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;el&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;


&lt;p&gt;Let's also add some hard-coded data to the store, that will include one activity and an array with one emoji to display our feelings towards the activity.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Vuex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vuex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;activities&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;go snowboarding&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;rating&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="p"&gt;}],&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;emojis&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;🤩&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;el&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;


&lt;p&gt;To allow our state to change reactively, we can use Vuex &lt;code&gt;mapState&lt;/code&gt; to handle computed state properties for us.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;el&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Vuex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mapState&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;activities&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;emojis&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

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

&lt;/div&gt;

&lt;h1&gt;
  
  
  Add component
&lt;/h1&gt;

&lt;p&gt;Now we have activities inside our state. Let's render a separate component for each of those activities. Each one will need &lt;code&gt;activity&lt;/code&gt; and &lt;code&gt;emojis&lt;/code&gt; props.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;component&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;activity-item&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="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;props&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;activity&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;emojis&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;li&amp;gt;
      &amp;lt;span&amp;gt;{{ activity.name }}
        &amp;lt;span&amp;gt;{{ emojis[0] }}&amp;lt;/span&amp;gt;
        &amp;lt;button&amp;gt;👎&amp;lt;/button&amp;gt;
        {{activity.rating}}
        &amp;lt;button&amp;gt;👍&amp;lt;/button&amp;gt;
      &amp;lt;/span&amp;gt;
    &amp;lt;/li&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;Inside &lt;code&gt;app&lt;/code&gt; we can now use our newly created component with all the appropriate bindings for &lt;code&gt;activity&lt;/code&gt; and emojis. As a quick reminder, if we want to loop over an array and display a component for each item in an array, in Vue, we can use &lt;code&gt;v-for&lt;/code&gt; binding.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Activity voter&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;form&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"Add Activity"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Add Activity&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;activity-item&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;v-for=&lt;/span&gt;&lt;span class="s"&gt;"item in activities"&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;v-bind:activity=&lt;/span&gt;&lt;span class="s"&gt;"item"&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;v-bind:emojis=&lt;/span&gt;&lt;span class="s"&gt;"emojis"&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;v-bind:key=&lt;/span&gt;&lt;span class="s"&gt;"item.name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/activity-item&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F42ixhwdzkncbibp1m210.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F42ixhwdzkncbibp1m210.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Add mutations to store
&lt;/h1&gt;

&lt;p&gt;If we want to update the store in Vuex, we can use mutations. At the moment we will just &lt;code&gt;console.log&lt;/code&gt; that a mutation happened and we will implement it afterwards.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vuex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;activities&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;go snowboarding&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;rating&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;emojis&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;🤩&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;mutations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nf"&gt;increment&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;activityName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&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="s1"&gt;increment&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nf"&gt;decrement&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;activityName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&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="s1"&gt;decrement&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="err"&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;How do we trigger a mutation? We call a &lt;code&gt;commit&lt;/code&gt; function on &lt;code&gt;$store&lt;/code&gt; with the name of mutations we want to be executed. Any arguments after the name of a mutation are treated as arguments to a committed mutation.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;el&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;activityName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Vuex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mapState&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;activities&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;emojis&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;activityName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&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;$store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;increment&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;activityName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nf"&gt;decrement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;activityName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&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;$store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;decrement&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;activityName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&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;h1&gt;
  
  
  Add functionality to component
&lt;/h1&gt;

&lt;p&gt;Each &lt;code&gt;activity-item&lt;/code&gt; has voting buttons that need to &lt;code&gt;increment&lt;/code&gt; and &lt;code&gt;decrement&lt;/code&gt; on click of a button. We can pass these functions as props. Let's now bind our methods to props.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;activity-item&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;v-for=&lt;/span&gt;&lt;span class="s"&gt;"item in activities"&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;v-bind:increment=&lt;/span&gt;&lt;span class="s"&gt;"increment"&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;v-bind:decrement=&lt;/span&gt;&lt;span class="s"&gt;"decrement"&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;v-bind:activity=&lt;/span&gt;&lt;span class="s"&gt;"item"&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;v-bind:emojis=&lt;/span&gt;&lt;span class="s"&gt;"emojis"&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;v-bind:key=&lt;/span&gt;&lt;span class="s"&gt;"item.name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/activity-item&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;


&lt;p&gt;Let's also not forget to provide &lt;code&gt;activity.name&lt;/code&gt; as an argument to both.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;component&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;activity-item&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="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;props&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;activity&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;emojis&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;increment&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;decrement&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;li&amp;gt;
      &amp;lt;span&amp;gt;{{ activity.name }}
          &amp;lt;span&amp;gt;{{ emojis[0] }}&amp;lt;/span&amp;gt;
          &amp;lt;button @click="decrement(activity.name)"&amp;gt;👎&amp;lt;/button&amp;gt;
          {{activity.rating}}
          &amp;lt;button @click="increment(activity.name)"&amp;gt;👍&amp;lt;/button&amp;gt;
      &amp;lt;/span&amp;gt;
    &amp;lt;/li&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 there we go! The flow is working. We can see the &lt;code&gt;console.log&lt;/code&gt; statement in the console.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F2spr4ea73npem7pyv05h.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F2spr4ea73npem7pyv05h.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Implement counter
&lt;/h1&gt;

&lt;p&gt;Let's implement the counter. First, we need to find an activity by its name, and then update its rating.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nx"&gt;mutations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nf"&gt;increment&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;activityName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&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;activities&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;activity&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;activity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;activityName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;activity&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;activity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rating&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nf"&gt;decrement&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;activityName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&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;activities&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;activity&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;activity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;activityName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;activity&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;activity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rating&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Perfect, we can now vote on activities.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Feh23lvlqaszxq0rxmkel.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Feh23lvlqaszxq0rxmkel.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Use form input to add activity
&lt;/h1&gt;

&lt;p&gt;But of course, we need to be able to add activities too.&lt;/p&gt;

&lt;p&gt;Let's create a mutation to the store, that would add an activity to the list of existing activities, with a name that we will later get from the input and a default rating of 0.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nx"&gt;mutations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nf"&gt;addActivity&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;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&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;activities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&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="na"&gt;rating&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="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Inside methods, we can commit a new activity to the store.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nf"&gt;addActivity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;activityName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&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;$store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;addActivity&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;activityName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h1&gt;
  
  
  Implement form submission
&lt;/h1&gt;

&lt;p&gt;Let's wire up the submit function to our HTML form.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;submit=&lt;/span&gt;&lt;span class="s"&gt;"onSubmit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"Add Activity"&lt;/span&gt; &lt;span class="na"&gt;v-model=&lt;/span&gt;&lt;span class="s"&gt;"activityName"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Add Activity&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We can now add our submit function to methods. Inside, we're going to use our existing &lt;code&gt;addActivity&lt;/code&gt; method and in the end, reset &lt;code&gt;activityName&lt;/code&gt; in the input field to an empty string.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nf"&gt;onSubmit&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="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&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;addActivity&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;activityName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&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;activityName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We call &lt;code&gt;e.preventDefault()&lt;/code&gt; to avoid the form from reloading on each addition of a new activity.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fqsnc185pcchj71c6878i.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fqsnc185pcchj71c6878i.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All the counters now work and the field gets updated. It does look a bit strange, that we have only one emotion for all the activities, no matter what their rating is.&lt;/p&gt;

&lt;p&gt;Let's rewrite emojis into an object with some description of what moods they are meant to reflect and clean up existing state, so we start from no activities.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nx"&gt;activities&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nx"&gt;emojis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;yay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🤩&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;nice&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;😀&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;meh&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;😐&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;argh&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🤬&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;hateIt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;💩&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And as a finishing touch, we can display different emojis depending on the rating an activity has.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;component&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;activity-item&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="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;props&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;activity&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;emojis&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;increment&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;decrement&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;li&amp;gt;
      &amp;lt;span&amp;gt;{{ activity.name }}
        &amp;lt;span v-if="activity.rating &amp;lt;= -5"&amp;gt;{{ emojis.hateIt }}&amp;lt;/span&amp;gt;
        &amp;lt;span v-else-if="activity.rating &amp;lt;= -3"&amp;gt;{{ emojis.argh }}&amp;lt;/span&amp;gt;
        &amp;lt;span v-else-if="activity.rating &amp;lt; 3"&amp;gt;{{ emojis.meh }}&amp;lt;/span&amp;gt;
        &amp;lt;span v-else-if="activity.rating &amp;lt; 5"&amp;gt;{{ emojis.nice }}&amp;lt;/span&amp;gt;
        &amp;lt;span v-else&amp;gt;{{ emojis.yay }}&amp;lt;/span&amp;gt;
        &amp;lt;button @click="decrement(activity.name)"&amp;gt;👎&amp;lt;/button&amp;gt;
          {{activity.rating}}
        &amp;lt;button @click="increment(activity.name)"&amp;gt;👍&amp;lt;/button&amp;gt;
      &amp;lt;/span&amp;gt;
    &amp;lt;/li&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;We start with a blank app, which is what we wanted.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F7izt1gxbmnje90fiv9gq.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F7izt1gxbmnje90fiv9gq.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And now if we add back the two activities we used to have in the app, vote on the ratings we have emojis that reflect how we feel about the activities!&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fhclj6218rr3pxe5pnv19.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fhclj6218rr3pxe5pnv19.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Full Code
&lt;/h1&gt;


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



</description>
      <category>vuex</category>
      <category>vue</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Learn React Hooks by Building a Paint App</title>
      <dc:creator>Per</dc:creator>
      <pubDate>Fri, 05 Jun 2020 17:05:14 +0000</pubDate>
      <link>https://forem.com/scrimba/learn-react-hooks-by-building-a-paint-app-4p9c</link>
      <guid>https://forem.com/scrimba/learn-react-hooks-by-building-a-paint-app-4p9c</guid>
      <description>&lt;p&gt;According to people in the know, React Hooks are hot, hot, hot. In this article, we follow Christian Jensen's &lt;a href="https://scrimba.com/g/greacthooks?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greacthooks_launch_article"&gt;14-part tutorial&lt;/a&gt; to find out about the basics of this new feature of React. Follow along to find out more!&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fmh1hdo0zzhtgei8gv614.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fmh1hdo0zzhtgei8gv614.png" alt="React Hooks we will learn in this course"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Intro
&lt;/h1&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F1j9osq1fshioocmoo0v4.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F1j9osq1fshioocmoo0v4.png" alt="Paint app we will build during this project"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hooks are new to the React library and allow us to share logic between components and make them reusable.&lt;/p&gt;

&lt;p&gt;In this course, we will be building a paint app similar to Microsoft Paint, which will allow us to name our project, switch out colors, get a new batch of colors and of course paint.&lt;/p&gt;

&lt;p&gt;Scrimba allows you to pause screencasts at any time and play with the code. It's a great way to learn by doing!&lt;/p&gt;

&lt;h1&gt;
  
  
  Prerequisites
&lt;/h1&gt;

&lt;p&gt;The course assumes some &lt;a href="https://www.freecodecamp.org/news/learn-modern-javascript-in-this-free-28-part-course-7ec8d353eb/" rel="noopener noreferrer"&gt;prior knowledge of ES6&lt;/a&gt;, &lt;a href="https://www.freecodecamp.org/news/learn-react-js-in-5-minutes-526472d292f4/" rel="noopener noreferrer"&gt;JSX, State and Props&lt;/a&gt;, but no worries, we've got you covered - check out our Scrimba articles by hitting the links above.&lt;/p&gt;

&lt;p&gt;If you are completely new to React, be sure to check out our &lt;a href="https://scrimba.com/g/glearnreact?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greacthooks_launch_article"&gt;Scrimba React course&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;code&gt;useState&lt;/code&gt; - Part 1
&lt;/h1&gt;

&lt;p&gt;First, we give our application a way to manage state using useState.&lt;/p&gt;

&lt;p&gt;In our &lt;code&gt;&amp;lt;Playground.js /&amp;gt;&lt;/code&gt; component, we declare a component called &lt;code&gt;&amp;lt;Playground /&amp;gt;&lt;/code&gt; and create buttons to increment and decrement it. We then give useState an argument of (0) and use state restructuring to get &lt;code&gt;state&lt;/code&gt; and &lt;code&gt;setState&lt;/code&gt; (the function which updates the state) from our &lt;code&gt;useState&lt;/code&gt; function. These are now renamed to &lt;code&gt;count&lt;/code&gt; and &lt;code&gt;setCount&lt;/code&gt;. We then render our count in the browser.&lt;/p&gt;

&lt;p&gt;Lastly, we render buttons which update the count using an inline function which will be triggered on the click.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkohiz9hz2f49n5i80l71.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkohiz9hz2f49n5i80l71.png" alt="Incrementing count with our buttons"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To ensure our count is accurate, we pass a function to our &lt;code&gt;setState&lt;/code&gt; function instead of a value. This function takes the current state as its argument, which is then updated:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="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;import&lt;/span&gt; &lt;span class="nx"&gt;randomColor&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;randomcolor&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="nf"&gt;Playground&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;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&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="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;currentCount&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;currentCount&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="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="o"&gt;-&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;currentCount&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;currentCount&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="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="o"&gt;+&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you're worried about the performance of inline functions, take a look a &lt;a href="https://cdb.reacttraining.com/react-inline-functions-and-performance-bdff784f5578" rel="noopener noreferrer"&gt;this&lt;/a&gt; blog.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;code&gt;useState&lt;/code&gt; - Part 2
&lt;/h1&gt;

&lt;p&gt;Now we add our name input to the &lt;code&gt;&amp;lt;Name.js /&amp;gt;&lt;/code&gt; component so the user can name their project.&lt;/p&gt;

&lt;p&gt;To set up&lt;code&gt;&amp;lt;Name.js /&amp;gt;&lt;/code&gt; with a &lt;code&gt;useState&lt;/code&gt; Hook, we need to import the Hook with a named import and then set our state up. Our state will be &lt;code&gt;name&lt;/code&gt; and we will update it with setName. We then call useState and pass in an empty string as our default state value.&lt;/p&gt;

&lt;p&gt;We now need an input element with four properties. These are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;value&lt;/code&gt;, which will always be the state &lt;code&gt;name&lt;/code&gt; from above&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;onChange&lt;/code&gt;, which will use &lt;code&gt;setState&lt;/code&gt; inline to update &lt;code&gt;name&lt;/code&gt; by passing the value into setState&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;onClick&lt;/code&gt; which uses setSelectionRange which takes a start index of 0 and end index of the length of the string to select the entire name, making it easier for the end-user to change the name.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;placeholder&lt;/code&gt;, which we set to 'Untitled'.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="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="nf"&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;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setName&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="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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;header-name&lt;/span&gt;&lt;span class="dl"&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;input&lt;/span&gt;
                &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&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="nx"&gt;onChange&lt;/span&gt;&lt;span class="o"&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="nf"&gt;setName&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="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&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;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="nf"&gt;setSelectionRange&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="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="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
                &lt;span class="nx"&gt;placeholder&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Untitled&lt;/span&gt;&lt;span class="dl"&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="sr"&gt;/label&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can now name our project and select the name to reset it with just one click:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Frgupvtuwliarlt2woyrj.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Frgupvtuwliarlt2woyrj.png" alt="Project's name input in action."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;code&gt;useEffect&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;Currently, our Playground.js component is simply rendering a counter where can increment or decrement the count. Now we will update this so that every time the count is changed, the color of something is also changed.&lt;/p&gt;

&lt;p&gt;We use the useState Hook to set up the initial color, which we set to &lt;code&gt;null&lt;/code&gt; and the function to update it (&lt;code&gt;setColor&lt;/code&gt;). Now, we set up &lt;code&gt;useEffect&lt;/code&gt; to update this color. &lt;code&gt;useEffect&lt;/code&gt;'s first argument is setColor, which we want to set to a &lt;code&gt;randomColor&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;As we only want a change in &lt;code&gt;count&lt;/code&gt; to trigger &lt;code&gt;useEffect&lt;/code&gt;, we set this as the second argument. If the count value hasn't changed, the Hook will not run the effect and the color will remain the same.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="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="nx"&gt;useEffect&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;import&lt;/span&gt; &lt;span class="nx"&gt;randomColor&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;randomcolor&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="nf"&gt;Playground&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;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&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="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="nf"&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="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;setColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;randomColor&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;borderTop&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`10px solid &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt; &lt;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;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;currentCount&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;currentCount&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="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="o"&gt;-&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;currentCount&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;currentCount&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="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="o"&gt;+&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, our color changes every time we increment or decrement our count.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6b6n7h96pkk89llw6abi.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6b6n7h96pkk89llw6abi.png" alt="initial color"&gt;&lt;/a&gt;&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fvawilltd0p7mu15lwa1d.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fvawilltd0p7mu15lwa1d.png" alt="color changed by one increment"&gt;&lt;/a&gt;&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fsq1ouu7f3d7u26kuov3f.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fsq1ouu7f3d7u26kuov3f.png" alt="color changed by a second increment"&gt;&lt;/a&gt;&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ff2paopu37b35ojior8s7.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ff2paopu37b35ojior8s7.png" alt="color changed by one decrement"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;code&gt;useState&lt;/code&gt; &amp;amp; &lt;code&gt;useEffect&lt;/code&gt; Challenge
&lt;/h1&gt;

&lt;p&gt;It's now time to test the skills we have acquired so far. In this screencast, a function which gets some random colors for us has been added to :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getColors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;baseColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;randomColor&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&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="s2"&gt;`https://www.thecolorapi.com/scheme?hex=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;baseColor&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;amp;mode=monochrome`&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;res&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;res&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;res&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;setColors&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&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="o"&gt;=&amp;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;hex&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="nf"&gt;setActiveColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;colors&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="nx"&gt;hex&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="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our task is to write the functions for &lt;code&gt;setColors&lt;/code&gt;, which will give us an array of hex colors and &lt;code&gt;setActiveColor&lt;/code&gt;, which will tell use what the active color is.&lt;/p&gt;

&lt;p&gt;If we set up everything correctly, the UI will update with five colors which we can click on to expand. We only need useState and useEffect for this test.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;code&gt;useState&lt;/code&gt; &amp;amp; &lt;code&gt;useEffect&lt;/code&gt; Solution
&lt;/h1&gt;

&lt;p&gt;In &lt;a href="https://scrimba.com/p/pKkkVU3/cDbkNJsg?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greacthooks_launch_article"&gt;this&lt;/a&gt; screencast, Christian walks us through how to give functionality to the &lt;code&gt;&amp;lt;ColorPicker /&amp;gt;&lt;/code&gt; component. At the end of it, we now have some colors:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Frxe2h70fqoldqf6ouoss.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Frxe2h70fqoldqf6ouoss.png" alt="colors visible in UI"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;code&gt;useEffect&lt;/code&gt; Clean Up
&lt;/h1&gt;

&lt;p&gt;Now we add a component called &lt;code&gt;&amp;lt;WindowSize.js /&amp;gt;&lt;/code&gt; which will show the window width and height at the bottom of the screen when the user resizes the window. This then disappears after half a second.&lt;/p&gt;

&lt;p&gt;When we set up a timer or an event listener, we also need to clean it up once the component unmounts. This requires two pieces of state - the window size and visibility of the &lt;code&gt;&amp;lt;WindowSize /&amp;gt;&lt;/code&gt; component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;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="nf"&gt;WindowSize&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;windowWidth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;windowHeight&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;setWindowSize&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="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerWidth&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;innerHeight&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;visible&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setVisible&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="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we set up our effect, which adds the event listener:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleResize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
    &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;resize&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleResize&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;Next, we set up the cleanup phase. This returns the function and an empty array is passed in to tell it that useEffect should only run on the first mount. The cleanup will then run and remove the event listener:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleResize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
    &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;resize&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleResize&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="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;resize&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleResize&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We now set up the window size, the visibility and the timer so that the the resize window appears and then disappears after 500 milliseconds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;visible&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setVisible&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="kc"&gt;false&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleResize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;setWindowSize&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;innerWidth&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;innerHeight&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
        &lt;span class="nf"&gt;setVisible&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;setTimeout&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;setVisible&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;500&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="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;resize&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleResize&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="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;resize&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleResize&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, we do not want to add a new timer every time the user resizes the window, so we also need to clean up the timer with &lt;code&gt;clearTimeout(timeoutId)&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;timeoutId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setTimeout&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;setVisible&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To give &lt;code&gt;clearTimeout&lt;/code&gt; the &lt;code&gt;timeoutId&lt;/code&gt; from the last time the function ran, we use &lt;em&gt;closures&lt;/em&gt;, which means that we declare our &lt;code&gt;timeoutId&lt;/code&gt; variable outside the &lt;code&gt;handleResize&lt;/code&gt; function. This way, the variable is still available to the inner function. Every time the function runs, the previous timeout will be cleared and a new one will be set up.&lt;/p&gt;

&lt;p&gt;Lastly, we render our resize function to the browser.The final code can be seen in the screencast.&lt;/p&gt;

&lt;p&gt;Now, whenever the user resizes their window, the window size is set to the current window size, the visibility is set to true, and a timer is started to set the visibility to false after 500 milliseconds.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbg2ir6q0ik2zfrhdh8f0.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbg2ir6q0ik2zfrhdh8f0.png" alt="browser with resize function rendered"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;code&gt;useRef&lt;/code&gt; Challenge
&lt;/h1&gt;

&lt;p&gt;If you need to access to actual DOM elements in React, you may need to use Refs. React has a Hook, &lt;code&gt;useRef&lt;/code&gt;, which is dedicated to Refs.&lt;/p&gt;

&lt;p&gt;To use a Ref, it needs to be added to the element:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;
    &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;inputRef&lt;/span&gt;&lt;span class="p"&gt;}&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;range&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="nx"&gt;onChange&lt;/span&gt;&lt;span class="o"&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="nf"&gt;setCount&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="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This input is a slider which updates the &lt;code&gt;count&lt;/code&gt; and therefore the selected color. As the value is also tied to the count, the slider will also adjust if the count is changed via the buttons we added earlier.&lt;/p&gt;

&lt;p&gt;We have now declared our Ref, but we also need to set it up by calling &lt;code&gt;useRef&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;inputRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In order to focus the input every time we change the count with the buttons, we simply add the necessary logic inside the effect which runs when the buttons are clicked:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="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;setColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;randomColor&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="nx"&gt;inputRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;focus&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fl0gksyz0v6rd5ve9x0pl.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fl0gksyz0v6rd5ve9x0pl.png" alt="Slider in focus"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Currently, the canvas is set to the height of the window itself, which makes it possible for the user to scroll within the canvas, which can lead to empty whitespace if the image is exported.&lt;/p&gt;

&lt;p&gt;Our challenge now is to ensure that the canvas of our paint app is only as big as the window minus the header height. To do this, we need to use useRef to get the height of the header and subtract it from the window's height.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;code&gt;useRef&lt;/code&gt; Solution
&lt;/h1&gt;

&lt;p&gt;In &lt;a href="https://scrimba.com/p/pKkkVU3/c66w99up?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greacthooks_launch_article"&gt;this&lt;/a&gt; screencast Christian walks us through how to get the correct canvas height with &lt;code&gt;useRef&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After this, the user is no longer able to scroll, except for a few pixels offset between Scrimba's browser and a regular browser. There is now no whitespace at the bottom of the image.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;code&gt;useCallback&lt;/code&gt; &amp;amp; &lt;code&gt;useMemo&lt;/code&gt; + Challenge
&lt;/h1&gt;

&lt;p&gt;In this screencast, we are introduced to the concept of _ memoization_. This is when a pure function returns the same output from a calculation it has previous processed, rather than re-running the entire calculation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Calculate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// first call, num === 3... ok I will calculate that&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;fetchComplicatedAlgorithmToAdd47&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns 50 after a while&lt;/span&gt;

    &lt;span class="c1"&gt;// second call, num === 5... ok I guess I have to calculate that too&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;fetchComplicatedAlgorithmToAdd47&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns 52 after a while&lt;/span&gt;

    &lt;span class="c1"&gt;// third call, num === 3... WAIT, I've seen this before! I know this one!&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// immediately&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;React provides two Hooks which allow us to use memoization: &lt;code&gt;useCallback&lt;/code&gt; and &lt;code&gt;useMemo&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;useCallback&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;We start off with a very simple component in Playground.js which renders the number of times the function has rendered:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Calculate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&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;renderCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;renderCount&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ft1l5jq70ub57jb3g1vc0.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ft1l5jq70ub57jb3g1vc0.png" alt="render count in the browser. "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's say that the component should only render when the count changes, but not when the color changes. To achieve this, we could use &lt;code&gt;useCallback&lt;/code&gt;. We assign the result of &lt;code&gt;useCallback&lt;/code&gt; to a variable called &lt;code&gt;calculate&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;calculate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Calculate&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will now render our new &lt;code&gt;calculate&lt;/code&gt; variable instead of the &lt;code&gt;&amp;lt;Calculate /&amp;gt;&lt;/code&gt; component. Now, the component only renders when the count is changed, and not when the 'Change Color' button is clicked.&lt;/p&gt;

&lt;p&gt;We also need to render our &lt;code&gt;&amp;lt;Calculate /&amp;gt;&lt;/code&gt; component instead of the variable we previously used and create a callback function. We use &lt;code&gt;useCallback&lt;/code&gt; and assign it to a variable called &lt;code&gt;cb&lt;/code&gt;. The &lt;code&gt;count&lt;/code&gt; is the only dependency, meaning that if the count changes we will get a new function instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cb&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;num&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;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="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we pass in a number (which is set to the count) to the &lt;code&gt;Calculate&lt;/code&gt; component and the callback function, which we log to the console. Whenever the &lt;code&gt;Calculate&lt;/code&gt; component re-renders (i.e. when the plus and minus buttons are clicked), the current count will be logged to the console.&lt;/p&gt;

&lt;p&gt;However, with this method, the count is also logged to the console when we click the 'Change Color' button. This is because we are using memoization for our &lt;code&gt;console.log&lt;/code&gt; function, but not for our actual component, meaning that is not checking whether the callback function is the same as a previous one.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;React.memo&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;To solve this, we add React.memo to the &lt;code&gt;Calculate&lt;/code&gt; component. Now, it will check the inputs and see whether they are the same, and will not render if so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Calculate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;memo&lt;/span&gt;&lt;span class="p"&gt;(({&lt;/span&gt; &lt;span class="nx"&gt;cb&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;num&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;cb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&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;renderCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;renderCount&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The 'Change Color' button now no longer logs the count to the console.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;useMemo&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;To see what &lt;code&gt;useMemo&lt;/code&gt; can do, we add a &lt;code&gt;useCallback&lt;/code&gt; call right next to a &lt;code&gt;useMemo&lt;/code&gt; call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;useCallback&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;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;useCallback&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nf"&gt;useMemo&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;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;useMemo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells us that &lt;code&gt;useMemo&lt;/code&gt; is used every time the function renders. This is because &lt;code&gt;useCallback&lt;/code&gt; returns the functions, whereas &lt;code&gt;useMemo&lt;/code&gt; returns the result of the function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;useCallback&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;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;useCallback&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// return the function&lt;/span&gt;
&lt;span class="nf"&gt;useMemo&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;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;useMemo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// return the result of the function&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;useMemo&lt;/code&gt; can be used for some expensive functions which you want to memoize. &lt;code&gt;UseCallback&lt;/code&gt;, on the other hand, is better for passing a callback into a component when you don't want to render the component unnecessarily.&lt;/p&gt;

&lt;p&gt;The screencast finishes with a new challenge. Our paint app currently offers only a few colors to work with. Our challenge is to add some functionality to a newly-added refresh button so that the user can click the button and get some new colors. This should take place in &lt;code&gt;RefreshButton.js&lt;/code&gt;, which is currently taking in a callback and should be calling that callback when the refresh button is clicked. Our challenge is to pass in the callback using &lt;code&gt;useCallback&lt;/code&gt; or &lt;code&gt;useMemo&lt;/code&gt;.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3fdokbwtn6h2gr7xwo44.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3fdokbwtn6h2gr7xwo44.png" alt="Refresh button which requires functionality"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a bonus challenge, we are also asked to use &lt;code&gt;React.memo&lt;/code&gt; to memoize the &lt;code&gt;&amp;lt;Name /&amp;gt;&lt;/code&gt; component, which is currently rendering unnecessarily every time we change our colors.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;code&gt;useCallback&lt;/code&gt; Solution
&lt;/h1&gt;

&lt;p&gt;Now, Christian walks us through the solution to the previous challenges, follow him in &lt;a href="https://scrimba.com/p/pKkkVU3/c9PEyQC4?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greacthooks_launch_article"&gt;this&lt;/a&gt; marvellous screencast.&lt;/p&gt;

&lt;p&gt;At the end of the screencast, our refresh button is now supplying shiny new colors when clicked:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fryhwc1o6fcn7liligbhd.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fryhwc1o6fcn7liligbhd.png" alt="Refresh button changing colors - 1"&gt;&lt;/a&gt;&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ft0vnezx4e2fumqq60qeb.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ft0vnezx4e2fumqq60qeb.png" alt="Refresh button changing colors - 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Custom Hooks
&lt;/h1&gt;

&lt;p&gt;Here, we learn about custom Hooks by refactoring the &lt;code&gt;&amp;lt;WindowSize /&amp;gt;&lt;/code&gt; component into a Hook. This is great for reusability.&lt;/p&gt;

&lt;p&gt;Currently, &lt;code&gt;&amp;lt;WindowSize /&amp;gt;&lt;/code&gt; is handling two different sets of state; the window size and visibility. As visibility might not be needed in future uses of &lt;code&gt;&amp;lt;WindowSize /&amp;gt;&lt;/code&gt;, we move its logic into our &lt;code&gt;&amp;lt;Paint /&amp;gt;&lt;/code&gt; component, which is also where we will use our &lt;code&gt;useWindowSize&lt;/code&gt; Hook.&lt;/p&gt;

&lt;p&gt;The following lines are removed from &lt;code&gt;WindowSize.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;timeoutId&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;///&lt;/span&gt;
&lt;span class="nf"&gt;setVisible&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;timeoutId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;timeoutId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setTimeout&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;setVisible&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additionally, the following lines now need to be returned from &lt;code&gt;&amp;lt;Paint.js /&amp;gt;&lt;/code&gt; instead of &lt;code&gt;&amp;lt;WindowSize /&amp;gt;&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`window-size &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;visible&lt;/span&gt; &lt;span class="p"&gt;?&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;hidden&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;windowWidth&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;windowHeight&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The window width and height will be returned from &lt;code&gt;&amp;lt;WindowSize /&amp;gt;&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;windowWidth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;windowHeight&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make the &lt;code&gt;windowWidth&lt;/code&gt; and &lt;code&gt;windowHeight&lt;/code&gt; variables available, we add the following code to &lt;code&gt;&amp;lt;Paint.js /&amp;gt;&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;windowWidth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;windowHeight&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useWindowSize&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To implement the visibility logic so that we can show and hide the window size as necessary, we pass in a callback to our &lt;code&gt;useWindowSize&lt;/code&gt; Hook and use a Ref to make &lt;code&gt;timeoutID&lt;/code&gt; available between renders:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;timeoutId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRef&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;windowWidth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;windowHeight&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useWindowSize&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;setVisible&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;timeoutId&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;timeoutId&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setTimeout&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;setVisible&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can now call this when we need to from &lt;code&gt;&amp;lt;WindowSize /&amp;gt;&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="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="nf"&gt;useWindowSize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cb&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;windowWidth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;windowHeight&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;setWindowSize&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="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerWidth&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;innerHeight&lt;/span&gt;&lt;span class="p"&gt;,&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleResize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nf"&gt;cb&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="nf"&gt;setWindowSize&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;innerWidth&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;innerHeight&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="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;resize&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleResize&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="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;resize&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleResize&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;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;windowWidth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;windowHeight&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We now have the same functionality as before but the &lt;code&gt;&amp;lt;WindowSize /&amp;gt;&lt;/code&gt; logic is in a reusable Hook.&lt;/p&gt;

&lt;p&gt;The lessons ends with another challenge - to convert the &lt;code&gt;&amp;lt;Canvas /&amp;gt;&lt;/code&gt; component into a function which uses Hooks instead of lifecycle methods.&lt;/p&gt;

&lt;h1&gt;
  
  
  Building the paint app with Hooks
&lt;/h1&gt;

&lt;p&gt;This screencast walks us through how to convert &lt;code&gt;&amp;lt;Canvas /&amp;gt;&lt;/code&gt; into a functional component using Hooks. It also shows us how to refactor our app to make it much cleaner and more readable. A big advantage of using Hooks is that all related logic is next to each other, in contrast to our old components in which related logic items were separated from each other.&lt;/p&gt;

&lt;p&gt;At the end of the screencast, our paint app is finally finished and we are ready to paint our masterpieces:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F04cpj3smokmoxf3ivx7f.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F04cpj3smokmoxf3ivx7f.png" alt="using our paint app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Outro
&lt;/h1&gt;

&lt;p&gt;We have now finished the React Hooks course. We have learnt about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;useState&lt;/code&gt;, which manages state&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useEffect&lt;/code&gt;, which does side effects,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useRef&lt;/code&gt;, which gets references to DOM elements and keeps values across renders&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useCallback&lt;/code&gt;, which creates functions which don't need to be created on every render&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useMemo&lt;/code&gt;, which memoizes expensive computations&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;React.Memo&lt;/code&gt;, which can go around a React component and memoize it&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;custom Hooks&lt;/code&gt;, which allow us to create our own reusable logic.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are two rules to keep in mind when using any of these Hooks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Only call Hooks at the top level of the React component, i.e. not within if blocks or anything similar.&lt;/li&gt;
&lt;li&gt;Only call Hooks from React functions, not your own custom functions.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Congratulations on following the tutorial and learning all the skills used in this project. To further your learning, check out Scrimba's free, six-hour &lt;a href="https://scrimba.com/course/glearnreact?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greacthooks_launch_article"&gt;Learn React for Free&lt;/a&gt; course which aims to make you a React wizard!&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>react</category>
      <category>reacthooks</category>
      <category>scrimba</category>
    </item>
    <item>
      <title>Build Tic-Tac-Toe with React Hooks</title>
      <dc:creator>Per</dc:creator>
      <pubDate>Fri, 29 May 2020 13:50:16 +0000</pubDate>
      <link>https://forem.com/scrimba/build-tic-tac-toe-with-react-hooks-2e6k</link>
      <guid>https://forem.com/scrimba/build-tic-tac-toe-with-react-hooks-2e6k</guid>
      <description>&lt;p&gt;If you have a good understanding of HTML, CSS, JavaScript, and React and are wondering where to go next on your learning journey, why not check out &lt;a href="https://scrimba.com/course/greactgame?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;Scrimba's brand new, free tutorial&lt;/a&gt; on how to build the classic Tic Tac Toe game in React?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/course/greactgame?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&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%2Fxtcbjygjr8s9in2u3nnv.png" alt="Fully working game"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Click above to go to the tutorial.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The example game is pulled from React's official tutorials but is brought bang up to date using React hooks - the latest hot topic in the React world. This article gives you an overview of the tutorial and lets you click through to the screencasts and play with the code at any time.&lt;/p&gt;

&lt;p&gt;If your HTML, CSS, JavaScript or React skills feel shaky, never fear - Scrimba offers a huge range of tutorials to bring you up to speed. We recommend the following courses to get you ready for the Tic Tac Toe tutorial:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://scrimba.com/course/ghtmlcss?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;HTML &amp;amp; CSS Crash Course&lt;/a&gt; with Kevin Powell&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://scrimba.com/course/gintrotojavascript?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;Introduction to Javascript&lt;/a&gt; with Dylan C. Israel&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://scrimba.com/course/glearnreact?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;Learn React for Free&lt;/a&gt; with Bob Ziroll&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In true Scrimba style, the Build Tic Tac Toe with React Hooks tutorial contains loads of interactive challenges along the way, so you'll embed your learning and feel like a hooks wizard by the end of it.&lt;/p&gt;

&lt;p&gt;The course is led by Thomas Weibenfalk, a passionate developer, designer, and coding instructor from Sweden. Thomas loves teaching people about front-end development, especially React, making him the ideal teacher to take you through this learning experience.&lt;/p&gt;

&lt;p&gt;Assuming you're ready to go with Tic Tac Toe, let's get started!&lt;/p&gt;
&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pgGEGtW/cPkGD8Sm?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&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%2Fe9mee46gi4pz43um8h1t.png" alt="Tic Tac Toe with React hooks slide"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://scrimba.com/p/pgGEGtW/cPkGD8Sm?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;the first scrim&lt;/a&gt;, Thomas tells us about his plans for the tutorial and shares the &lt;a href="https://reactjs.org/tutorial/tutorial.html" rel="noopener noreferrer"&gt;Official React Documentation&lt;/a&gt;, which we can refer to for a more detailed explanation of the features used to build the game.&lt;/p&gt;

&lt;p&gt;As well as talking us through the file structure he has implemented for the app, Thomas also gives us our first glimpse of the finished product. Click the image above to visit the cast.&lt;/p&gt;
&lt;h2&gt;
  
  
  Scaffolding Components
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pgGEGtW/cV8eB8fp?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;Next up&lt;/a&gt;, Thomas talks us through setting up the Board.js, Game.js and Square.js files needed to create the game. We also see how to import Game.js into the App.js file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Game&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;./components/Game&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Game&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;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;h2&gt;
  
  
  Square Component and Destructuring Props
&lt;/h2&gt;

&lt;p&gt;In &lt;a href="https://scrimba.com/p/pgGEGtW/cKp4eRfq?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;the next scrim&lt;/a&gt;, we create our square component using JSX to add a button:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Square&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For our first challenge, Thomas encourages us to destructure out the props in our component. &lt;a href="https://scrimba.com/p/pgGEGtW/cKp4eRfq?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;Click through&lt;/a&gt; to the cast to give the challenge a try.&lt;/p&gt;

&lt;h2&gt;
  
  
  Board Component and Scaffolding Functions
&lt;/h2&gt;

&lt;p&gt;Now it's time to create &lt;a href="https://scrimba.com/p/pgGEGtW/cypaG6CZ?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;the board component&lt;/a&gt; by importing the square component and adding nine instances of it to the board (note that we will refactor this with a loop to improve the code later):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Square&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dummy value&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Square&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dummy value&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Square&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dummy value&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Square&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;4&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dummy value&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Square&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;5&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dummy value&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Square&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;6&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dummy value&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Square&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;7&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dummy value&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Square&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;8&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dummy value&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Square&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;9&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dummy value&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&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;Thomas also scaffolds out the functions we need in Game.js, which we'll complete later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Square Styling
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pgGEGtW/ceMPzwhB?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&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%2F2zhixfxneekxecwxi2vn.png" alt="app with styled squares"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Click the image to access the cast.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pgGEGtW/ceMPzwhB?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;Next up&lt;/a&gt;, we style our squares using the &lt;code&gt;style&lt;/code&gt; default prop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lightblue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2px solid darkblue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;fontSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;30px&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;fontWeight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;800&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;pointer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;outline&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;none&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Square&lt;/span&gt; &lt;span class="o"&gt;=&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;onClick&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;onClick&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;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Board Styling
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pgGEGtW/c8rJyKcD?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&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%2Fynvasbhvjvj5kr9g5fe4.png" alt="app with styled board"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Click the image to access the scrim.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now that our squares are ready, it's time to the &lt;a href="https://scrimba.com/p/pgGEGtW/c8rJyKcD?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;style the board&lt;/a&gt;. Thomas kicks us off by once again creating a style object, this time with CSS grid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;4px solid darkblue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;borderRadius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10px&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;250px&lt;/span&gt;&lt;span class="dl"&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;250px&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0 auto&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;grid&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;gridTemplate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;repeat(3, 1fr) / repeat(3, 1fr)&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;Our challenge now is to apply the style object to the board. Head over &lt;a href="https://scrimba.com/p/pgGEGtW/c8rJyKcD?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;to the scrim&lt;/a&gt; to give it a try.&lt;/p&gt;

&lt;p&gt;Don't forget, while Thomas has provided some great styling options, Scrimba is fully interactive, so you are free to customize your game however you prefer - let your imagination run wild!&lt;/p&gt;

&lt;h2&gt;
  
  
  The calculateWinner Function Explained
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculateWinner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;squares&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;lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;],&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="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;],&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="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;squares&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;squares&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;squares&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;squares&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;squares&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;squares&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&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;return&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://scrimba.com/p/pgGEGtW/cBLrMvS2?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;Next up&lt;/a&gt;, Thomas explains the all-important &lt;code&gt;calculateWinner()&lt;/code&gt; function, which is taken from the original tutorial from &lt;a href="https://reactjs.org/tutorial/tutorial.html" rel="noopener noreferrer"&gt;reactjs.org&lt;/a&gt;. Head over &lt;a href="https://scrimba.com/p/pgGEGtW/cBLrMvS2?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;to the cast&lt;/a&gt; to explore the function and hear how it works.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create States and Fill with Initial Data
&lt;/h2&gt;

&lt;p&gt;In the next &lt;a href="https://scrimba.com/p/pgGEGtW/c4Pw97tV?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;scrim&lt;/a&gt;, we start creating the logic for the game.&lt;/p&gt;

&lt;p&gt;We begin by adding a hook called &lt;code&gt;usedState&lt;/code&gt; in Game.js and creating states to set an empty board and specify the next player. Lastly, we add &lt;code&gt;const winner&lt;/code&gt;, which tells us whether the latest move was a winning one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;board&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setBoard&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="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;fill&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;xIsNext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setXisNext&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="kc"&gt;true&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;winner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculateWinner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;board&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Over in Board.js, we delete our manually-rendered squares and replace them with mapped squares as promised earlier. &lt;a href="https://scrimba.com/p/pgGEGtW/c4Pw97tV?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;Click through&lt;/a&gt; to see this in detail:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Board&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;squares&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;onClick&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;style&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;squares&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;square&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Square&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;square&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="p"&gt;))}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create the handleClick Function
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pgGEGtW/c67knwTy?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;Next&lt;/a&gt;, we create the &lt;code&gt;handleClick()&lt;/code&gt; function, which carries out the calculations when we make a move:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleClick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;boardCopy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;board&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="c1"&gt;// If user click an occupied square or if game is won, return&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;winner&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;boardCopy&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&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="c1"&gt;// Put an X or an O in the clicked square&lt;/span&gt;
    &lt;span class="nx"&gt;boardCopy&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;xIsNext&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;X&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;O&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;setBoard&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;boardCopy&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;setXisNext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;xIsNext&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  renderMoves Function and the Last JSX
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pgGEGtW/cNq2EQAL?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&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%2Fxtcbjygjr8s9in2u3nnv.png" alt="Fully working game"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Click above to go to the tutorial.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pgGEGtW/cNq2EQAL?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;In this scrim&lt;/a&gt;, we create the JSX which makes the game playable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Board&lt;/span&gt; &lt;span class="nx"&gt;squares&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;board&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleClick&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&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;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;winner&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Winner: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;winner&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Next Player: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;xIsNext&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;X&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;O&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&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;We now have the all knowledge needed to create a fully working Tic Tac Toe game with React hooks!&lt;/p&gt;

&lt;h2&gt;
  
  
  BONUS: Implement Time Travel
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pgGEGtW/cBLr6Df6?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&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%2Fmyoj1edcpkv3gx0ry7xj.png" alt="Time travel feature in action"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Click the image to go to the bonus tutorial.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pgGEGtW/cBLr6Df6?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;In the bonus scrim&lt;/a&gt;, we take our game to the next level by implementing time travel to review the moves made throughout the game. Click through to get the goodies in this bonus tutorial.&lt;/p&gt;

&lt;p&gt;So there we have it - a fully working Tic Tac Toe game using React hooks! I hope you found this tutorial helpful. Don't forget, you can refer back to it at any time to refresh your memory of the topics covered or play around with the code in the interactive screencasts.&lt;/p&gt;

&lt;p&gt;If you feel that this Tic Tac Toe tutorial was a bit over your level, you can start our with our &lt;a href="https://scrimba.com/learn/learnreact?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=greactgame_launch_article"&gt;free Learn React Course&lt;/a&gt;. It'll ensure that you have the basics in place before tackling more complex React tutorials.&lt;/p&gt;

&lt;p&gt;Happy learning :)&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Z5RbPrK4VqM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>react</category>
      <category>reacthooks</category>
      <category>scrimba</category>
    </item>
    <item>
      <title>Want to learn Vuetify? Here's our free 15-part course by Gwen Faraday</title>
      <dc:creator>Per</dc:creator>
      <pubDate>Tue, 26 May 2020 09:37:17 +0000</pubDate>
      <link>https://forem.com/scrimba/want-to-learn-vuetify-here-s-our-free-15-part-course-by-gwen-faraday-231o</link>
      <guid>https://forem.com/scrimba/want-to-learn-vuetify-here-s-our-free-15-part-course-by-gwen-faraday-231o</guid>
      <description>&lt;p&gt;If you love building apps in Vue.js but struggle to know where to start with UI design, look no further than Vuetify - a UI library containing handcrafted material components which give apps a beautiful finish and professional feel.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why learn Vuetify?
&lt;/h2&gt;

&lt;p&gt;Vuetify is the most popular component library for Vue.js, enabling you to create great-looking, accessible apps even if UI design isn't your area. While the library has over 80 elements ready to use straight out the box, it also allows you to create custom elements, giving your apps a clean yet bespoke feel.&lt;/p&gt;

&lt;p&gt;This article takes you through Scrimba's free &lt;a href="https://scrimba.com/course/gvuetify?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;two-hour Vuetify course&lt;/a&gt; by Gwen Faraday. The course teaches you all the core skills needed to get started with Vuetify, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Typography&lt;/li&gt;
&lt;li&gt;Spacing&lt;/li&gt;
&lt;li&gt;Buttons&lt;/li&gt;
&lt;li&gt;Navigation&lt;/li&gt;
&lt;li&gt;Grid&lt;/li&gt;
&lt;li&gt;Card&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the first half, Gwen introduces all the Vuetify elements needed to build a great app. As with all Scrimba courses, you can pause the scrims and explore the code.&lt;/p&gt;

&lt;p&gt;The second half lets you get your hands dirty by building a webshop. This puts your new skills to good use and lets you apply your newfound knowledge.&lt;/p&gt;

&lt;p&gt;By the end, you'll be fully versed in building professionally-styled apps with Vuetify.&lt;/p&gt;

&lt;h2&gt;
  
  
  Intro to the Instructor
&lt;/h2&gt;

&lt;p&gt;Gwen Faraday is a software engineer, author, speaker, and &amp;amp; content creator who also runs a Youtube channel, &lt;a href="https://www.youtube.com/channel/UCxA99Yr6P_tZF9_BgtMGAWA/featured"&gt;the Faraday Academy&lt;/a&gt;, where she teaches a wide range of subjects including Vue.js and Vuetify. This makes her the perfect teacher to take you through this learning journey and bring your Vuetify skills to the next level.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;To learn the most from this tutorial, you'll need a decent understanding of HTML, CSS, Javascript and Vue.js. If you're not there yet, check out Scrimba's great free courses to get you up to speed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://scrimba.com/course/ghtmlcss?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;HTML and CSS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://scrimba.com/course/gintrotojavascript?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;Javascript&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://scrimba.com/course/glearnvue?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;Vue.js&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you’re ready to hit the ground running with Vuetify, let’s get into it!&lt;/p&gt;

&lt;h2&gt;
  
  
  Intro to Vuetify
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pP4xZu3/cEKyEkuB?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;In the first cast&lt;/a&gt;, Gwen introduces us to Vuetify and shares the two Github repositories where she has stored all the code, &lt;a href="https://github.com/gwenf/vuetify-basic-components"&gt;basic-components&lt;/a&gt; and &lt;a href="https://github.com/gwenf/vuetify-responsive"&gt;vuetify-responsive&lt;/a&gt;. This allows us to download the code and try it out for ourselves.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Material Design?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pP4xZu3/c4PDDZtg?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;Next up&lt;/a&gt;, we learn about Material Design, a standard developed by Google for implementing accessible, user-friendly interfaces.&lt;/p&gt;

&lt;p&gt;The Material Standard provides a set of rules for the most common elements found on web pages including buttons, text, navigation and more advanced features such as movement and elevation.&lt;/p&gt;

&lt;p&gt;Vuetify takes the hard work out of implementing this standard by providing a bunch of ready-made compliant UI elements which we can add to our Vue.js application straight out the box.&lt;/p&gt;

&lt;h2&gt;
  
  
  First Look at Vuetify Code
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pP4xZu3/ckPbepSM?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;In the next cast&lt;/a&gt;, Gwen gives us our first look at Vuetify code by instantiating a Vue application, adding a Vuetify property and creating a new Vuetify object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;el&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;vuetify&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vuetify&lt;/span&gt;&lt;span class="p"&gt;({}),&lt;/span&gt;
    &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Using Single File Components&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, Gwen shows us the &lt;code&gt;&amp;lt;v-app&amp;gt;&lt;/code&gt; element, which is the root component of all Vuetify elements (Vuetify components must fall within &lt;code&gt;&amp;lt;v-app&amp;gt;&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;v-app&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;v-content&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;playground&amp;gt;&amp;lt;/playground&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/v-content&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/v-app&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Typography
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pP4xZu3/cMqPmeTG?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YbHwJBa1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lrmuhh5orzx32c4jdlsd.png" alt="Vuetify typography"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Click the image to access the course.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://scrimba.com/p/pP4xZu3/cMqPmeTG?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;the next scrim&lt;/a&gt;, we see some of the options Vuetify offers to handle typography, including headings, titles, subtitles and body text. We also see how to change text color and background color.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;v-card-text&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"display-4 purple yellow--text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Heading 1&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;h2&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"display-3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Heading 2&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;h3&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"display-2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Heading 3&lt;span class="nt"&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;h4&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Title&lt;span class="nt"&gt;&amp;lt;/h4&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;h5&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"subtitle-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Subtitle&lt;span class="nt"&gt;&amp;lt;/h5&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"body-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Body&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/v-card-text&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, we see how to use Vuetify classes to adjust font weight and style:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"font-italic font-weight-light"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Heading 1&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Vuetify classes override any other styles that the browser applies to HTML tags.&lt;/p&gt;

&lt;h2&gt;
  
  
  Spacing
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pP4xZu3/cD7pnzSw?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;Next up&lt;/a&gt;, we explore some of the spacing classes in Vuetify, which allow us to add margins and padding. We also see how to change spacing size.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h3&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"ml-5"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Spacing&lt;span class="nt"&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Best of all, Gwen also shows us how Vuetify classes can help with that holy grail of app styling - centering an element! Click through to the course to find out more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Buttons
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pP4xZu3/crmrBwtP?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--khlhK0dq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ollkzqisck44bqdnc1r9.png" alt="Vuetify buttons"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Click the image to access the course.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;a href="https://scrimba.com/p/pP4xZu3/crmrBwtP?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;next scrim&lt;/a&gt;, we look at some of the options available with Vuetify's button component, including buttons with text, icons or both.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;v-btn&lt;/span&gt; &lt;span class="na"&gt;large&lt;/span&gt; &lt;span class="na"&gt;block&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="nt"&gt;&amp;lt;/v-btn&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lastly, we look at how to build custom buttons using classes from earlier.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;v-ripple&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"elevation-2 py-2 px-4"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
     Submit
&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Navigation
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pP4xZu3/czkwwQCw?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xTetNj8s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/je40l0odaw1l68pi8a71.png" alt="Vuetify navigation"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Click the image to access the course.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pP4xZu3/czkwwQCw?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;Next up&lt;/a&gt;, we look at the two main navigation options available in Vuetify,&lt;code&gt;&amp;lt;v-app-bar&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;v-toolbar&amp;gt;&lt;/code&gt;. Both navigation elements provide automatic button and icon sizing, navigation icons and the ability to handle list dropdowns.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;v-toolbar&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"deep-purple accent-4"&lt;/span&gt; &lt;span class="na"&gt;dense&lt;/span&gt; &lt;span class="na"&gt;dark&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;v-app-bar-nav-icon&amp;gt;&amp;lt;/v-app-bar-nav-icon&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;v-toolbar-title&amp;gt;&lt;/span&gt;App Title&lt;span class="nt"&gt;&amp;lt;/v-toolbar-title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/v-toolbar&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://scrimba.com/p/pP4xZu3/czkwwQCw?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;Click through&lt;/a&gt; to see all this in action!&lt;/p&gt;

&lt;h2&gt;
  
  
  Grid
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pP4xZu3/cWKBnPSV?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UAZ12Pha--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/hddtxtqh91j6z9gjb1up.png" alt="Vuetify grid"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Click the image to access the course.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://scrimba.com/p/pP4xZu3/cWKBnPSV?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;the next scrim&lt;/a&gt;, Gwen takes us through Vuetify's grid system, which is split into 12 columns, with five built-in media breakpoints for handling different screen sizes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;v-row&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;v-col&lt;/span&gt; &lt;span class="na"&gt;cols=&lt;/span&gt;&lt;span class="s"&gt;"12"&lt;/span&gt; &lt;span class="na"&gt;sm=&lt;/span&gt;&lt;span class="s"&gt;"6"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;v-card&lt;/span&gt;
        &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"pa-2"&lt;/span&gt;
        &lt;span class="na"&gt;outlined&lt;/span&gt;
        &lt;span class="na"&gt;tile&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        Column
        &lt;span class="nt"&gt;&amp;lt;/v-card&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/v-col&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/v-row&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Card
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pP4xZu3/cdNW42t8?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rBk67ShQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dbh0863c4we6t4sncpf2.png" alt="Vuetify card"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Click the image to access the course.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://scrimba.com/p/pP4xZu3/cdNW42t8?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;this cast&lt;/a&gt;, Gwen explains that Vuetify uses a &lt;code&gt;&amp;lt;v-card&amp;gt;&lt;/code&gt; component as the wrapper for any UI card. This component can take props, classes and slots and has custom events, allowing for neat, well-aligned cards in any use case.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt; &lt;span class="nt"&gt;&amp;lt;v-card-title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;v-icon&lt;/span&gt;
        &lt;span class="na"&gt;large&lt;/span&gt;
        &lt;span class="na"&gt;left&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        mdi-twitter
    &lt;span class="nt"&gt;&amp;lt;/v-icon&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/v-card-title&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;v-card-text&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"headline font-weight-bold"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    "Vue Rocks!"
    &lt;span class="nt"&gt;&amp;lt;/v-card-text&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/v-card&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Gwen also introduces us to the &lt;code&gt;&amp;lt;v-spacer&amp;gt;&lt;/code&gt; element, which lets us easily add whitespace between elements.&lt;/p&gt;

&lt;p&gt;Finally, we check out the &lt;code&gt;Playground.vue&lt;/code&gt; file - a space for us to explore the features of Vuetify Gwen has shown us so far. Head over &lt;a href="https://scrimba.com/p/pP4xZu3/cdNW42t8?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;to the course&lt;/a&gt; to try it out for yourself and see what Vuetify can do.&lt;/p&gt;

&lt;h2&gt;
  
  
  Store Navigation
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pP4xZu3/cMZMQbu9?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bfhAKq7G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tc2s63qss1f3tc7vyyhu.png" alt="Vuetify web store navigation"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Click the image to access the course.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pP4xZu3/cMZMQbu9?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;Next&lt;/a&gt;, it's time to start building our store application. Gwen starts us off by adding a navigation bar including responsiveness and a drawer menu. We also run through some options for styling, including icons and a dense menu.&lt;/p&gt;
&lt;h2&gt;
  
  
  Home Page
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pP4xZu3/c33vv6fz?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;Next up&lt;/a&gt;, it's time to add a home page. Gwen adds the header and a footer and then sets us the challenge of coding the mid-section using the mock-ups provided. Head over &lt;a href="https://scrimba.com/p/pP4xZu3/c33vv6fz?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;to the screencast&lt;/a&gt; to test out your new Vuetify skills and compare your work to Gwen's solution.&lt;/p&gt;

&lt;p&gt;To finish off, Gwen shows us the &lt;code&gt;&amp;lt;v-snackbar&amp;gt;&lt;/code&gt; element, which can be used to notify a user when a product has been added to the cart.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;v-snackbar&lt;/span&gt;
    &lt;span class="na"&gt;v-model=&lt;/span&gt;&lt;span class="s"&gt;"$store.state.snackbar.show"&lt;/span&gt;
    &lt;span class="na"&gt;:multi-line=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;
    &lt;span class="na"&gt;:right=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;
    &lt;span class="na"&gt;:top=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;
    &lt;span class="na"&gt;:timeout=&lt;/span&gt;&lt;span class="s"&gt;"6000"&lt;/span&gt;
    &lt;span class="na"&gt;:color=&lt;/span&gt;&lt;span class="s"&gt;"$store.state.snackbar.variant"&lt;/span&gt;
&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    {{ $store.state.snackbar.message }}
    &lt;span class="nt"&gt;&amp;lt;v-btn&lt;/span&gt;
    &lt;span class="na"&gt;dark&lt;/span&gt;
    &lt;span class="na"&gt;text&lt;/span&gt;
    &lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="na"&gt;click=&lt;/span&gt;&lt;span class="s"&gt;"$store.commit('updateSnackbar', { show: false })"&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Close
    &lt;span class="nt"&gt;&amp;lt;/v-btn&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/v-snackbar&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Store Page
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pP4xZu3/cvdrn6Ar?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4Knac8XQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/m1d909j9guwo0q1da9jj.png" alt="Vuetify web store page"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Click the image to access the course.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pP4xZu3/cvdrn6Ar?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;In the next Scrim&lt;/a&gt; we build out our store page using Vuetify grid elements. First up, we add product cards by reusing the cards we built for our home page. Next, Gwen challenges us to build out a sidebar with the &lt;code&gt;&amp;lt;v-sheet&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;v-expansion-panels&amp;gt;&lt;/code&gt; elements.&lt;/p&gt;

&lt;p&gt;Head over &lt;a href="https://scrimba.com/p/pP4xZu3/cvdrn6Ar?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;to the cast&lt;/a&gt; to give the challenge a try.&lt;/p&gt;
&lt;h2&gt;
  
  
  Cart Page
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pP4xZu3/caZyp7um?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Nqzuhoqa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/drbsnxpy6p95kzj3aph5.png" alt="Vuetify cart page"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Click the image to access the course.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://scrimba.com/p/pP4xZu3/caZyp7um?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;Next up&lt;/a&gt;, we add a cart page to our app. Once again, Gwen sets us the challenge of coding out the page as per her mock-ups, which is great practice for real-world coding and flexes the muscle memory needed to become a Vuetify wizard.&lt;/p&gt;

&lt;p&gt;Click through to give the challenge your best shot before comparing your work with Gwen's final code. Don't forget, you can always look back at the previous scrims or check out the Vuetify docs if you're having trouble.&lt;/p&gt;
&lt;h2&gt;
  
  
  Checkout Screen
&lt;/h2&gt;

&lt;p&gt;In the final code scrim, we build a simple checkout flow using the &lt;code&gt;&amp;lt;v-stepper&amp;gt;&lt;/code&gt; element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;v-stepper-header&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;v-stepper-step&lt;/span&gt;
        &lt;span class="na"&gt;step=&lt;/span&gt;&lt;span class="s"&gt;"1"&lt;/span&gt;
        &lt;span class="na"&gt;:complete=&lt;/span&gt;&lt;span class="s"&gt;"step &amp;gt; 1"&lt;/span&gt;
    &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;v-divider&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;v-stepper-step&lt;/span&gt;
        &lt;span class="na"&gt;step=&lt;/span&gt;&lt;span class="s"&gt;"2"&lt;/span&gt;
        &lt;span class="na"&gt;:complete=&lt;/span&gt;&lt;span class="s"&gt;"step &amp;gt; 2"&lt;/span&gt;
    &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;v-divider&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;v-stepper-step&lt;/span&gt;
        &lt;span class="na"&gt;step=&lt;/span&gt;&lt;span class="s"&gt;"3"&lt;/span&gt;
    &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/v-stepper-header&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To finish the course, Gwen points out that there are a few features in the mockups which we haven't covered and encourages us to have a go at coding them ourselves using Scrimba's interactive interface.&lt;/p&gt;

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

&lt;p&gt;A huge well done for completing the course! I hope you've found it useful and now have the confidence to build stunning apps using Vuetify. Why not continue your learning journey by checking out the huge range of other topics available over at &lt;a href="https://scrimba.com/?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;Scrimba&lt;/a&gt;?&lt;/p&gt;

&lt;p&gt;If you don't know where to start, you can check out our &lt;a href="https://scrimba.com/learn/learnreact?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=gvuetify_launch_article"&gt;Learn React for Free&lt;/a&gt; course with Bob Ziroll.&lt;/p&gt;

&lt;p&gt;Wherever you go next, happy coding :)&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/rJIRv-_oYnA"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>vuetify</category>
      <category>vue</category>
      <category>scrimba</category>
    </item>
  </channel>
</rss>
