<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Scrimba - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Scrimba - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Wed, 06 May 2026 17:00:44 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/scrimba/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Algorithms in Javascript - Binary Search Explained ]]>
                </title>
                <description>
                    <![CDATA[ By Per Harald Borgen If you want to gain new problem-solving skills and level up your Computer Science knowledge, look no further than Scrimba's free one-hour course, The Working Developer's Guide To Algorithms. It was designed for those who don't ha... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/the-working-developers-guide-to-algorithms/</link>
                <guid isPermaLink="false">66d8525bc1d58e16fbe2b425</guid>
                
                    <category>
                        <![CDATA[ algorithms ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Computer Science ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Scrimba ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 15 Jun 2020 09:44:40 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/05/Screenshot-2020-05-19-at-15.25.42.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Per Harald Borgen</p>
<p>If you want to gain new problem-solving skills and level up your Computer Science knowledge, look no further than Scrimba's free one-hour course, <a target="_blank" href="https://scrimba.com/course/galgorithmsguide?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=galgorithmsguide_launch_article">The Working Developer's Guide To Algorithms</a>. It was designed for those who don't have a background in Computer Science and feel they would benefit from learning to think algorithmically.</p>
<h2 id="heading-what-does-the-course-do">What does the course do?</h2>
<p>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.</p>
<p>You'll learn:</p>
<ul>
<li>Binary Search</li>
<li>Big O notation</li>
<li>Imperative code</li>
<li>Recursion</li>
<li>Tail recursion</li>
<li>Array splitting</li>
<li>Array view</li>
<li>Partition</li>
</ul>
<p>Each algorithm is taught in three stages:</p>
<ul>
<li><strong>Walkthrough:</strong> Jonathan introduces the algorithm conceptually.</li>
<li><strong>Implementation:</strong> We get our hands dirty by crafting our own versions of the algorithm.</li>
<li><strong>Solution:</strong> Jonathan shows us his implementation for comparison.</li>
</ul>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>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. </p>
<p>If you're not there yet, check out Scrimba's great free tutorials <a target="_blank" href="https://scrimba.com/course/gintrotojavascript?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=galgorithmsguide_launch_article">Introduction to JavaScript</a> and <a target="_blank" href="https://scrimba.com/course/gintrotoes6?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=galgorithmsguide_launch_article">Introduction to ES6+</a>.</p>
<h2 id="heading-intro-to-the-instructor">Intro to the instructor</h2>
<p>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. </p>
<p>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!</p>
<h2 id="heading-binary-search">Binary Search</h2>
<p><a target="_blank" href="https://scrimba.com/p/pk57XHz/cPJqarfK?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=galgorithmsguide_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/iphh9m8t8a0jgq94w926.png" alt="Graph of Sweeper vs Splitter searches." width="664" height="379" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p>In <a target="_blank" href="https://scrimba.com/p/pk57XHz/cPJqarfK?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=galgorithmsguide_launch_article">the first cast</a>, Jonathan introduces to the concepts of <strong>Big-O notation</strong> and <strong>binary search</strong>, the algorithm we'll be working with.</p>
<p><strong>Big-O notation</strong> 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.</p>
<p><strong>Binary search</strong> is one of several strategies for answering the question "Where does this element appear in a list?"</p>
<p>When answering the question, there are two main approaches:</p>
<ul>
<li><strong>Sweeper</strong>: Checking through each item in the list until the correct item is found.</li>
<li><strong>Splitter</strong> / <strong>Binary Search</strong>: 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.</li>
</ul>
<p>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. 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.</p>
<p>Binary Search is more efficient than the sweeper approach, particularly for larger lists. But it only works when the list has already been sorted. </p>
<p>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).</p>
<h2 id="heading-imperative">Imperative</h2>
<p><a target="_blank" href="https://scrimba.com/p/pk57XHz/czkBGrtD?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=galgorithmsguide_launch_article">In the first challenge cast</a>, 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.</p>
<p>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.</p>
<p>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...</p>
<h2 id="heading-recursion">Recursion</h2>
<p><a target="_blank" href="https://scrimba.com/p/pk57XHz/c2Pr87c4?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=galgorithmsguide_launch_article">In this cast</a>, 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 <code>const</code> operator so they can't be mutated.</p>
<p>Jonanthan kicks us off with a skeleton version of the solution and then encourages us to try the challenge on our own:</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> binarySearchWithRecursion = <span class="hljs-function">(<span class="hljs-params">array, element, compare = defaultCompare</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-number">-1</span>;
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> binarySearchWithRecursion;
</code></pre>
<p>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...</p>
<h2 id="heading-tail-recursion">Tail Recursion</h2>
<p>The challenge for <a target="_blank" href="https://scrimba.com/p/pk57XHz/ceMQgZTB?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=galgorithmsguide_launch_article">the next cast</a> is to improve our previous implementation by reducing duplication.</p>
<p>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.</p>
<h2 id="heading-array-splitting">Array Splitting</h2>
<p>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. <a target="_blank" href="https://scrimba.com/p/pk57XHz/cEKyndHw?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=galgorithmsguide_launch_article">This cast</a> looks at a way of cleaning that up called <strong>array splitting</strong>.</p>
<p>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.</p>
<p>To help us achieve this, Jonathan starts us off with some skeleton code:</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> binarySearchWithArraySplitting = <span class="hljs-function">(<span class="hljs-params">
    array,
    element,
    compare = defaultCompare
</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-number">-1</span>;
};
</code></pre>
<p>Then, as usual, he gives us free rein to try to the solution for ourselves before walking us through his own implementation.</p>
<p>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...</p>
<h2 id="heading-array-view">Array View</h2>
<p><a target="_blank" href="https://scrimba.com/p/pk57XHz/cmdvdnhb?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=galgorithmsguide_launch_article">In this cast</a>, 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.</p>
<p>Jonathan gets us started by initializing a function <code>ArrayView</code> which returns an object that expects three arguments: <code>array</code>, <code>start</code> and <code>end</code>. When invoked, <code>ArrayView</code> should return an object with four methods, <code>length</code>, <code>toArray</code>, <code>slice</code> and <code>get</code>.</p>
<pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-keyword">let</span> ArrayView = <span class="hljs-function">(<span class="hljs-params">
    array,
    start = <span class="hljs-number">0</span>,
    end = array.length,
</span>) =&gt;</span> ({
    <span class="hljs-attr">length</span>: end - start,
    <span class="hljs-attr">toArray</span>: <span class="hljs-function">() =&gt;</span> array.slice(start, end),
    <span class="hljs-attr">slice</span>: <span class="hljs-function">() =&gt;</span> ,
    get: <span class="hljs-function">() =&gt;</span> ,
});

<span class="hljs-keyword">let</span> binarySearchWithArrayView = <span class="hljs-function">(<span class="hljs-params">array, ...args</span>) =&gt;</span>
    binarySearchWithArraySplitting(ArrayView(array), ...args)
</code></pre>
<p>Our challenge is to implement the <code>slice</code> and <code>get</code> methods of <code>ArrayView</code> without making a copy of the original array. Click through to try it out and then view Jonathan's walkthrough.</p>
<p>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 <code>ArrayView</code> while lifting even more of the logic out of binary search code...</p>
<h2 id="heading-array-partition">Array Partition</h2>
<p>In <a target="_blank" href="https://scrimba.com/p/pk57XHz/c8rZqEsV?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=galgorithmsguide_launch_article">the final challenge cast</a> of the course, Jonathan gives us a goal of extracting some of the cryptic bounce logic in our previous version into a data structure.</p>
<p>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 <code>ArrayPartition</code>:</p>
<pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-keyword">let</span> ArrayPartition = <span class="hljs-function">(<span class="hljs-params">array, pivot</span>) =&gt;</span> ({
    <span class="hljs-attr">left</span>: <span class="hljs-function">() =&gt;</span> array.slice(<span class="hljs-number">0</span>, pivot),
    <span class="hljs-attr">middle</span>: <span class="hljs-function">() =&gt;</span> array.get(pivot),
    <span class="hljs-attr">right</span>: <span class="hljs-function">() =&gt;</span> array.slice(pivot + <span class="hljs-number">1</span>, array.length),
});
</code></pre>
<p>Next, Jonathan sets up a new version of binary search called <code>binarySearchWithPartition</code>, which has a starting signature the same as <code>binarySearchWithArraySplitting</code>:</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> binarySearchWithPartition = <span class="hljs-function">(<span class="hljs-params">array, element, compare = defaultCompare</span>) =&gt;</span> {
    <span class="hljs-keyword">if</span> (array.length === <span class="hljs-number">0</span>) {
        <span class="hljs-keyword">return</span> <span class="hljs-number">-1</span>;
    }
    <span class="hljs-keyword">const</span> middle = <span class="hljs-built_in">Math</span>.floor(array.length / <span class="hljs-number">2</span>);
    <span class="hljs-keyword">const</span> comparison = compare(element, array.get(middle));

    <span class="hljs-keyword">if</span> (comparison === <span class="hljs-number">0</span>) {
        <span class="hljs-keyword">return</span> middle;
    }

    <span class="hljs-comment">//bounce logic</span>
    <span class="hljs-keyword">const</span> [left, right] =
        comparison === <span class="hljs-number">-1</span> ? [<span class="hljs-number">0</span>, middle - <span class="hljs-number">1</span>] : [middle + <span class="hljs-number">1</span>, array.length];
    <span class="hljs-comment">//end of bounce logic</span>

    <span class="hljs-keyword">const</span> subIndex = binarySearchWithArraySplitting(
        array.slice(left, right),
        element,
        compare
    );

    <span class="hljs-keyword">return</span> subIndex === <span class="hljs-number">-1</span> ? <span class="hljs-number">-1</span> : left + subIndex;
};

<span class="hljs-keyword">let</span> binarySearchWithPartitionAndView = <span class="hljs-function">(<span class="hljs-params">array, ...args</span>) =&gt;</span>
    binarySearchWithPartition(ArrayView(array), ...args);
</code></pre>
<p>Our challenge now is to rewrite <code>binarySearchWithPartition</code> with none of the <code>bounce</code> logic highlighted above, instead of creating an array partition and making calls to its left, middle and right methods.</p>
<p>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.</p>
<h2 id="heading-wrap-up">Wrap-Up</h2>
<p>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 we've built some great muscle memory for working effectively with algorithms. </p>
<p>Now that you've seen six different approaches to binary search, you'll probably notice it pop up in many different places in programming.</p>
<p>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.</p>
<p>Happy coding :)</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/v684EuCrPAM" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Learn Vuetify in 5 Minutes ]]>
                </title>
                <description>
                    <![CDATA[ By Leanne Rybintsev Welcome to a whistle-stop tour of Vuetify - a popular component library for Vue.js. It allows you to create attractive, accessible apps with 80 elements ready to use from the get-go, plus it gives you the option to customize eleme... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-vuetify-in-5-minutes/</link>
                <guid isPermaLink="false">66d46016d1ffc3d3eb89de1e</guid>
                
                    <category>
                        <![CDATA[ Scrimba ]]>
                    </category>
                
                    <category>
                        <![CDATA[ vue ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Vuetify ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 12 Jun 2020 16:38:26 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/06/Screenshot-2020-06-12-at-17.19.31--2-.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Leanne Rybintsev</p>
<p>Welcome to a whistle-stop tour of Vuetify - a popular component library for Vue.js. It allows you to create attractive, accessible apps with 80 elements ready to use from the get-go, plus it gives you the option to customize elements for a bespoke design.</p>
<p>In the next five minutes, I'll you show you the following hot Vuetify elements:</p>
<ul>
<li>Typography</li>
<li>Spacing</li>
<li>Buttons</li>
<li>Navigation</li>
<li>Grid</li>
<li>Card</li>
</ul>
<p>And by the end of this article, you'll feel confident in making stunning apps with just a few lines of code.</p>
<p>While reading, head over to <a target="_blank" href="https://scrimba.com/course/gvuetify?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_5_minute_article">Scrimba's 2-hour Vuetify course</a> to find out more and explore the code in the platform's interactive playground. Plus you can test your new skills with some interactive coding challenges. Let's get started!</p>
<h2 id="heading-creating-a-vuetify-object">Creating a Vuetify object</h2>
<p>To use Vuetify, we first pull in Vue and Vuetify from their CDNS. </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<p>This allows us to instantiate a Vue application with a Vuetify property and create a new Vuetify object:</p>
<pre><code class="lang-js"><span class="hljs-keyword">new</span> Vue({ 
    <span class="hljs-attr">el</span>: <span class="hljs-string">'#app'</span>,
    <span class="hljs-attr">vuetify</span>: <span class="hljs-keyword">new</span> Vuetify({}),
    <span class="hljs-attr">data</span>: {
        <span class="hljs-attr">message</span>: <span class="hljs-string">'Using Single File Components'</span>
    }
});
</code></pre>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/ckPbepSM?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_5_minute_article">Click through</a> to see this in detail. </p>
<h2 id="heading-typography">Typography</h2>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/cMqPmeTG?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_5_minute_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/uey76nlf4hxjttq9krzh.png" alt="Vuetify typography" width="600" height="400" loading="lazy"></a>
<em>Click the image to go to the cast.</em></p>
<p>Vuetify provides plenty of options for creating stunning typography, from headings of various sizes, to titles, subtitles and body text:</p>
<pre><code class="lang-vue">&lt;h1 class="display-4"&gt;Heading 1&lt;/h1&gt;
&lt;h2 class="display-3"&gt;Heading 2&lt;/h2&gt;
&lt;h3 class="display-2"&gt;Heading 3&lt;/h3&gt;
&lt;h4 class="title"&gt;Title&lt;/h4&gt;
&lt;h5 class="subtitle-1"&gt;Subtitle&lt;/h5&gt;
&lt;p class="body-1"&gt;Body&lt;/p&gt;
</code></pre>
<p>Changing text color and background color is easy with Vuetify, too. For the background color, simply add the name of the required color to the element's class. For text color, just add the color name followed by <code>--text</code>. </p>
<p>This works for around 20 standard colors and can be customized using accompanying classes such as <code>lighten</code> and <code>darken</code>.</p>
<pre><code class="lang-vue">&lt;h1 class="display-4 purple yellow--text text--darken-2"&gt;Heading 1&lt;/h1&gt;
</code></pre>
<p>Vuetify also offers classes to change the font weight and style, as well as truncate and transform text. <a target="_blank" href="https://scrimba.com/p/pP4xZu3/cMqPmeTG?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_5_minute_article">Head over to the cast</a> to find out more. </p>
<h2 id="heading-spacing">Spacing</h2>
<p>Anyone who's ever used CSS knows that margins and padding can be tricky. Not with Vuetify! To add and adjust the spacing between elements, simply use classes with the following abbreviations:</p>
<p><code>m</code> = margin
<code>p</code> = padding
<code>t</code> = top
<code>r</code> = right
<code>b</code> = bottom
<code>l</code> = left
<code>x</code> = right + left
<code>y</code> = top + bottom
<code>a</code> = all </p>
<p>Spacing size is adjusted using the numbers 1 to 12, which correspond to four-pixel increments. For example <code>ml-5</code> denotes a left margin of 20 pixels. </p>
<pre><code class="lang-vue">&lt;h3 class="ml-5"&gt;Spacing&lt;/h3&gt;
</code></pre>
<p>Centering elements is also easy with Vuetify. Simply wrap the element in a container that spans the page, then give it a right and left margin of <code>auto</code>:</p>
<pre><code class="lang-vue">&lt;v-row&gt;
     &lt;h3 class="mx-auto"&gt;Spacing&lt;/h3&gt;
&lt;/v-row&gt;
</code></pre>
<p>That's not the end of Vuetify's handy tips and tricks for element spacing. <a target="_blank" href="https://scrimba.com/p/pP4xZu3/cD7pnzSw?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_5_minute_article">Click through</a> to the cast to see more!</p>
<h2 id="heading-buttons">Buttons</h2>
<p>Vuetify offers dozens of options for styling buttons, including regular clickable buttons, outline buttons with ready-positioned icons, and icon-only buttons. </p>
<p>Keeping reading to see some of the options available straight out the box, or <a target="_blank" href="https://scrimba.com/p/pP4xZu3/crmrBwtP?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_5_minute_article">click through</a> to see how to customize buttons. </p>
<p><strong>Large outline button:</strong></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/uobelihs9l8ab86duimx.png" alt="Large outline button" width="600" height="400" loading="lazy"></p>
<pre><code class="lang-vue">&lt;v-btn large outlined&gt;Submit&lt;/v-btn&gt;
</code></pre>
<p><strong>Button with icon:</strong></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/zbs74uvuqnyfyrg529yq.png" alt="Button with icon" width="600" height="400" loading="lazy"></p>
<pre><code class="lang-vue">&lt;v-btn tile outlined color="success"&gt;
     &lt;v-icon left&gt;mdi-pencil&lt;/v-icon&gt; Edit
&lt;/v-btn&gt;
</code></pre>
<p><strong>Floating action icon button:</strong>
<img src="https://dev-to-uploads.s3.amazonaws.com/i/39p0zcaeyr8plveu2tjj.png" alt="Floating action button with icon" width="600" height="400" loading="lazy"></p>
<pre><code class="lang-vue">&lt;v-btn class="mx-2" fab dark color="indigo"&gt;
     &lt;v-icon dark&gt;mdi-plus&lt;/v-icon&gt;
&lt;/v-btn&gt;
</code></pre>
<h2 id="heading-navigation">Navigation</h2>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/czkwwQCw?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_5_minute_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/z4iz7cjvdttvdk31227f.png" alt="Vuetify navigation bar" width="600" height="400" loading="lazy"></a>
<em>Click the image to go the cast.</em></p>
<p>The two main navigation options available in Vuetify are <code>&lt;v-app-bar&gt;</code> and <code>&lt;v-toolbar&gt;</code>. </p>
<pre><code class="lang-vue">&lt;v-app-bar
     color="deep-purple accent-4"
     dense
     dark
&gt;
</code></pre>
<p>Although the two elements are interchangeable to some extent, <code>&lt;v-app-bar&gt;</code> is designed for use as a site's main navigation and includes features such as scroll animations and a range of props and options. </p>
<p><code>&lt;v-toolbar&gt;</code> is a smaller, more versatile component which is designed to provide functionality to other areas of an app. For instance, it could be used for the basic edit features on a small text editor.</p>
<p>Both navigation elements handle list drop-downs and automatically size navigation icons and buttons. </p>
<h2 id="heading-grid">Grid</h2>
<p>Vuetify has a built-in grid system which makes sizing and positioning elements in an app simpler than ever. The grid is split into 12 columns and has five media breakpoints for handling a variety of screen sizes.</p>
<p>While the default width of an element is 12 columns, it's easy to adjust this by changing the column value. For example, an item with a column value of 6 takes up half the page width. Items can be positioned using the <code>offset</code> property. </p>
<pre><code class="lang-vue">&lt;v-col sm="6" offset-sm="3"&gt;
    &lt;v-card
    class="pa-2"
    outlined
    tile
    &gt;
    Column
    &lt;/v-card&gt;
&lt;/v-col&gt;
</code></pre>
<p>Columns in Vuetify come with pre-set spacing. <a target="_blank" href="https://scrimba.com/p/pP4xZu3/cWKBnPSV?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_5_minute_article">Click through</a> to the scrim to see how this affects the element and how to customize it. </p>
<h2 id="heading-card">Card</h2>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/cdNW42t8?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_5_minute_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/mvxtqa1l2dfze9mu8acv.png" alt="Customised Vuetify card" width="600" height="400" loading="lazy"></a>
<em>Click the card to access the scrim.</em></p>
<p>Adding cards to your app is simple with Vuetify's <code>&lt;v-card&gt;</code> element, which is easily customisable with its four optional nested elements: <code>&lt;v-card-title&gt;</code>, <code>&lt;v-card-text&gt;</code>, <code>&lt;v-card-actions&gt;</code> and <code>&lt;v-list-item-content&gt;</code>. </p>
<p>I've played around with the card provided <a target="_blank" href="https://scrimba.com/p/pP4xZu3/cdNW42t8?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_5_minute_article">in the cast</a> to make my own Coffee Card. Why not head over and see where your imagination takes you, too?</p>
<pre><code class="lang-vue"> &lt;v-card class="mx-auto" color="brown" dark &gt;
    &lt;v-card-title&gt;
    &lt;v-icon large left&gt; mdi-coffee&lt;/v-icon&gt;
    &lt;span class="title font-weight-light"&gt;Coffee Card&lt;/span&gt;
    &lt;/v-card-title&gt;

    &lt;v-card-text class="headline font-weight-bold"&gt;"Coffee Rocks!"&lt;/v-card-text&gt;

    &lt;v-card-actions&gt;
    &lt;v-list-item class="grow"&gt;
        &lt;v-list-item-content&gt;
        &lt;v-list-item-title&gt;Miss C Bean&lt;/v-list-item-title&gt;
        &lt;/v-list-item-content&gt;

        &lt;/v-row&gt;
    &lt;/v-list-item&gt;
    &lt;/v-card-actions&gt;
&lt;/v-card&gt;
</code></pre>
<p>That's all for our hyper-speed tour of Vuetify's basic functions. To explore further, head over <a target="_blank" href="https://scrimba.com/p/pP4xZu3/cdNW42t8?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_5_minute_article">to the course</a> and check out the Playground.vue file, where you can test out the code and see more of what it can do.</p>
<p>The course also includes a bunch of interactive challenges to put your newfound knowledge to the test and get you well on your way to becoming a Vuetify pro. When you're done there, why not check out <a target="_blank" href="https://scrimba.com/?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_5_minute_article">Scrimba's</a> huge range of other topics to continue your learning journey? </p>
<p>Whatever you choose to do next, happy coding :) </p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Learn React Hooks by Building a Paint App ]]>
                </title>
                <description>
                    <![CDATA[ By Per Harald Borgen According to people in the know, React Hooks are hot, hot, hot. In this article, we follow Christian Jensen's 14-part tutorial to find out about the basics of this new feature of React. Follow along to find out more! Intro Hook... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-react-hooks-by-building-a-paint-app/</link>
                <guid isPermaLink="false">66d8524662a291dea8987903</guid>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ react hooks ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Scrimba ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 05 Jun 2020 17:04:06 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/06/hooks-logo.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Per Harald Borgen</p>
<p>According to people in the know, React Hooks are hot, hot, hot. In this article, we follow Christian Jensen's <a target="_blank" href="https://scrimba.com/g/greacthooks?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greacthooks_launch_article">14-part tutorial</a> to find out about the basics of this new feature of React. Follow along to find out more!</p>
<p><img src="https://thepracticaldev.s3.amazonaws.com/i/mh1hdo0zzhtgei8gv614.png" alt="React Hooks we will learn in this course" width="677" height="365" loading="lazy"></p>
<h1 id="heading-intro">Intro</h1>
<p><img src="https://thepracticaldev.s3.amazonaws.com/i/1j9osq1fshioocmoo0v4.png" alt="Paint app we will build during this project" width="630" height="395" loading="lazy"></p>
<p>Hooks are new to the React library and allow us to share logic between components and make them reusable.</p>
<p>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.</p>
<p>Scrimba allows you to pause screencasts at any time and play with the code. It's a great way to learn by doing!</p>
<h1 id="heading-prerequisites">Prerequisites</h1>
<p>The course assumes some <a target="_blank" href="https://www.freecodecamp.org/news/learn-modern-javascript-in-this-free-28-part-course-7ec8d353eb/">prior knowledge of ES6</a>, <a target="_blank" href="https://www.freecodecamp.org/news/learn-react-js-in-5-minutes-526472d292f4/">JSX, State and Props</a>, but no worries, we've got you covered - check out our Scrimba articles by hitting the links above.</p>
<p>If you are completely new to React, be sure to check out our <a target="_blank" href="https://scrimba.com/g/glearnreact?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greacthooks_launch_article">Scrimba React course</a></p>
<h1 id="heading-usestate-part-1"><code>useState</code> - Part 1</h1>
<p>First, we give our application a way to manage state using <code>useState</code>.</p>
<p>In our <code>&lt;Playground.js /&gt;</code> component, we declare a component called <code>&lt;Playground /&gt;</code> and create buttons to increment and decrement it. We then give <code>useState</code> an argument of (0) and use state restructuring to get <code>state</code> and <code>setState</code> (the function which updates the state) from our <code>useState</code> function. These are now renamed to <code>count</code> and <code>setCount</code>. We then render our count in the browser.</p>
<p>Lastly, we render buttons which update the count using an inline function which will be triggered on the click.</p>
<p><img src="https://thepracticaldev.s3.amazonaws.com/i/kohiz9hz2f49n5i80l71.png" alt="Incrementing count with our buttons" width="300" height="100" loading="lazy"></p>
<p>To ensure our count is accurate, we pass a function to our <code>setState</code> function instead of a value. This function takes the current state as its argument, which is then updated:</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React, { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> randomColor <span class="hljs-keyword">from</span> <span class="hljs-string">"randomcolor"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Playground</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> [count, setCount] = useState(<span class="hljs-number">0</span>);
    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
            {count}
            <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> setCount((currentCount) =&gt; currentCount - 1)}&gt;
                -
            <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> setCount((currentCount) =&gt; currentCount + 1)}&gt;
                +
            <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
    );
}
</code></pre>
<p>If you're worried about the performance of inline functions, take a look a <a target="_blank" href="https://cdb.reacttraining.com/react-inline-functions-and-performance-bdff784f5578">this</a> blog.</p>
<h1 id="heading-usestate-part-2"><code>useState</code> - Part 2</h1>
<p>Now we add our name input to the <code>&lt;Name.js /&gt;</code> component so the user can name their project.</p>
<p>To set up<code>&lt;Name.js /&gt;</code> with a <code>useState</code> Hook, we need to import the Hook with a named import and then set our state up. Our state will be <code>name</code> and we will update it with setName. We then call <code>useState</code> and pass in an empty string as our default state value.</p>
<p>We now need an input element with four properties. These are:</p>
<ul>
<li><code>value</code>, which will always be the state <code>name</code> from above</li>
<li><code>onChange</code>, which will use <code>setState</code> inline to update <code>name</code> by passing the value into <code>setState</code></li>
<li><code>onClick</code> 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.</li>
<li><code>placeholder</code>, which we set to 'Untitled'.</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React, { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Name</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> [name, setName] = useState(<span class="hljs-string">""</span>);
    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"header-name"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">input</span>
                <span class="hljs-attr">value</span>=<span class="hljs-string">{name}</span>
                <span class="hljs-attr">onChange</span>=<span class="hljs-string">{(e)</span> =&gt;</span> setName(e.target.value)}
                onClick={(e) =&gt; e.target.setSelectionRange(0, e.target.value.length)}
                placeholder="Untitled"
            /&gt;
        <span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span></span>
    );
}
</code></pre>
<p>We can now name our project and select the name to reset it with just one click:</p>
<p><img src="https://thepracticaldev.s3.amazonaws.com/i/rgupvtuwliarlt2woyrj.png" alt="Project's name input in action." width="482" height="84" loading="lazy"></p>
<h1 id="heading-useeffect"><code>useEffect</code></h1>
<p>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.</p>
<p>We use the <code>useState</code> Hook to set up the initial color, which we set to <code>null</code> and the function to update it (<code>setColor</code>). Now, we set up <code>useEffect</code> to update this color. <code>useEffect</code>'s first argument is setColor, which we want to set to a <code>randomColor</code>.</p>
<p>As we only want a change in <code>count</code> to trigger <code>useEffect</code>, 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.</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React, { useState, useEffect } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> randomColor <span class="hljs-keyword">from</span> <span class="hljs-string">"randomcolor"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Playground</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> [count, setCount] = useState(<span class="hljs-number">0</span>);

    <span class="hljs-keyword">const</span> [color, setColor] = useState(<span class="hljs-literal">null</span>);
    useEffect(<span class="hljs-function">() =&gt;</span> {
        setColor(randomColor());
    }, [count]);

    <span class="hljs-keyword">return</span> (
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{{</span> <span class="hljs-attr">borderTop:</span> `<span class="hljs-attr">10px</span> <span class="hljs-attr">solid</span> ${<span class="hljs-attr">color</span>}` }}&gt;</span>
            {count}
            <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> setCount((currentCount) =&gt; currentCount - 1)}&gt;
                -
            <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> setCount((currentCount) =&gt; currentCount + 1)}&gt;
                +
            <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
    );
}
</code></pre>
<p>Now, our color changes every time we increment or decrement our count.</p>
<p><img src="https://thepracticaldev.s3.amazonaws.com/i/6b6n7h96pkk89llw6abi.png" alt="initial color" width="300" height="180" loading="lazy"></p>
<p><img src="https://thepracticaldev.s3.amazonaws.com/i/vawilltd0p7mu15lwa1d.png" alt="color changed by one increment" width="300" height="180" loading="lazy"></p>
<p><img src="https://thepracticaldev.s3.amazonaws.com/i/sq1ouu7f3d7u26kuov3f.png" alt="color changed by a second increment" width="300" height="181" loading="lazy"></p>
<p><img src="https://thepracticaldev.s3.amazonaws.com/i/f2paopu37b35ojior8s7.png" alt="color changed by one decrement" width="300" height="180" loading="lazy"></p>
<h1 id="heading-usestate-amp-useeffect-challenge"><code>useState</code> &amp; <code>useEffect</code> Challenge</h1>
<p>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 :</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> getColors = <span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">const</span> baseColor = randomColor().slice(<span class="hljs-number">1</span>);
    fetch(<span class="hljs-string">`https://www.thecolorapi.com/scheme?hex=<span class="hljs-subst">${baseColor}</span>&amp;mode=monochrome`</span>)
        .then(<span class="hljs-function">(<span class="hljs-params">res</span>) =&gt;</span> res.json())
        .then(<span class="hljs-function">(<span class="hljs-params">res</span>) =&gt;</span> {
            setColors(res.colors.map(<span class="hljs-function">(<span class="hljs-params">color</span>) =&gt;</span> color.hex.value));
            setActiveColor(res.colors[<span class="hljs-number">0</span>].hex.value);
        });
};
</code></pre>
<p>Our task is to write the functions for <code>setColors</code>, which will give us an array of hex colors and <code>setActiveColor</code>, which will tell use what the active color is.</p>
<p>If we set up everything correctly, the UI will update with five colors which we can click on to expand. We only need <code>useState</code> and <code>useEffect</code> for this test.</p>
<p>#<code>useState</code> &amp; <code>useEffect</code> Solution#</p>
<p>In <a target="_blank" href="https://scrimba.com/p/pKkkVU3/cDbkNJsg?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greacthooks_launch_article">this</a> screencast, Christian walks us through how to give functionality to the <code>&lt;ColorPicker /&gt;</code> component. At the end of it, we now have some colors:</p>
<p><img src="https://thepracticaldev.s3.amazonaws.com/i/rxe2h70fqoldqf6ouoss.png" alt="colors visible in UI" width="300" height="180" loading="lazy"></p>
<h1 id="heading-useeffect-clean-up"><code>useEffect</code> Clean Up</h1>
<p>Now we add a component called <code>&lt;WindowSize.js /&gt;</code> 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.</p>
<p>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 <code>&lt;WindowSize /&gt;</code> component:</p>
<pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">WindowSize</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> [[windowWidth, windowHeight], setWindowSize] = useState([
        <span class="hljs-built_in">window</span>.innerWidth,
        <span class="hljs-built_in">window</span>.innerHeight,
    ]);
    <span class="hljs-keyword">const</span> [visible, setVisible] = useState(<span class="hljs-literal">false</span>);
}
</code></pre>
<p>Now we set up our effect, which adds the event listener:</p>
<pre><code class="lang-js">useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">const</span> handleResize = <span class="hljs-function">() =&gt;</span> {};
    <span class="hljs-built_in">window</span>.addEventListener(<span class="hljs-string">"resize"</span>, handleResize);
});
</code></pre>
<p>Next, we set up the cleanup phase. This returns the function and an empty array is passed in to tell it that <code>useEffect</code> should only run on the first mount. The cleanup will then run and remove the event listener:</p>
<pre><code class="lang-js">useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">const</span> handleResize = <span class="hljs-function">() =&gt;</span> {};
    <span class="hljs-built_in">window</span>.addEventListener(<span class="hljs-string">"resize"</span>, handleResize);
    <span class="hljs-keyword">return</span> <span class="hljs-function">() =&gt;</span> <span class="hljs-built_in">window</span>.removeEventListener(<span class="hljs-string">"resize"</span>, handleResize);
}, []);
</code></pre>
<p>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:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> [visible, setVisible] = useState(<span class="hljs-literal">false</span>);
useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">const</span> handleResize = <span class="hljs-function">() =&gt;</span> {
        setWindowSize([<span class="hljs-built_in">window</span>.innerWidth, <span class="hljs-built_in">window</span>.innerHeight]);
        setVisible(<span class="hljs-literal">true</span>);
        <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =&gt;</span> setVisible(<span class="hljs-literal">false</span>), <span class="hljs-number">500</span>);
    };
    <span class="hljs-built_in">window</span>.addEventListener(<span class="hljs-string">"resize"</span>, handleResize);
    <span class="hljs-keyword">return</span> <span class="hljs-function">() =&gt;</span> <span class="hljs-built_in">window</span>.removeEventListener(<span class="hljs-string">"resize"</span>, handleResize);
}, []);
</code></pre>
<p>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 <code>clearTimeout(timeoutId)</code>:</p>
<pre><code class="lang-js">timeoutId = <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =&gt;</span> setVisible(<span class="hljs-literal">false</span>), <span class="hljs-number">500</span>);
</code></pre>
<p>To give <code>clearTimeout</code> the <code>timeoutId</code> from the last time the function ran, we use <em>closures</em>, which means that we declare our <code>timeoutId</code> variable outside the <code>handleResize</code> 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.</p>
<p>Lastly, we render our resize function to the browser.The final code can be seen in the screencast.</p>
<p>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.</p>
<p><img src="https://thepracticaldev.s3.amazonaws.com/i/bg2ir6q0ik2zfrhdh8f0.png" alt="browser with resize function rendered" width="401" height="446" loading="lazy"></p>
<h1 id="heading-useref-challenge"><code>useRef</code> Challenge</h1>
<p>If you need to access to actual DOM elements in React, you may need to use Refs. React has a Hook, <code>useRef</code>, which is dedicated to Refs.</p>
<p>To use a Ref, it needs to be added to the element:</p>
<pre><code class="lang-js">&lt;input
    ref={inputRef}
    type=<span class="hljs-string">"range"</span>
    onChange={<span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> setCount(e.target.value)}
    value={count}
/&gt;
</code></pre>
<p>This input is a slider which updates the <code>count</code> 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.</p>
<p>We have now declared our Ref, but we also need to set it up by calling <code>useRef</code>:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> inputRef = useRef();
</code></pre>
<p>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:</p>
<pre><code class="lang-js"> useEffect(<span class="hljs-function">() =&gt;</span> {
    setColor(randomColor())
    inputRef.current.focus()
  },
</code></pre>
<p><img src="https://thepracticaldev.s3.amazonaws.com/i/l0gksyz0v6rd5ve9x0pl.png" alt="Slider in focus" width="683" height="157" loading="lazy"></p>
<p>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.</p>
<p>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.</p>
<h1 id="heading-useref-solution"><code>useRef</code> Solution</h1>
<p>In <a target="_blank" href="https://scrimba.com/p/pKkkVU3/c66w99up?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greacthooks_launch_article">this</a> screencast Christian walks us through how to get the correct canvas height with <code>useRef</code>.</p>
<p>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.</p>
<h1 id="heading-usecallback-amp-usememo-challenge"><code>useCallback</code> &amp; <code>useMemo</code> + Challenge</h1>
<p>In this screencast, we are introduced to the concept of <em> memoization</em>. This is when a pure function returns the same output from a calculation it has previous processed, rather than re-running the entire calculation:</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Calculate</span>(<span class="hljs-params">num</span>) </span>{
    <span class="hljs-comment">// first call, num === 3... ok I will calculate that</span>
    <span class="hljs-keyword">return</span> fetchComplicatedAlgorithmToAdd47(<span class="hljs-number">3</span>); <span class="hljs-comment">// returns 50 after a while</span>

    <span class="hljs-comment">// second call, num === 5... ok I guess I have to calculate that too</span>
    <span class="hljs-keyword">return</span> fetchComplicatedAlgorithmToAdd47(<span class="hljs-number">5</span>); <span class="hljs-comment">// returns 52 after a while</span>

    <span class="hljs-comment">// third call, num === 3... WAIT, I've seen this before! I know this one!</span>
    <span class="hljs-keyword">return</span> <span class="hljs-number">50</span>; <span class="hljs-comment">// immediately</span>
}
</code></pre>
<p>React provides two Hooks which allow us to use memoization: <code>useCallback</code> and <code>useMemo</code>.</p>
<p>###<code>useCallback</code>###</p>
<p>We start off with a very simple component in Playground.js which renders the number of times the function has rendered:</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Calculate</span>(<span class="hljs-params">num</span>) </span>{
    <span class="hljs-keyword">const</span> renderCount = useRef(<span class="hljs-number">1</span>);
    <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>{renderCount.current++}<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>;
}
</code></pre>
<p><img src="https://thepracticaldev.s3.amazonaws.com/i/t1l5jq70ub57jb3g1vc0.png" alt="render count in the browser. " width="685" height="134" loading="lazy"></p>
<p>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 <code>useCallback</code>. We assign the result of <code>useCallback</code> to a variable called <code>calculate</code>:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> calculate = useCallback(<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Calculate</span> /&gt;</span></span>, [count]);
</code></pre>
<p>We will now render our new <code>calculate</code> variable instead of the <code>&lt;Calculate /&gt;</code> component. Now, the component only renders when the count is changed, and not when the 'Change Color' button is clicked.</p>
<p>We also need to render our <code>&lt;Calculate /&gt;</code> component instead of the variable we previously used and create a callback function. We use <code>useCallback</code> and assign it to a variable called <code>cb</code>. The <code>count</code> is the only dependency, meaning that if the count changes we will get a new function instance:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> cb = useCallback(<span class="hljs-function">(<span class="hljs-params">num</span>) =&gt;</span> <span class="hljs-built_in">console</span>.log(num), [count]);
</code></pre>
<p>Now we pass in a number (which is set to the count) to the <code>Calculate</code> component and the callback function, which we log to the console. Whenever the <code>Calculate</code> component re-renders (i.e. when the plus and minus buttons are clicked), the current count will be logged to the console.</p>
<p>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 <code>console.log</code> function, but not for our actual component, meaning that is not checking whether the callback function is the same as a previous one.</p>
<h3 id="heading-reactmemo"><code>React.memo</code></h3>
<p>To solve this, we add React.memo to the <code>Calculate</code> component. Now, it will check the inputs and see whether they are the same, and will not render if so:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> Calculate = React.memo(<span class="hljs-function">(<span class="hljs-params">{ cb, num }</span>) =&gt;</span> {
    cb(num);
    <span class="hljs-keyword">const</span> renderCount = useRef(<span class="hljs-number">1</span>);
    <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>{renderCount.current++}<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>;
});
</code></pre>
<p>The 'Change Color' button now no longer logs the count to the console.</p>
<p>###<code>useMemo</code>###
To see what <code>useMemo</code> can do, we add a <code>useCallback</code> call right next to a <code>useMemo</code> call:</p>
<pre><code class="lang-js">useCallback(<span class="hljs-function">() =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"useCallback"</span>));
useMemo(<span class="hljs-function">() =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"useMemo"</span>));
</code></pre>
<p>This tells us that <code>useMemo</code> is used every time the function renders. This is because <code>useCallback</code> returns the functions, whereas <code>useMemo</code> returns the result of the function:</p>
<pre><code class="lang-js">useCallback(<span class="hljs-function">() =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"useCallback"</span>)); <span class="hljs-comment">// return the function</span>
useMemo(<span class="hljs-function">() =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"useMemo"</span>)); <span class="hljs-comment">// return the result of the function</span>
</code></pre>
<p><code>useMemo</code> can be used for some expensive functions which you want to memoize. <code>UseCallback</code>, on the other hand, is better for passing a callback into a component when you don't want to render the component unnecessarily.</p>
<p>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 <code>RefreshButton.js</code>, 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 <code>useCallback</code> or <code>useMemo</code>.</p>
<p><img src="https://thepracticaldev.s3.amazonaws.com/i/3fdokbwtn6h2gr7xwo44.png" alt="Refresh button which requires functionality" width="679" height="179" loading="lazy"></p>
<p>As a bonus challenge, we are also asked to use <code>React.memo</code> to memoize the <code>&lt;Name /&gt;</code> component, which is currently rendering unnecessarily every time we change our colors.</p>
<h1 id="heading-usecallback-solution"><code>useCallback</code> Solution</h1>
<p>Now, Christian walks us through the solution to the previous challenges, follow him in <a target="_blank" href="https://scrimba.com/p/pKkkVU3/c9PEyQC4?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greacthooks_launch_article">this</a> marvellous screencast.</p>
<p>At the end of the screencast, our refresh button is now supplying shiny new colors when clicked:</p>
<p><img src="https://thepracticaldev.s3.amazonaws.com/i/ryhwc1o6fcn7liligbhd.png" alt="Refresh button changing colors - 1" width="683" height="160" loading="lazy"></p>
<p><img src="https://thepracticaldev.s3.amazonaws.com/i/t0vnezx4e2fumqq60qeb.png" alt="Refresh button changing colors - 2" width="681" height="162" loading="lazy"></p>
<h1 id="heading-custom-hooks">Custom Hooks</h1>
<p>Here, we learn about custom Hooks by refactoring the <code>&lt;WindowSize /&gt;</code> component into a Hook. This is great for reusability.</p>
<p>Currently, <code>&lt;WindowSize /&gt;</code> is handling two different sets of state; the window size and visibility. As visibility might not be needed in future uses of <code>&lt;WindowSize /&gt;</code>, we move its logic into our <code>&lt;Paint /&gt;</code> component, which is also where we will use our <code>useWindowSize</code> Hook.</p>
<p>The following lines are removed from <code>WindowSize.js</code>:</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> timeoutId;
<span class="hljs-comment">///</span>
setVisible(<span class="hljs-literal">true</span>);
<span class="hljs-built_in">clearTimeout</span>(timeoutId);
timeoutId = <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =&gt;</span> setVisible(<span class="hljs-literal">false</span>), <span class="hljs-number">500</span>);
</code></pre>
<p>Additionally, the following lines now need to be returned from <code>&lt;Paint.js /&gt;</code> instead of <code>&lt;WindowSize /&gt;</code>:</p>
<pre><code class="lang-js">&lt;div className={<span class="hljs-string">`window-size <span class="hljs-subst">${visible ? <span class="hljs-string">""</span> : <span class="hljs-string">"hidden"</span>}</span>`</span>}&gt;
    {windowWidth} x {windowHeight}
&lt;/div&gt;
</code></pre>
<p>The window width and height will be returned from <code>&lt;WindowSize /&gt;</code>:</p>
<pre><code class="lang-js"><span class="hljs-keyword">return</span> [windowWidth, windowHeight];
</code></pre>
<p>To make the <code>windowWidth</code> and <code>windowHeight</code> variables available, we add the following code to <code>&lt;Paint.js /&gt;</code>:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> [windowWidth, windowHeight] = useWindowSize();
</code></pre>
<p>To implement the visibility logic so that we can show and hide the window size as necessary, we pass in a callback to our <code>useWindowSize</code> Hook and use a Ref to make <code>timeoutID</code> available between renders:</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> timeoutId = useRef();
<span class="hljs-keyword">const</span> [windowWidth, windowHeight] = useWindowSize(<span class="hljs-function">() =&gt;</span> {
    setVisible(<span class="hljs-literal">true</span>);
    <span class="hljs-built_in">clearTimeout</span>(timeoutId.current);
    timeoutId.current = <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =&gt;</span> setVisible(<span class="hljs-literal">false</span>), <span class="hljs-number">500</span>);
});
</code></pre>
<p>We can now call this when we need to from <code>&lt;WindowSize /&gt;</code>:</p>
<pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">useWindowSize</span>(<span class="hljs-params">cb</span>) </span>{
    <span class="hljs-keyword">const</span> [[windowWidth, windowHeight], setWindowSize] = useState([
        <span class="hljs-built_in">window</span>.innerWidth,
        <span class="hljs-built_in">window</span>.innerHeight,
    ]);

    useEffect(<span class="hljs-function">() =&gt;</span> {
        <span class="hljs-keyword">const</span> handleResize = <span class="hljs-function">() =&gt;</span> {
            cb();
            setWindowSize([<span class="hljs-built_in">window</span>.innerWidth, <span class="hljs-built_in">window</span>.innerHeight]);
        };
        <span class="hljs-built_in">window</span>.addEventListener(<span class="hljs-string">"resize"</span>, handleResize);
        <span class="hljs-keyword">return</span> <span class="hljs-function">() =&gt;</span> <span class="hljs-built_in">window</span>.removeEventListener(<span class="hljs-string">"resize"</span>, handleResize);
    }, []);
    <span class="hljs-keyword">return</span> [windowWidth, windowHeight];
}
</code></pre>
<p>We now have the same functionality as before but the <code>&lt;WindowSize /&gt;</code> logic is in a reusable Hook.</p>
<p>The lessons ends with another challenge - to convert the <code>&lt;Canvas /&gt;</code> component into a function which uses Hooks instead of lifecycle methods.</p>
<h1 id="heading-building-the-paint-app-with-hooks">Building the paint app with Hooks</h1>
<p>This screencast walks us through how to convert <code>&lt;Canvas /&gt;</code> 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.</p>
<p>At the end of the screencast, our paint app is finally finished and we are ready to paint our masterpieces:</p>
<p><img src="https://thepracticaldev.s3.amazonaws.com/i/04cpj3smokmoxf3ivx7f.png" alt="using our paint app" width="487" height="256" loading="lazy"></p>
<h1 id="heading-outro">Outro</h1>
<p>We have now finished the React Hooks course. We have learnt about:</p>
<ul>
<li><code>useState</code>, which manages state</li>
<li><code>useEffect</code>, which does side effects,</li>
<li><code>useRef</code>, which gets references to DOM elements and keeps values across renders</li>
<li><code>useCallback</code>, which creates functions which don't need to be created on every render</li>
<li><code>useMemo</code>, which memoizes expensive computations</li>
<li><code>React.Memo</code>, which can go around a React component and memoize it</li>
<li><code>custom Hooks</code>, which allow us to create our own reusable logic.</li>
</ul>
<p>There are two rules to keep in mind when using any of these Hooks:</p>
<ol>
<li>Only call Hooks at the top level of the React component, i.e. not within if blocks or anything similar.</li>
<li>Only call Hooks from React functions, not your own custom functions.</li>
</ol>
<p>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 <a target="_blank" href="https://scrimba.com/course/glearnreact?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greacthooks_launch_article">Learn React for Free</a> course which aims to make you a React wizard!</p>
<p>Happy coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Learn How to Build Tic-Tac-Toe with React Hooks ]]>
                </title>
                <description>
                    <![CDATA[ By Per Harald Borgen If you have a good understanding of HTML, CSS, JavaScript, and React you might be wondering where to go next on your learning journey. So why not check out Scrimba's brand new, free tutorial on how to build the classic tic-tac-to... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-how-to-build-tic-tac-toe-with-react-hooks/</link>
                <guid isPermaLink="false">66d85240836d1162d8815c43</guid>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ react hooks ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Scrimba ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 29 May 2020 13:49:57 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/05/Screenshot-2020-05-26-at-21.27.58.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Per Harald Borgen</p>
<p>If you have a good understanding of HTML, CSS, JavaScript, and React you might be wondering where to go next on your learning journey. So why not check out <a target="_blank" href="https://scrimba.com/course/greactgame?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">Scrimba's brand new, free tutorial</a> on how to build the classic tic-tac-toe game in React?</p>
<p><a target="_blank" href="https://scrimba.com/course/greactgame?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/xtcbjygjr8s9in2u3nnv.png" alt="Fully working game" width="353" height="410" loading="lazy"></a>
<em>Click above to go to the tutorial.</em></p>
<p>The example game is pulled from React's official tutorials but is brought up to date using React hooks - the latest hot topic in the React world. </p>
<p>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.</p>
<p>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:</p>
<ul>
<li><a target="_blank" href="https://scrimba.com/course/ghtmlcss?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">HTML &amp; CSS Crash Course</a> with Kevin Powell</li>
<li><a target="_blank" href="https://scrimba.com/course/gintrotojavascript?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">Introduction to Javascript</a> with Dylan C. Israel</li>
<li><a target="_blank" href="https://scrimba.com/course/glearnreact?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">Learn React for Free</a> with Bob Ziroll</li>
</ul>
<p>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.</p>
<p>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.</p>
<p>Assuming you're ready to go with tic-tac-toe, let's get started!</p>
<h2 id="heading-introduction">Introduction</h2>
<p><a target="_blank" href="https://scrimba.com/p/pgGEGtW/cPkGD8Sm?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/e9mee46gi4pz43um8h1t.png" alt="Tic-tac-toe with React hooks slide" width="1172" height="511" loading="lazy"></a></p>
<p>In <a target="_blank" href="https://scrimba.com/p/pgGEGtW/cPkGD8Sm?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">the first scrim</a>, Thomas tells us about his plans for the tutorial and shares the <a target="_blank" href="https://reactjs.org/tutorial/tutorial.html">Official React Documentation</a>, which we can refer to for a more detailed explanation of the features used to build the game.</p>
<p>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.</p>
<h2 id="heading-scaffolding-components">Scaffolding Components</h2>
<p><a target="_blank" href="https://scrimba.com/p/pgGEGtW/cV8eB8fp?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">Next up</a>, 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.</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> Game <span class="hljs-keyword">from</span> <span class="hljs-string">"./components/Game"</span>;

<span class="hljs-keyword">const</span> App = <span class="hljs-function">() =&gt;</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Game</span> /&gt;</span></span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App;
</code></pre>
<h2 id="heading-square-component-and-destructuring-props">Square Component and Destructuring Props</h2>
<p>In <a target="_blank" href="https://scrimba.com/p/pgGEGtW/cKp4eRfq?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">the next scrim</a>, we create our square component using JSX to add a button:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> Square = <span class="hljs-function">(<span class="hljs-params">props</span>) =&gt;</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{props.onClick}</span>&gt;</span>{props.value}<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>
);
</code></pre>
<p>For our first challenge, Thomas encourages us to destructure out the props in our component. <a target="_blank" href="https://scrimba.com/p/pgGEGtW/cKp4eRfq?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">Click through</a> to the cast to give the challenge a try.</p>
<h2 id="heading-board-component-and-scaffolding-functions">Board Component and Scaffolding Functions</h2>
<p>Now it's time to create <a target="_blank" href="https://scrimba.com/p/pgGEGtW/cypaG6CZ?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">the board component</a> 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):</p>
<pre><code class="lang-js">&lt;div&gt;
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Square</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"1"</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> onClick("dummy value")} /&gt;</span>
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Square</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"2"</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> onClick("dummy value")} /&gt;</span>
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Square</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"3"</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> onClick("dummy value")} /&gt;</span>
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Square</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"4"</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> onClick("dummy value")} /&gt;</span>
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Square</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"5"</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> onClick("dummy value")} /&gt;</span>
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Square</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"6"</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> onClick("dummy value")} /&gt;</span>
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Square</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"7"</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> onClick("dummy value")} /&gt;</span>
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Square</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"8"</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> onClick("dummy value")} /&gt;</span>
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Square</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"9"</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> onClick("dummy value")} /&gt;</span>
&lt;/div&gt;
</code></pre>
<p>Thomas also scaffolds out the functions we need in Game.js, which we'll complete later.</p>
<h2 id="heading-square-styling">Square Styling</h2>
<p><a target="_blank" href="https://scrimba.com/p/pgGEGtW/ceMPzwhB?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/2zhixfxneekxecwxi2vn.png" alt="app with styled squares" width="354" height="234" loading="lazy"></a>
<em>Click the image to access the cast.</em></p>
<p><a target="_blank" href="https://scrimba.com/p/pgGEGtW/ceMPzwhB?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">Next up</a>, we style our squares using the <code>style</code> default prop:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> style = {
    <span class="hljs-attr">background</span>: <span class="hljs-string">"lightblue"</span>,
    <span class="hljs-attr">border</span>: <span class="hljs-string">"2px solid darkblue"</span>,
    <span class="hljs-attr">fontSize</span>: <span class="hljs-string">"30px"</span>,
    <span class="hljs-attr">fontWeight</span>: <span class="hljs-string">"800"</span>,
    <span class="hljs-attr">cursor</span>: <span class="hljs-string">"pointer"</span>,
    <span class="hljs-attr">outline</span>: <span class="hljs-string">"none"</span>,
};

<span class="hljs-keyword">const</span> Square = <span class="hljs-function">(<span class="hljs-params">{ value, onClick }</span>) =&gt;</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{style}</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{onClick}</span>&gt;</span>
        {value}
    <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>
);
</code></pre>
<h2 id="heading-board-styling">Board Styling</h2>
<p><a target="_blank" href="https://scrimba.com/p/pgGEGtW/c8rJyKcD?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/ynvasbhvjvj5kr9g5fe4.png" alt="app with styled board" width="323" height="368" loading="lazy"></a>
<em>Click the image to access the scrim.</em></p>
<p>Now that our squares are ready, it's time to the <a target="_blank" href="https://scrimba.com/p/pgGEGtW/c8rJyKcD?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">style the board</a>. Thomas kicks us off by once again creating a style object, this time with CSS grid:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> style = {
    <span class="hljs-attr">border</span>: <span class="hljs-string">"4px solid darkblue"</span>,
    <span class="hljs-attr">borderRadius</span>: <span class="hljs-string">"10px"</span>,
    <span class="hljs-attr">width</span>: <span class="hljs-string">"250px"</span>,
    <span class="hljs-attr">height</span>: <span class="hljs-string">"250px"</span>,
    <span class="hljs-attr">margin</span>: <span class="hljs-string">"0 auto"</span>,
    <span class="hljs-attr">display</span>: <span class="hljs-string">"grid"</span>,
    <span class="hljs-attr">gridTemplate</span>: <span class="hljs-string">"repeat(3, 1fr) / repeat(3, 1fr)"</span>,
};
</code></pre>
<p>Our challenge now is to apply the style object to the board. Head over <a target="_blank" href="https://scrimba.com/p/pgGEGtW/c8rJyKcD?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">to the scrim</a> to give it a try.</p>
<p>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!</p>
<h2 id="heading-the-calculatewinner-function-explained">The calculateWinner Function Explained</h2>
<pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">calculateWinner</span>(<span class="hljs-params">squares</span>) </span>{
    <span class="hljs-keyword">const</span> lines = [
        [<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>],
        [<span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>],
        [<span class="hljs-number">6</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>],
        [<span class="hljs-number">0</span>, <span class="hljs-number">3</span>, <span class="hljs-number">6</span>],
        [<span class="hljs-number">1</span>, <span class="hljs-number">4</span>, <span class="hljs-number">7</span>],
        [<span class="hljs-number">2</span>, <span class="hljs-number">5</span>, <span class="hljs-number">8</span>],
        [<span class="hljs-number">0</span>, <span class="hljs-number">4</span>, <span class="hljs-number">8</span>],
        [<span class="hljs-number">2</span>, <span class="hljs-number">4</span>, <span class="hljs-number">6</span>],
    ];
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; lines.length; i++) {
        <span class="hljs-keyword">const</span> [a, b, c] = lines[i];
        <span class="hljs-keyword">if</span> (squares[a] &amp;&amp; squares[a] === squares[b] &amp;&amp; squares[a] === squares[c]) {
            <span class="hljs-keyword">return</span> squares[a];
        }
    }
    <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>;
}
</code></pre>
<p><a target="_blank" href="https://scrimba.com/p/pgGEGtW/cBLrMvS2?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">Next up</a>, Thomas explains the all-important <code>calculateWinner()</code> function, which is taken from the original tutorial from <a target="_blank" href="https://reactjs.org/tutorial/tutorial.html">reactjs.org</a>. Head over <a target="_blank" href="https://scrimba.com/p/pgGEGtW/cBLrMvS2?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">to the cast</a> to explore the function and hear how it works.</p>
<h2 id="heading-create-states-and-fill-with-initial-data">Create States and Fill with Initial Data</h2>
<p>In the next <a target="_blank" href="https://scrimba.com/p/pgGEGtW/c4Pw97tV?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">scrim</a>, we start creating the logic for the game.</p>
<p>We begin by adding a hook called <code>usedState</code> in Game.js and creating states to set an empty board and specify the next player. Lastly, we add <code>const winner</code>, which tells us whether the latest move was a winning one:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> [board, setBoard] = useState(<span class="hljs-built_in">Array</span>(<span class="hljs-number">9</span>).fill(<span class="hljs-literal">null</span>));
<span class="hljs-keyword">const</span> [xIsNext, setXisNext] = useState(<span class="hljs-literal">true</span>);
<span class="hljs-keyword">const</span> winner = calculateWinner(board);
</code></pre>
<p>Over in Board.js, we delete our manually-rendered squares and replace them with mapped squares as promised earlier. <a target="_blank" href="https://scrimba.com/p/pgGEGtW/c4Pw97tV?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">Click through</a> to see this in detail:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> Board = <span class="hljs-function">(<span class="hljs-params">{ squares, onClick }</span>) =&gt;</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{style}</span>&gt;</span>
        {squares.map((square, i) =&gt; (
            <span class="hljs-tag">&lt;<span class="hljs-name">Square</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{i}</span> <span class="hljs-attr">value</span>=<span class="hljs-string">{square}</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> onClick(i)} /&gt;
        ))}
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
);
</code></pre>
<h2 id="heading-create-the-handleclick-function">Create the handleClick Function</h2>
<p><a target="_blank" href="https://scrimba.com/p/pgGEGtW/c67knwTy?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">Next</a>, we create the <code>handleClick()</code> function, which carries out the calculations when we make a move:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> handleClick = <span class="hljs-function">(<span class="hljs-params">i</span>) =&gt;</span> {
    <span class="hljs-keyword">const</span> boardCopy = [...board];
    <span class="hljs-comment">// If user click an occupied square or if game is won, return</span>
    <span class="hljs-keyword">if</span> (winner || boardCopy[i]) <span class="hljs-keyword">return</span>;
    <span class="hljs-comment">// Put an X or an O in the clicked square</span>
    boardCopy[i] = xIsNext ? <span class="hljs-string">"X"</span> : <span class="hljs-string">"O"</span>;
    setBoard(boardCopy);
    setXisNext(!xIsNext);
};
</code></pre>
<h2 id="heading-rendermoves-function-and-the-last-jsx">renderMoves Function and the Last JSX</h2>
<p><a target="_blank" href="https://scrimba.com/p/pgGEGtW/cNq2EQAL?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/xtcbjygjr8s9in2u3nnv.png" alt="Fully working game" width="353" height="410" loading="lazy"></a>
<em>Click above to go to the tutorial.</em></p>
<p><a target="_blank" href="https://scrimba.com/p/pgGEGtW/cNq2EQAL?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">In this scrim</a>, we create the JSX which makes the game playable.</p>
<pre><code class="lang-js">&lt;&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Board</span> <span class="hljs-attr">squares</span>=<span class="hljs-string">{board}</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{handleClick}</span> /&gt;</span></span>
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{styles}</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
      {winner ? "Winner: " + winner : "Next Player: " + (xIsNext ? "X" : "O")}
    <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/&gt;
</code></pre>
<p>We now have the all knowledge needed to create a fully working tic-tac-toe game with React hooks!</p>
<h2 id="heading-bonus-implement-time-travel">BONUS: Implement Time Travel</h2>
<p><a target="_blank" href="https://scrimba.com/p/pgGEGtW/cBLr6Df6?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/myoj1edcpkv3gx0ry7xj.png" alt="Time travel feature in action" width="403" height="591" loading="lazy"></a>
<em>Click the image to go to the bonus tutorial.</em></p>
<p><a target="_blank" href="https://scrimba.com/p/pgGEGtW/cBLr6Df6?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">In the bonus scrim</a>, 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.</p>
<p>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.</p>
<p>Next up, why not check out some of many other tutorials available on <a target="_blank" href="https://scrimba.com/?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgame_launch_article">Scrimba?</a> With a huge range of topics, there is something for everyone.</p>
<p>Happy learning :)</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/Z5RbPrK4VqM" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Here's a Free Course to Help Front End Developers Learn Math ]]>
                </title>
                <description>
                    <![CDATA[ By Per Harald Borgen Are you looking to become a more effective developer by improving your fundamental math skills without reaching for NASA-level calculations? Look no further! At Scrimba, we're are really excited to announce our new course 'Practi... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/want-to-learn-practical-math-for-front-end-developers-heres-our-free-11-part-course-by-radical-coder/</link>
                <guid isPermaLink="false">66d85273836d1162d8815c45</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Math ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Scrimba ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 25 May 2020 15:05:47 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/04/Screenshot-2020-04-23-at-16.49.35.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Per Harald Borgen</p>
<p>Are you looking to become a more effective developer by improving your fundamental math skills without reaching for NASA-level calculations? Look no further!</p>
<p>At Scrimba, we're are really excited to announce our new course <a target="_blank" href="https://scrimba.com/course/gpracticalmath">'Practical Math for Front-End Developers'</a>, which offers exactly that. In the course we build 3 projects:</p>
<ol>
<li>A Shopping Cart, where we generate a list of products, calculate the total price of the products and apply a tax rate.</li>
<li>A Weekly Schedule, where we introduce the <code>Date</code> object, perform layout manipulation and learn about the <code>reduce</code> function.</li>
<li>A Monthly Expense Sheet, which brings together everything we've learned and gives us a few handy tips and tricks.</li>
</ol>
<p>This course is brought to you by Ryan Gonyon, who has his own <a target="_blank" href="https://www.google.com/url?q=https://www.twitch.tv/radicalcoder&amp;sa=D&amp;ust=1585686482555000&amp;usg=AFQjCNHoQP_okALIk85y1YojlBM-DwEiHw">Twitch</a> and <a target="_blank" href="https://www.google.com/url?q=https://www.youtube.com/channel/UC2J1l95xB98Fd-v9xGkxHIg&amp;sa=D&amp;ust=1585686482556000&amp;usg=AFQjCNGzqdwTLYFINOKqnrb4a0XgwxY_DA">YouTube</a> channels.</p>
<p>With 5 years of Web Dev experience, a B.S. in Computer Science, and experience tutoring K-12 and University-level math, Ryan is the perfect tutor for this course. Head over to <a target="_blank" href="https://scrimba.com/playlist/pzKyeuP?utm_source=fcc&amp;utm_medium=referral&amp;utm_campaign=gpracticalmath_launch_article">Scrimba</a> to see what he has in store!</p>
<h1 id="heading-app-layout-and-css-calc-introduction">App Layout and CSS calc() Introduction</h1>
<p><a target="_blank" href="https://scrimba.com/p/pzKyeuP/c73zJGtp?utm_source=fcc&amp;utm_medium=referral&amp;utm_campaign=gpracticalmath_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/6ox8mhsqz51nnxda6q0t.png" alt="Site header, main and footer" width="350" height="399" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p>In this screencast, Ryan shows us how to build the outer shell of our applications by correctly sizing the <code>&lt;header&gt;</code>, <code>&lt;footer&gt;</code> and <code>&lt;main&gt;</code> tags with CSS variables and the <code>calc()</code> function.</p>
<p>We use <code>overflow-y: auto</code>; to ensure that the contents of the <code>&lt;main&gt;</code> tag do not extend over the footer.</p>
<pre><code class="lang-css">* {
    <span class="hljs-attribute">--headerFontSize</span>: <span class="hljs-number">2rem</span>;
    <span class="hljs-attribute">--headerPadding</span>: <span class="hljs-number">0.5rem</span>;
    <span class="hljs-attribute">--footerFontSize</span>: <span class="hljs-number">1rem</span>;
    <span class="hljs-attribute">--footerPadding</span>: <span class="hljs-number">1rem</span>;
}

<span class="hljs-selector-tag">header</span> {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-built_in">var</span>(--headerFontSize);
    <span class="hljs-attribute">padding</span>: <span class="hljs-built_in">var</span>(--headerPadding);
}

<span class="hljs-selector-tag">main</span> {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1.5rem</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-built_in">calc</span>(
        <span class="hljs-number">100vh</span> - var(--headerFontSize) - (<span class="hljs-number">2</span> * <span class="hljs-built_in">var</span>(--headerPadding)) - <span class="hljs-built_in">var</span>(
                --footerFontSize
            ) - (<span class="hljs-number">2</span> * <span class="hljs-built_in">var</span>(--footerPadding))
    );
    <span class="hljs-attribute">overflow-y</span>: auto;
}

<span class="hljs-selector-tag">footer</span> {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-built_in">var</span>(--footerFontSize);
    <span class="hljs-attribute">padding</span>: <span class="hljs-built_in">var</span>(--footerPadding);
}
</code></pre>
<h1 id="heading-the-roll-function">The roll() Function</h1>
<p>At some point during your front-end journey, it will be useful to generate random data to test your layouts. The <code>roll()</code> function does exactly that. This cast also shows us how to use JavaScript's <code>Math</code> module and <code>random()</code> function.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">roll</span>(<span class="hljs-params">min, max, floatFlag</span>) </span>{
    <span class="hljs-keyword">let</span> r = <span class="hljs-built_in">Math</span>.random() * (max - min) + min;
    <span class="hljs-keyword">return</span> floatFlag ? r : <span class="hljs-built_in">Math</span>.floor(r);
}
</code></pre>
<h1 id="heading-shopping-cart-generate-data-build-layout">Shopping Cart - Generate Data / Build Layout</h1>
<p><a target="_blank" href="https://scrimba.com/p/pzKyeuP/cn4kQnUK?utm_source=fcc&amp;utm_medium=referral&amp;utm_campaign=gpracticalmath_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/bd17qggr11kjt0mwjsib.png" alt="Finished Shopping Cart layout" width="345" height="396" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p>Now we start building our first project, the Shopping Cart, using our newly written <code>roll()</code> function to generate prices. This shows us how much time we save using our new knowledge!</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> products = [...Array(<span class="hljs-number">5</span>)].map(<span class="hljs-function">(<span class="hljs-params">_, i</span>) =&gt;</span> {
    <span class="hljs-keyword">return</span> {
        <span class="hljs-attr">index</span>: i,
        <span class="hljs-attr">title</span>: possibleProducts[roll(<span class="hljs-number">0</span>, possibleProducts.length)],
        <span class="hljs-attr">price</span>: roll(<span class="hljs-number">1</span>, <span class="hljs-number">10</span>, <span class="hljs-number">1</span>).toFixed(<span class="hljs-number">2</span>),
        <span class="hljs-attr">count</span>: roll(<span class="hljs-number">1</span>, <span class="hljs-number">6</span>),
    };
});
</code></pre>
<h1 id="heading-shopping-cart-calculate-total-apply-tax-rate">Shopping Cart - Calculate Total / Apply Tax Rate</h1>
<p>In this screencast, we learn how to use <code>.reduce</code> to calculate the total price of the cart</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> cartTotal = products
    .reduce(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">accumulator, product</span>) </span>{
        <span class="hljs-built_in">console</span>.log(accumulator, product);
        <span class="hljs-keyword">return</span> accumulator + <span class="hljs-built_in">parseFloat</span>(product.price) * product.count;
    }, <span class="hljs-number">0</span>)
    .toFixed(<span class="hljs-number">2</span>);
</code></pre>
<p>We also see how to use <code>roll()</code> to generate a random tax rate and apply it.</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> taxRate = roll(<span class="hljs-number">5</span>, <span class="hljs-number">9</span>, <span class="hljs-number">1</span>).toFixed(<span class="hljs-number">1</span>);
</code></pre>
<p>Along the way, we practise parsing float values and rounding them to a specified number after a decimal point.</p>
<h1 id="heading-shopping-cart-bonus-challenge-weights">Shopping Cart (Bonus Challenge) - Weights</h1>
<p>As a bonus challenge in this cast, we randomly generate the weight of each item in our shopping cart and calculate the total weight at the checkout. In the real world, this could be used to estimate the shipping cost for the buyer.</p>
<p>No spoilers here, so if you want to see the solution you'll have to click through <a target="_blank" href="https://scrimba.com/p/pzKyeuP/ce99mQsa?utm_source=fcc&amp;utm_medium=referral&amp;utm_campaign=gpracticalmath_launch_article">to the course.</a> ?</p>
<h1 id="heading-a-brief-exploration-of-css-shapes">A Brief Exploration of CSS Shapes</h1>
<p><a target="_blank" href="https://scrimba.com/p/pzKyeuP/cGmWKMfR?utm_source=fcc&amp;utm_medium=referral&amp;utm_campaign=gpracticalmath_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/afroa8rcp6hv0g24aej2.png" alt="Rendered shapes built with CSS" width="496" height="840" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p>In this cast, we learn how to create a square, a circle, a diamond and a triangle with CSS shapes.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.triangle</span> {
    <span class="hljs-attribute">height</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">border-left</span>: <span class="hljs-number">5.5rem</span> solid transparent;
    <span class="hljs-attribute">border-right</span>: <span class="hljs-number">5.5rem</span> solid transparent;
    <span class="hljs-attribute">border-bottom</span>: <span class="hljs-number">5.5rem</span> solid black;
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">1rem</span>;
    <span class="hljs-attribute">position</span>: relative;
}

<span class="hljs-selector-class">.triangle</span><span class="hljs-selector-pseudo">:after</span> {
    <span class="hljs-attribute">content</span>: <span class="hljs-string">""</span>;
    <span class="hljs-attribute">position</span>: absolute;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">border-left</span>: <span class="hljs-number">4.5rem</span> solid transparent;
    <span class="hljs-attribute">border-right</span>: <span class="hljs-number">4.5rem</span> solid transparent;
    <span class="hljs-attribute">border-bottom</span>: <span class="hljs-number">4.5rem</span> solid red;
    <span class="hljs-attribute">left</span>: -<span class="hljs-number">4.5rem</span>;
    <span class="hljs-attribute">top</span>: <span class="hljs-number">0.6rem</span>;
}
</code></pre>
<h1 id="heading-weekly-schedule-using-date-to-build-week-generating-tasks">Weekly Schedule - Using Date() to Build Week / Generating Tasks</h1>
<p>In this cast, we start work on our Weekly Schedule app. First up, we learn about JavaScript's <code>Date</code> object.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getNextDay</span>(<span class="hljs-params">day</span>) </span>{
    <span class="hljs-keyword">let</span> nextDay = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>(day);
    nextDay.setDate(day.getDate() + <span class="hljs-number">1</span>);
    <span class="hljs-keyword">return</span> nextDay;
}
</code></pre>
<p>Next, we look at using the <code>roll()</code> function to test the layout and produce a list of tasks. Take a look <a target="_blank" href="https://scrimba.com/p/pzKyeuP/c2KKPGh6?utm_source=fcc&amp;utm_medium=referral&amp;utm_campaign=gpracticalmath_launch_article">at the course</a> to see how it works</p>
<h1 id="heading-weekly-schedule-build-layout-display-data">Weekly Schedule - Build Layout / Display Data</h1>
<p><a target="_blank" href="https://scrimba.com/p/pzKyeuP/caZZyNA9?utm_source=fcc&amp;utm_medium=referral&amp;utm_campaign=gpracticalmath_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/uezalgp2o5marghv69gs.png" alt="Weekly Schedule app" width="1038" height="1074" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p>In this cast, Ryan shows us how to use the <code>calc()</code> function to display the data generated in the previous cast.</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">--mainHeight</span>: <span class="hljs-selector-tag">calc</span>(
    100<span class="hljs-selector-tag">vh</span> <span class="hljs-selector-tag">-</span> <span class="hljs-selector-tag">var</span>(<span class="hljs-selector-tag">--headerFontSize</span>) <span class="hljs-selector-tag">-</span> (2 * <span class="hljs-selector-tag">var</span>(<span class="hljs-selector-tag">--headerPadding</span>)) <span class="hljs-selector-tag">-</span> <span class="hljs-selector-tag">var</span>(
            <span class="hljs-selector-tag">--footerFontSize</span>
        ) <span class="hljs-selector-tag">-</span> (2 * <span class="hljs-selector-tag">var</span>(<span class="hljs-selector-tag">--footerPadding</span>))
);
</code></pre>
<p>We also learn how to cross out completed tasks (<a target="_blank" href="https://scrimba.com/p/pzKyeuP/caZZyNA9?utm_source=fcc&amp;utm_medium=referral&amp;utm_campaign=gpracticalmath_launch_article">click through</a> to find out how.) The result is a clean, functional app that we can use in everyday life.</p>
<h1 id="heading-monthly-expense-sheet-generate-and-display-month">Monthly Expense Sheet - Generate and Display Month</h1>
<p><a target="_blank" href="https://scrimba.com/p/pzKyeuP/cD44VpTW?utm_source=fcc&amp;utm_medium=referral&amp;utm_campaign=gpracticalmath_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/a6you8qo65mq9smjyhrv.png" alt="Grid display" width="395" height="460" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p>Next, use the concepts from the previous casts to build something more complex - our expenses tracker. In this project we generate data, display months and draw up a grid.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">displayMonth</span>(<span class="hljs-params">month</span>) </span>{
    <span class="hljs-comment">// &lt;div class="day"&gt;3&lt;/div&gt;</span>
    <span class="hljs-keyword">let</span> monthHtml = month.reduce(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">accumulator, day</span>) </span>{
        <span class="hljs-keyword">return</span> accumulator + <span class="hljs-string">`&lt;div class="day"&gt;<span class="hljs-subst">${day.date.getDate()}</span>&lt;/div&gt;`</span>;
    }, <span class="hljs-string">""</span>);
    <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"MonthlyExpenses"</span>).innerHTML = monthHtml;
}
</code></pre>
<h1 id="heading-monthly-expense-sheet-generate-display-and-track-expenses">Monthly Expense Sheet - Generate, Display, and Track Expenses</h1>
<p><a target="_blank" href="https://scrimba.com/p/pzKyeuP/cD4weyhd?utm_source=fcc&amp;utm_medium=referral&amp;utm_campaign=gpracticalmath_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/kb2kp4o9k4p6mwlvi0hl.png" alt="Monthly Expense Sheet app" width="396" height="465" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p>In the final cast, we perform budget calculations by writing functions to track our expenses, rent and utility bills. We then display the expenditures alongside the remaining available budget.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">displayMonth</span>(<span class="hljs-params">month, budget, netValue</span>) </span>{
    <span class="hljs-keyword">let</span> monthHtml =
        <span class="hljs-string">`&lt;div class="monthly-summary"&gt;
        Budget: \$<span class="hljs-subst">${budget.toFixed(<span class="hljs-number">2</span>)}</span> | Net Value: \$<span class="hljs-subst">${netValue.toFixed(<span class="hljs-number">2</span>)}</span>
    &lt;/div&gt;`</span> +
        month.reduce(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">accumulator, day</span>) </span>{
            <span class="hljs-keyword">return</span> accumulator + <span class="hljs-string">`&lt;div class="day"&gt;<span class="hljs-subst">${day.date.getDate()}</span>&lt;/div&gt;`</span>;
        }, <span class="hljs-string">""</span>);
    <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"MonthlyExpenses"</span>).innerHTML = monthHtml;
}
</code></pre>
<h1 id="heading-conclusion">Conclusion</h1>
<p>Well done for finishing this course, I really hope you have learned some useful tips and tricks that you can apply in your future coding adventures!</p>
<p>Happy learning ;)</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Want to Learn Vuetify? Here's Our Free 15-Part Course by Gwen Faraday ]]>
                </title>
                <description>
                    <![CDATA[ By Per Harald Borgen If you love building apps in Vue.js but struggle to know where to start with UI design, look no further than Vuetify. It's a UI library containing handcrafted material components which give apps a beautiful finish and professiona... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/want-to-learn-vuetify-heres-our-free-15-part-course-by-gwen-faraday/</link>
                <guid isPermaLink="false">66d8527fb56109a3fff9ddbc</guid>
                
                    <category>
                        <![CDATA[ Scrimba ]]>
                    </category>
                
                    <category>
                        <![CDATA[ vue ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Vuetify ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 23 May 2020 16:02:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/05/Screenshot-2020-05-23-at-17.06.55.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Per Harald Borgen</p>
<p>If you love building apps in Vue.js but struggle to know where to start with UI design, look no further than Vuetify. It's a UI library containing handcrafted material components which give apps a beautiful finish and professional feel.</p>
<h2 id="heading-why-learn-vuetify">Why learn Vuetify?</h2>
<p>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. </p>
<p>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.</p>
<p>This article takes you through Scrimba's free <a target="_blank" href="https://scrimba.com/course/gvuetify?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">two-hour Vuetify course</a> by Gwen Faraday. The course teaches you all the core skills needed to get started with Vuetify, including:</p>
<ul>
<li>Typography</li>
<li>Spacing</li>
<li>Buttons</li>
<li>Navigation</li>
<li>Grid</li>
<li>Card</li>
</ul>
<p>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.</p>
<p>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.</p>
<p>By the end, you'll be fully versed in building professionally-styled apps with Vuetify.</p>
<h2 id="heading-intro-to-the-instructor">Intro to the Instructor</h2>
<p>Gwen Faraday is a software engineer, author, speaker, and &amp; content creator who also runs a Youtube channel, <a target="_blank" href="https://www.youtube.com/channel/UCxA99Yr6P_tZF9_BgtMGAWA/featured">the Faraday Academy</a>, 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.</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>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:</p>
<ul>
<li><a target="_blank" href="https://scrimba.com/course/ghtmlcss?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">HTML and CSS</a></li>
<li><a target="_blank" href="https://scrimba.com/course/gintrotojavascript?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">Javascript</a></li>
<li><a target="_blank" href="https://scrimba.com/course/glearnvue?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">Vue.js</a></li>
</ul>
<p>If you’re ready to hit the ground running with Vuetify, let’s get into it!</p>
<h2 id="heading-intro-to-vuetify">Intro to Vuetify</h2>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/cEKyEkuB?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">In the first cast</a>, Gwen introduces us to Vuetify and shares the two Github repositories where she has stored all the code, <a target="_blank" href="https://github.com/gwenf/vuetify-basic-components">basic-components</a> and <a target="_blank" href="https://github.com/gwenf/vuetify-responsive">vuetify-responsive</a>. This allows us to download the code and try it out for ourselves.</p>
<h2 id="heading-what-is-material-design">What is Material Design?</h2>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/c4PDDZtg?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">Next up</a>, we learn about Material Design, a standard developed by Google for implementing accessible, user-friendly interfaces.</p>
<p>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.</p>
<p>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.</p>
<h2 id="heading-first-look-at-vuetify-code">First Look at Vuetify Code</h2>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/ckPbepSM?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">In the next cast</a>, Gwen gives us our first look at Vuetify code by instantiating a Vue application, adding a Vuetify property and creating a new Vuetify object:</p>
<pre><code class="lang-js"><span class="hljs-keyword">new</span> Vue({
    <span class="hljs-attr">el</span>: <span class="hljs-string">"#app"</span>,
    <span class="hljs-attr">vuetify</span>: <span class="hljs-keyword">new</span> Vuetify({}),
    <span class="hljs-attr">data</span>: {
        <span class="hljs-attr">message</span>: <span class="hljs-string">"Using Single File Components"</span>,
    },
});
</code></pre>
<p>Next, Gwen shows us the <code>&lt;v-app&gt;</code> element, which is the root component of all Vuetify elements (Vuetify components must fall within <code>&lt;v-app&gt;</code>):</p>
<pre><code class="lang-vue">&lt;v-app&gt;
     &lt;v-content&gt;
          &lt;playground&gt;&lt;/playground&gt;
     &lt;/v-content&gt;
&lt;/v-app&gt;
</code></pre>
<h2 id="heading-typography">Typography</h2>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/cMqPmeTG?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/lrmuhh5orzx32c4jdlsd.png" alt="Vuetify typography" width="670" height="541" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p>In <a target="_blank" href="https://scrimba.com/p/pP4xZu3/cMqPmeTG?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">the next scrim</a>, 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.</p>
<pre><code class="lang-vue">&lt;v-card-text&gt;
     &lt;h1 class="display-4 purple yellow--text"&gt;Heading 1&lt;/h1&gt;
     &lt;h2 class="display-3"&gt;Heading 2&lt;/h2&gt;
     &lt;h3 class="display-2"&gt;Heading 3&lt;/h3&gt;
     &lt;h4 class="title"&gt;Title&lt;/h4&gt;
     &lt;h5 class="subtitle-1"&gt;Subtitle&lt;/h5&gt;
     &lt;p class="body-1"&gt;Body&lt;/p&gt;
&lt;/v-card-text&gt;
</code></pre>
<p>Finally, we see how to use Vuetify classes to adjust font weight and style:</p>
<pre><code class="lang-vue">&lt;h1 class="font-italic font-weight-light"&gt;Heading 1&lt;/h1&gt;
</code></pre>
<p><strong>Note:</strong> Vuetify classes override any other styles that the browser applies to HTML tags.</p>
<h2 id="heading-spacing">Spacing</h2>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/cD7pnzSw?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">Next up</a>, 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.</p>
<pre><code class="lang-vue">&lt;h3 class="ml-5"&gt;Spacing&lt;/h3&gt;
</code></pre>
<p>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.</p>
<h2 id="heading-buttons">Buttons</h2>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/crmrBwtP?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/ollkzqisck44bqdnc1r9.png" alt="Vuetify buttons" width="363" height="427" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p>In the <a target="_blank" href="https://scrimba.com/p/pP4xZu3/crmrBwtP?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">next scrim</a>, we look at some of the options available with Vuetify's button component, including buttons with text, icons or both.</p>
<pre><code class="lang-vue">&lt;v-btn large block&gt;Submit&lt;/v-btn&gt;
</code></pre>
<p>Lastly, we look at how to build custom buttons using classes from earlier.</p>
<pre><code class="lang-vue">&lt;button v-ripple class="elevation-2 py-2 px-4"&gt;
     Submit
&lt;/button&gt;
</code></pre>
<h2 id="heading-navigation">Navigation</h2>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/czkwwQCw?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/je40l0odaw1l68pi8a71.png" alt="Vuetify navigation" width="380" height="176" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/czkwwQCw?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">Next up</a>, we look at the two main navigation options available in Vuetify,<code>&lt;v-app-bar&gt;</code> and <code>&lt;v-toolbar&gt;</code>. Both navigation elements provide automatic button and icon sizing, navigation icons and the ability to handle list dropdowns.</p>
<pre><code class="lang-vue">&lt;v-toolbar color="deep-purple accent-4" dense dark&gt;
    &lt;v-app-bar-nav-icon&gt;&lt;/v-app-bar-nav-icon&gt;
&lt;v-toolbar-title&gt;App Title&lt;/v-toolbar-title&gt;&lt;/v-toolbar&gt;
</code></pre>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/czkwwQCw?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">Click through</a> to see all this in action!</p>
<h2 id="heading-grid">Grid</h2>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/cWKBnPSV?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/hddtxtqh91j6z9gjb1up.png" alt="Vuetify grid" width="431" height="220" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p>In <a target="_blank" href="https://scrimba.com/p/pP4xZu3/cWKBnPSV?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">the next scrim</a>, 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.</p>
<pre><code class="lang-vue">&lt;v-row&gt;
    &lt;v-col cols="12" sm="6"&gt;
        &lt;v-card
        class="pa-2"
        outlined
        tile
        &gt;
        Column
        &lt;/v-card&gt;
    &lt;/v-col&gt;
&lt;/v-row&gt;
</code></pre>
<h2 id="heading-card">Card</h2>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/cdNW42t8?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/dbh0863c4we6t4sncpf2.png" alt="Vuetify card" width="383" height="258" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p>In <a target="_blank" href="https://scrimba.com/p/pP4xZu3/cdNW42t8?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">this cast</a>, Gwen explains that Vuetify uses a <code>&lt;v-card&gt;</code> 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.</p>
<pre><code class="lang-vue"> &lt;v-card-title&gt;
    &lt;v-icon
        large
        left
    &gt;
        mdi-twitter
    &lt;/v-icon&gt;
    &lt;/v-card-title&gt;

    &lt;v-card-text class="headline font-weight-bold"&gt;
    "Vue Rocks!"
    &lt;/v-card-text&gt;

&lt;/v-card&gt;
</code></pre>
<p>Gwen also introduces us to the <code>&lt;v-spacer&gt;</code> element, which lets us easily add whitespace between elements.</p>
<p>Finally, we check out the <code>Playground.vue</code> file - a space for us to explore the features of Vuetify Gwen has shown us so far. Head over <a target="_blank" href="https://scrimba.com/p/pP4xZu3/cdNW42t8?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">to the course</a> to try it out for yourself and see what Vuetify can do.</p>
<h2 id="heading-store-navigation">Store Navigation</h2>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/cMZMQbu9?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/tc2s63qss1f3tc7vyyhu.png" alt="Vuetify web store navigation" width="445" height="234" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/cMZMQbu9?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">Next</a>, 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.</p>
<h2 id="heading-home-page">Home Page</h2>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/c33vv6fz?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">Next up</a>, 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 <a target="_blank" href="https://scrimba.com/p/pP4xZu3/c33vv6fz?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">to the screencast</a> to test out your new Vuetify skills and compare your work to Gwen's solution.</p>
<p>To finish off, Gwen shows us the <code>&lt;v-snackbar&gt;</code> element, which can be used to notify a user when a product has been added to the cart.</p>
<pre><code class="lang-vue">&lt;v-snackbar
    v-model="$store.state.snackbar.show"
    :multi-line="true"
    :right="true"
    :top="true"
    :timeout="6000"
    :color="$store.state.snackbar.variant"
&gt;
    {{ $store.state.snackbar.message }}
    &lt;v-btn
    dark
    text
    @click="$store.commit('updateSnackbar', { show: false })"
    &gt;
    Close
    &lt;/v-btn&gt;
&lt;/v-snackbar&gt;
</code></pre>
<h2 id="heading-store-page">Store Page</h2>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/cvdrn6Ar?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/m1d909j9guwo0q1da9jj.png" alt="Vuetify web store page" width="970" height="531" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/cvdrn6Ar?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">In the next Scrim</a> 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 <code>&lt;v-sheet&gt;</code> and <code>&lt;v-expansion-panels&gt;</code> elements.</p>
<p>Head over <a target="_blank" href="https://scrimba.com/p/pP4xZu3/cvdrn6Ar?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">to the cast</a> to give the challenge a try.</p>
<h2 id="heading-cart-page">Cart Page</h2>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/caZyp7um?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/drbsnxpy6p95kzj3aph5.png" alt="Vuetify cart page" width="414" height="521" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p><a target="_blank" href="https://scrimba.com/p/pP4xZu3/caZyp7um?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">Next up</a>, 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.</p>
<p>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.</p>
<h2 id="heading-checkout-screen">Checkout Screen</h2>
<p>In the final code scrim, we build a simple checkout flow using the <code>&lt;v-stepper&gt;</code> element.</p>
<pre><code class="lang-vue">&lt;v-stepper-header&gt;
    &lt;v-stepper-step
        step="1"
        :complete="step &gt; 1"
    /&gt;
    &lt;v-divider /&gt;
    &lt;v-stepper-step
        step="2"
        :complete="step &gt; 2"
    /&gt;
    &lt;v-divider /&gt;
    &lt;v-stepper-step
        step="3"
    /&gt;
    &lt;/v-stepper-header&gt;
</code></pre>
<p>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.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>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 <a target="_blank" href="https://scrimba.com/?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=gvuetify_launch_article">Scrimba</a>?</p>
<p>Wherever you go next, happy coding :)</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/rJIRv-_oYnA" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Want to build an app with React and GraphQL? Here's our free 1-hour course by Karl Hadwen ]]>
                </title>
                <description>
                    <![CDATA[ By Per Harald Borgen If you've ever wondered how to connect React.js & GraphQL, then Scrimba's hot one hour course is for you! The course jumps right into using a wide range of technologies to build a fast application with a concise amount of code - ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/want-to-build-an-app-with-react-and-graphql-heres-our-free-1-hour-course-by-karl-hadwen/</link>
                <guid isPermaLink="false">66d8526218dca47577c8daa5</guid>
                
                    <category>
                        <![CDATA[ GraphQL ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Scrimba ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 18 May 2020 20:00:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/05/Screenshot-2020-05-09-at-18.33.24.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Per Harald Borgen</p>
<p>If you've ever wondered how to connect React.js &amp; GraphQL, then Scrimba's hot <a target="_blank" href="https://scrimba.com/course/greactgraphql?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article">one hour course</a> is for you! The course jumps right into using a wide range of technologies to build a fast application with a concise amount of code - what's not to love?</p>
<h2 id="heading-why-learn-react-and-graphql">Why learn React and GraphQL?</h2>
<p>GraphQL has a faster build and iteration time than REST APIs and reduces the amount of data sent from the server. This means faster and more responsive apps - a must for any React developer.</p>
<h2 id="heading-intro-to-the-instructor">Intro to the instructor</h2>
<p>This course is brought to you by Karl Hadwen - a JavaScript and React developer with over ten years of experience. Karl also runs a <a target="_blank" href="https://www.youtube.com/channel/UC1DUQiZduv_yNZy0O7n_iHA">YouTube channel</a> teaching React, JavaScript, and GraphQL, so he's just the person to help you level up your React and GraphQL skills.</p>
<h2 id="heading-whats-covered-in-the-course">What's covered in the course?</h2>
<p>In this course, we'll learn how to build a fun front-end application that uses React, GraphQL, and Apollo to display Pokemon characters, facts and images! The course is interactive and to-the-point, meaning you'll build something like this in no time:</p>
<p><a target="_blank" href="https://scrimba.com/p/pdqXpfD/ckRd6NU9?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/m93x4nidm7dfqsnaohbm.png" alt="Pokemon app UI" width="721" height="411" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p>In true Scrimba tradition, Karl's course is jam-packed with interactive coding challenges to help you apply your knowledge and embed your learning, so head over <a target="_blank" href="https://scrimba.com/course/greactgraphql?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article">to Scrimba</a> now and read on to find out more.</p>
<h2 id="heading-welcome-to-the-course">Welcome to the course</h2>
<p>In <a target="_blank" href="https://scrimba.com/p/pdqXpfD/ckRd6NU9?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article">the first scrim</a>, Karl introduces us to the technologies we'll use in the course, which are:</p>
<ul>
<li>React</li>
<li>GraphQL</li>
<li>Apollo</li>
<li>CSS</li>
<li>the Pokemon open API.</li>
</ul>
<h2 id="heading-installing-our-dependencies-amp-creating-our-skeleton-project">Installing our dependencies &amp; creating our skeleton project</h2>
<p><a target="_blank" href="https://scrimba.com/p/pdqXpfD/ckRdVWSD?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/an3cm74ty42qt0e4ptsm.png" alt="Apollo, GraphQL and React dependencies added to the project" width="214" height="155" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p>Now it's time to <a target="_blank" href="https://scrimba.com/p/pdqXpfD/ckRdVWSD?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article">start our project</a>. First things first, we install the Apollo, GraphQL and React dependencies. Next up, we build up the files and folders we need for our project:</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> { render } <span class="hljs-keyword">from</span> <span class="hljs-string">"react-dom"</span>;
<span class="hljs-keyword">import</span> { App } <span class="hljs-keyword">from</span> <span class="hljs-string">"./App"</span>;

render(<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">App</span> /&gt;</span></span>, <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"root"</span>));
</code></pre>
<h2 id="heading-giving-our-application-life">Giving our application life!</h2>
<p>Now it's time to give our application life by adding to our app file and hitting the GraphQL server:</p>
<pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> client = <span class="hljs-keyword">new</span> ApolloClient({
        <span class="hljs-attr">uri</span>: <span class="hljs-string">"https://graphql-pokemon.now.sh"</span>,
    });

    <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>I am a Pokemon<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>;
}
</code></pre>
<p><a target="_blank" href="https://scrimba.com/p/pdqXpfD/c8qgp9TZ?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article">This scrim</a> takes us through the following steps to allow our user to interact with our application:</p>
<ul>
<li>setting up the Apollo client</li>
<li>building the <code>ApolloProvider</code> and passing in the client as a prop</li>
<li>adding our <code>&lt;main&gt;</code> tag and <code>PokemonsContainer</code></li>
</ul>
<h2 id="heading-lets-talk-about-graphql">Let's talk about GraphQL</h2>
<p><a target="_blank" href="https://scrimba.com/p/pdqXpfD/cmmdmvc6?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/trsebt5rtu5zyetzn40b.png" alt="fields which can be returned from pokemon open API" width="247" height="506" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p><a target="_blank" href="https://scrimba.com/p/pdqXpfD/cmmdmvc6?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article">This scrim</a> takes a look at <a target="_blank" href="https://graphql-pokemon.now.sh/">the GraphQL server</a> that we'll be using in our app. The great thing about GraphQL is that it allows us to request just the fields we need from the object, unlike REST which sends all the information available. Karl shows us this in action by walking us through building and running our first GraphQL query.</p>
<h2 id="heading-using-our-container-component-to-map-over-our-pokemons">Using our container component to map over our Pokemons!</h2>
<p>In <a target="_blank" href="https://scrimba.com/p/pdqXpfD/c4MGWJf8?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article">the next scrim</a>, we build out our main container so we can loop over our Pokemons.</p>
<p>Karl kicks us of by showing us how to get the data from the Pokemon API:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> { <span class="hljs-attr">data</span>: { pokemons = [] } = {} } = useQuery(GET_POKEMONS, {
    <span class="hljs-attr">variables</span>: { <span class="hljs-attr">first</span>: <span class="hljs-number">9</span> },
});
</code></pre>
<p>Next, it's time for an interactive challenge: passing two props, the key and <code>pokemon</code>. Head over to <a target="_blank" href="https://scrimba.com/p/pdqXpfD/c4MGWJf8?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article">the course</a> to give the challenge a try for yourself.</p>
<h2 id="heading-adding-a-graphql-query-and-creating-our-pokemon-component">Adding a GraphQL query and creating our Pokemon component!</h2>
<p><a target="_blank" href="https://scrimba.com/p/pdqXpfD/cND38EfL?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/09rwvu8lyfclzw1yv46o.png" alt="Alt Text" width="490" height="526" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p>In <a target="_blank" href="https://scrimba.com/p/pdqXpfD/cND38EfL?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article">this scrim</a>, we start by building our graphQL query:</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> gql <span class="hljs-keyword">from</span> <span class="hljs-string">"graphql-tag"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> GET_POKEMONS = gql<span class="hljs-string">`
    query pokemons($first: Int!) {
        pokemons(first: $first) {
            id
            name
            image
            maxHP
            maxCP
            attacks {
                special {
                    name
                    damage
                }
            }
        }
    }
`</span>;
</code></pre>
<p>Next, Karl gives us the bare bones of our Pokemon component:</p>
<pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Pokemon</span>(<span class="hljs-params">{ pokemon }</span>) </span>{
    <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>{pokemon.name}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>;
}
</code></pre>
<p>Our challenge now is to build up the Pokemon component so it displays all the information retrieved from the API. Click through <a target="_blank" href="https://scrimba.com/p/pdqXpfD/cND38EfL?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article">to the course</a> now to give it a try.</p>
<h2 id="heading-finishing-our-pokemon-component">Finishing our Pokemon component</h2>
<p><a target="_blank" href="https://scrimba.com/p/pdqXpfD/cVnyLyfW?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article">Next up,</a> Karl talks us through how to map over up to three of a Pokemon's multiple attacks:</p>
<pre><code class="lang-js">{
    pokemon.attacks.special.slice(<span class="hljs-number">0</span>, <span class="hljs-number">3</span>).map(<span class="hljs-function">(<span class="hljs-params">attack</span>) =&gt;</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span></span>);
}
</code></pre>
<p>We also have a mini-challenge of adding a key within our <code>pokemon__attacks</code> div. <a target="_blank" href="https://scrimba.com/p/pdqXpfD/cVnyLyfW?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article">Click through</a> now to give it a try.</p>
<h2 id="heading-lets-style-our-application">Let's style our application!</h2>
<p><a target="_blank" href="https://scrimba.com/p/pdqXpfD/c8qgEqUV?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/3lsg12e2b8dc0uwmjhe7.png" alt="Styled Pokemon component" width="602" height="564" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p>Now that we've created our app, it's time to style it. In <a target="_blank" href="https://scrimba.com/p/pdqXpfD/c8qgEqUV?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article">this bumper scrim</a>, Karl talks us through styling all the elements of our Pokemon app and gives us a few CSS challenges along the way. Of course, Karl's suggested styles are his personal preference - you could style your app however you like!</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> <span class="hljs-selector-class">.pokemon</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">49%</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#fff</span>;
    <span class="hljs-attribute">background-clip</span>: border-box;
    <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0.125</span>);
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">0.25rem</span>;
    <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">0.125rem</span> <span class="hljs-number">0.25rem</span> <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0.075</span>);
    <span class="hljs-attribute">overflow</span>: hidden;
    <span class="hljs-attribute">margin-bottom</span>: <span class="hljs-number">20px</span>;
}
</code></pre>
<h2 id="heading-responsively-styling-our-application">Responsively styling our application</h2>
<p><a target="_blank" href="https://scrimba.com/p/pdqXpfD/c2K7EgUa?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/tbtvim617msylhr92ld3.png" alt="responsively styled app on extra small screen" width="334" height="622" loading="lazy"></a>
<em>Click the image to access the course.</em></p>
<p>In <a target="_blank" href="https://scrimba.com/p/pdqXpfD/c2K7EgUa?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article">the last scrim</a> of the course, we find out how to responsively style our app with media queries:</p>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">800px</span>) {
    <span class="hljs-selector-class">.container</span> <span class="hljs-selector-class">.pokemon</span> {
        <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
    }
}

<span class="hljs-keyword">@media</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">400px</span>) {
    <span class="hljs-selector-class">.container</span> <span class="hljs-selector-class">.pokemon__attacks</span>,
    <span class="hljs-selector-class">.container</span> <span class="hljs-selector-class">.pokemon__meta</span> {
        <span class="hljs-attribute">flex-wrap</span>: wrap;
    }

    <span class="hljs-selector-class">.container</span> <span class="hljs-selector-class">.pokemon__meta</span> <span class="hljs-selector-tag">span</span>,
    <span class="hljs-selector-class">.container</span> <span class="hljs-selector-class">.pokemon__attacks</span> <span class="hljs-selector-tag">span</span>,
    <span class="hljs-selector-class">.container</span> <span class="hljs-selector-class">.pokemon</span> {
        <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
    }

    <span class="hljs-selector-class">.container</span> <span class="hljs-selector-class">.pokemon__meta</span> <span class="hljs-selector-tag">span</span> {
        <span class="hljs-attribute">margin-bottom</span>: <span class="hljs-number">10px</span>;
    }
}
</code></pre>
<p>Now that's done, our app looks great across all browser sizes.</p>
<p>Well done for completing the course - you've created and styled a fully working React app that hits a GraphQL server, which is a great achievement!</p>
<p>Hopefully, you've learned a lot throughout this course and you'll have a chance to apply your new knowledge to other applications soon. In the meantime, why not head over to <a target="_blank" href="https://scrimba.com?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=greactgraphql_launch_article">Scrimba</a> to see what other courses are on offer? You could even catch 'em all :)</p>
<p>Whatever you decide to learn next, happy programming!</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/w04_SuqvpzY" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Want to Learn Svelte? Here's a Free 16-Part Course by Noah Kaufman ]]>
                </title>
                <description>
                    <![CDATA[ By Per Harald Borgen If you're looking to learn a new Javascript framework which allows you to write less code, use no virtual DOM, and create truly reactive apps, then Svelte is for you. What is Svelte? Svelte is a Javascript framework, a compiler, ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/want-to-learn-svelte-heres-our-free-15-part-course-by-noah-kaufman/</link>
                <guid isPermaLink="false">66d8527929e30bc0ad4775b2</guid>
                
                    <category>
                        <![CDATA[ Scrimba ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Svelte ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 14 May 2020 22:09:51 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/04/jm6s35gtdtf5rijq0uqm.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Per Harald Borgen</p>
<p>If you're looking to learn a new Javascript framework which allows you to write less code, use no virtual DOM, and create truly reactive apps, then Svelte is for you.</p>
<h2 id="heading-what-is-svelte">What is Svelte?</h2>
<p>Svelte is a Javascript framework, a compiler, and a language. Unlike other Frameworks such as React and Vue which do much of their work in the browser, Svelte does its work in the compile step. This results in highly efficient code and a potentially faster run-time on the client-side.</p>
<p>Svelte offers faster development, faster web pages, and a better developer experience - the creators of Svelte created it with other developers in mind). </p>
<p>On top of this, knowing Svelte will help you stand out to potential employers and shows that you're interested in newer technologies.</p>
<h2 id="heading-great-tell-me-about-svelte">Great! Tell me about Svelte.</h2>
<p>This article takes you through Scrimba's brand-new <a target="_blank" href="https://scrimba.com/playlist/pG6X6UG?utm_source=fcc&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_launch_article">16-part Svelte course</a> which covers the following essential topics to put you well on your way to becoming a Svelte master:</p>
<ul>
<li>Components</li>
<li>Importing/exporting</li>
<li>Slots</li>
<li>Template</li>
<li>Event Handling</li>
<li>Event Dispatching</li>
<li>Buttons</li>
<li>Reactivity</li>
<li>Binding</li>
</ul>
<p>The course is delivered through a series of interactive screencasts, allowing you to practice your new skills and truly embed your learning.</p>
<p>Finishing up with an in-depth Final Project which consolidates all the skills learned along the way, the course helps you build the muscle memory needed to become an effective Svelte developer. </p>
<p>It is led by is Noah Kaufman, a Senior Frontend Developer from San Francisco, California with an M.S in Computational Linguistics.</p>
<p>If this sounds right up your street, <a target="_blank" href="https://scrimba.com/g/glearnsvelte?utm_source=fcc&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_launch_article">head on over to the course</a> on Scrimba and read on to find out more.</p>
<h2 id="heading-components">Components</h2>
<p>In Svelte, everything exists inside a component, and the first cast shows what the anatomy of these components looks like. </p>
<p>The component has three optional parts; <code>&lt;script&gt;</code>, which contains Javascript, <code>&lt;style&gt;</code> which contains CSS, and finally some HTML, which is able to use the JS from the <code>&lt;script&gt;</code> tag.</p>
<pre><code class="lang-js">&lt;script&gt;
    <span class="hljs-keyword">let</span> say = <span class="hljs-string">'hi'</span>;
&lt;/script&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
    <span class="hljs-selector-tag">div</span> {
        <span class="hljs-attribute">color</span>: red;
    }
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    Say: {say}
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
</code></pre>
<h2 id="heading-importing-and-exporting">Importing and Exporting</h2>
<p>Here, we take a quick look at how to import and export components so they can be used elsewhere in our app.</p>
<p>Components are imported with the <code>import</code> keyword:</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> Face <span class="hljs-keyword">from</span> <span class="hljs-string">"./Face.svelte"</span>;
</code></pre>
<p>While the <code>export</code> keyword allows other components to change components on import:</p>
<pre><code class="lang-js">&lt;script&gt;
    <span class="hljs-keyword">export</span> <span class="hljs-keyword">let</span> size;
&lt;/script&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"font-size: {size}em"</span>&gt;</span>=)<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
</code></pre>
<h2 id="heading-challenge-1">Challenge 1</h2>
<p>In this cast, Noah challenges us to put our new Svelte skills to the test. No spoilers here, so <a target="_blank" href="https://scrimba.com/p/pG6X6UG/cvdpNRU8?utm_source=fcc&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_launch_article">click through to the course</a> to give the challenge a try and check the solution.</p>
<h2 id="heading-slots">Slots</h2>
<p>Slots allow us to place elements inside components. For example, inserting a <code>&lt;slot&gt;</code> into a <code>&lt;div&gt;</code> with the class <code>Container</code> allows us to place as many elements as we want into the <code>&lt;Container&gt;</code> component:</p>
<pre><code class="lang-js">&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"Container"</span>&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">slot</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">slot</span>&gt;</span></span>
&lt;/div&gt;
</code></pre>
<p>The newly-placed elements are children of the component:</p>
<pre><code class="lang-js">&lt;Container&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Say: {say}<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>

  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Face</span> <span class="hljs-attr">index</span>=<span class="hljs-string">{0}</span> /&gt;</span></span>
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Face</span> /&gt;</span></span>
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Face</span> <span class="hljs-attr">index</span>=<span class="hljs-string">{2}</span> /&gt;</span></span>
&lt;/Container&gt;
</code></pre>
<h2 id="heading-templating">Templating</h2>
<p>The Svelte templating syntax allows us to add if statements and for loops to our HTML. That's right, to our HTML!</p>
<p>An if statement looks like this:</p>
<pre><code class="lang-js">&lt;Container&gt;
    {#<span class="hljs-keyword">if</span> say}
        &lt;div&gt;
            Hi!
        &lt;/div&gt;

    {/<span class="hljs-keyword">if</span>}
&lt;/Container&gt;
</code></pre>
<p>While a for loop looks like this:</p>
<pre><code class="lang-js">{#each [<span class="hljs-number">2</span>,<span class="hljs-number">1</span>,<span class="hljs-number">0</span>] <span class="hljs-keyword">as</span> faceIndex}
        &lt;Face index={faceIndex} /&gt;
    {/each}
</code></pre>
<h2 id="heading-making-header-challenge-2">Making Header - Challenge 2</h2>
<p>In this challenge, we use what we've just learned about Svelte templating to add a Header to our app. <a target="_blank" href="https://scrimba.com/p/pG6X6UG/cGmeLzsR?utm_source=fcc&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_launch_article">Check out the course</a> to try it out for yourself and check your answer.</p>
<h2 id="heading-event-handling">Event Handling</h2>
<p>Next up, Noah shows us a simple inline event handler, which allows the user to show the app's header at the click of a button.</p>
<pre><code class="lang-js">&lt;button
  <span class="hljs-attr">on</span>:click={<span class="hljs-function">() =&gt;</span> {
    showHeader = <span class="hljs-literal">true</span>;
  }}
&gt;
  show
&lt;/button&gt;
</code></pre>
<p>However, if we use a <code>&lt;Button&gt;</code> component rather than a native HTML button, this kind of <code>on:click</code> handler won't work. We can fix this with <strong>event forwarding</strong>, i.e. adding a plain <code>on:click</code> to the native <code>&lt;button&gt;</code> in the component file:</p>
<pre><code class="lang-js">&lt;button on:click&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">slot</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">slot</span>&gt;</span></span>
&lt;/button&gt;
</code></pre>
<h2 id="heading-event-dispatching">Event Dispatching</h2>
<p>Event dispatching allows a component to emit more than one type of event, for example, the same <code>&lt;Button&gt;</code> component can be used both to show an element and to hide it.</p>
<p>We create an event dispatcher like this:</p>
<pre><code class="lang-js">&lt;script&gt;
  <span class="hljs-keyword">import</span> {createEventDispatcher} <span class="hljs-keyword">from</span> <span class="hljs-string">'svelte'</span>; <span class="hljs-keyword">const</span> dispatch =
  createEventDispatcher();
&lt;/script&gt;
</code></pre>
<p>We then add it to native HTML <code>&lt;button&gt;</code> like this:</p>
<pre><code class="lang-js">&lt;button on:click={<span class="hljs-function">() =&gt;</span> dispatch(<span class="hljs-string">'show'</span>)}&gt;
    Show
&lt;/button&gt;
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">on:click</span>=<span class="hljs-string">{()</span> =&gt;</span> dispatch('hide')}&gt;
    Hide
<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>
</code></pre>
<p>Finally we define the <code>&lt;Button&gt;</code>'s functionality options in the <code>App.svelte</code> file like this:</p>
<pre><code class="lang-js">&lt;Buttons
  <span class="hljs-attr">on</span>:show={<span class="hljs-function">() =&gt;</span> {
    showHeader = <span class="hljs-literal">true</span>;
  }}
  <span class="hljs-attr">on</span>:hide={<span class="hljs-function">() =&gt;</span> {
    showHeader = <span class="hljs-literal">false</span>;
  }}
/&gt;
</code></pre>
<p>The same outcome can also be achieved by passing values (in this case <code>true</code> and <code>false</code>) up through the dispatch. The values can then be accessed through the event variable <code>e</code>.</p>
<pre><code>&lt;button on:click={<span class="hljs-function">() =&gt;</span> dispatch(<span class="hljs-string">'click'</span>, <span class="hljs-literal">true</span>)}&gt;
    Show
&lt;/button&gt;
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">on:click</span>=<span class="hljs-string">{()</span> =&gt;</span> dispatch('click', false)}&gt;
    Hide
<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>
</code></pre><pre><code class="lang-js">&lt;Container&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Buttons</span>
    <span class="hljs-attr">on:click</span>=<span class="hljs-string">{(e)</span> =&gt;</span> {
      showHeader = e.detail;
    }}
  /&gt;</span>
&lt;/Container&gt;
</code></pre>
<h2 id="heading-buttons-challenge-3">Buttons - Challenge 3</h2>
<p>Our third challenge is more involved than the previous two and puts our new knowledge of event dispatchers to the test. To help us along, Noah breaks the challenge down into bitesize chunks:</p>
<pre><code class="lang-js">&lt;!-- Challenge <span class="hljs-number">3</span> -
<span class="hljs-number">1.</span> add a prop <span class="hljs-keyword">in</span> Buttons.svelte called buttons which is a list <span class="hljs-keyword">of</span> objects like:
[{<span class="hljs-attr">value</span>: <span class="hljs-string">''</span>, <span class="hljs-attr">text</span>: <span class="hljs-string">''</span>}, ...etc]
<span class="hljs-number">2.</span> use #each to turn all the objects into buttons that:
    a. have innerHTML equal to the .text <span class="hljs-keyword">of</span> the object.
    b. dispatch a click event that passes the .value <span class="hljs-keyword">of</span> the object.
<span class="hljs-number">3.</span> Handle the event <span class="hljs-keyword">in</span> App.svelte to update the score.
--&gt;
</code></pre>
<p><a target="_blank" href="https://scrimba.com/p/pG6X6UG/cp342mTV?utm_source=fcc&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_launch_article">Head over to the course</a> now to give it a try and see the solution.</p>
<h2 id="heading-reactivity">Reactivity</h2>
<p>Reactive statements are a unique feature of Svelte which tell a piece of code to re-run each time a variable within that code is updated. </p>
<p>For example, the code below will run each time the score variable is changed (note that we declare a reactive statement with <code>$:</code>).</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> score = <span class="hljs-number">0</span>;
$: smileySays = <span class="hljs-string">"Hi there, your score is: "</span> + score;
</code></pre>
<p>We can also run if statements inside reactive statements:</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> score = <span class="hljs-number">0</span>;
$: smileySays = <span class="hljs-string">"Hi there, your score is: "</span> + score;
$: <span class="hljs-keyword">if</span> (score &lt; <span class="hljs-number">-4</span>) smileySays = <span class="hljs-string">"Wow your score is low!"</span>;
</code></pre>
<h2 id="heading-reactive-challenge-challenge-4">Reactive Challenge - Challenge 4</h2>
<p>We can now test our new skills by completing the Reactive Challenge, which brings us one step closer to being ready for the final project.</p>
<p>Once again, Noah splits the challenge into smaller parts to help us on our way:</p>
<pre><code class="lang-js">&lt;!-- Challenge <span class="hljs-number">4</span> -
<span class="hljs-number">1.</span> add happyScore and storyIndex (both equal <span class="hljs-number">0</span>)
<span class="hljs-number">2.</span> smileySays and buttons get updated whenever storyIndex changes
<span class="hljs-number">3.</span> add clickHandler <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">that</span> <span class="hljs-title">increments</span> <span class="hljs-title">storyIndex</span> <span class="hljs-title">and</span> <span class="hljs-title">adds</span> <span class="hljs-title">e</span>.<span class="hljs-title">detail</span>.<span class="hljs-title">value</span> <span class="hljs-title">to</span> <span class="hljs-title">the</span> <span class="hljs-title">happyScore</span> --&gt;</span>
</code></pre>
<p><a target="_blank" href="https://scrimba.com/p/pG6X6UG/cgKqRDt9?utm_source=fcc&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_launch_article">Click through to the course</a> to try it out and check your answer.</p>
<h2 id="heading-a-bit-more-reactivity">A Bit More Reactivity</h2>
<p>Next up, Noah gives us another example of using Reactive Statements, an emoji face which changes according the current <code>happyScore</code> variable:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> faceList = [
  <span class="hljs-string">"?"</span>,
  <span class="hljs-string">"?"</span>,
  <span class="hljs-string">"?"</span>,
  <span class="hljs-string">"?"</span>,
  <span class="hljs-string">"?"</span>,
  <span class="hljs-string">"?"</span>,
  <span class="hljs-string">"?"</span>,
  <span class="hljs-string">"?"</span>,
  <span class="hljs-string">"?"</span>,
  <span class="hljs-string">"?"</span>,
  <span class="hljs-string">"?"</span>,
];
$: index = happyScore + <span class="hljs-number">5</span>;
</code></pre>
<p>Similarly to the previous examples, the code runs each time the 'happyScore' variable changes, so a Reactive Statement is just the right tool for the job.</p>
<h2 id="heading-binding">Binding</h2>
<p>Binding allows a user to update a variable (in this case called <code>name</code>) by entering a value into an <code>&lt;input&gt;</code> field. As binding is a two-way process, changing the variable also updates the <code>&lt;input&gt;</code>'s value:</p>
<p>We bind values like this:</p>
<pre><code class="lang-js">&lt;script&gt;
    <span class="hljs-keyword">import</span> Face <span class="hljs-keyword">from</span> <span class="hljs-string">'./Face.svelte'</span>;
    <span class="hljs-keyword">import</span> Container <span class="hljs-keyword">from</span> <span class="hljs-string">'./Container.svelte'</span>;
    <span class="hljs-keyword">import</span> story <span class="hljs-keyword">from</span> <span class="hljs-string">'./story'</span>;

    <span class="hljs-keyword">let</span> showHeader = <span class="hljs-literal">false</span>;
    <span class="hljs-keyword">let</span> storyIndex = <span class="hljs-number">0</span>;
    $: smileySays = story[storyIndex].smileySays;
    <span class="hljs-comment">//variable name below:</span>
    <span class="hljs-keyword">let</span> name = <span class="hljs-string">''</span>;
&lt;/script&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Container</span>&gt;</span>
    //binding declared below:
    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">bind:value</span>=<span class="hljs-string">{name}</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>{name}, {smileySays}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">Container</span>&gt;</span></span>
</code></pre>
<p>As well as binding variables, it's also possible to bind values from objects, lists or components.</p>
<h2 id="heading-final-project">Final Project</h2>
<p><a target="_blank" href="https://scrimba.com/p/pG6X6UG/cgKK4yhG?utm_source=fcc&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_launch_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/mzg89uwkqt4yd0t4ghdz.png" alt="Final Project" width="569" height="503" loading="lazy"></a>
<em>Click the image to access the final project.</em></p>
<p>Well done for making it through the course! We wrap things up with a final project which ties together all the skills we've learned along the way. </p>
<p>Once again Noah breaks it down into smaller chunks to help us through:</p>
<pre><code class="lang-js">&lt;!-- Final Challenge
<span class="hljs-number">1.</span> The header appears <span class="hljs-keyword">if</span> the user chooses Svelte answer
(HINT: happyScore will be greater than <span class="hljs-number">0</span> <span class="hljs-keyword">if</span> they answer Svelte)
<span class="hljs-number">2.</span> Display final message depending on happyScore
<span class="hljs-number">3.</span> Implement the Reset functionality
--&gt;
</code></pre>
<p><a target="_blank" href="https://scrimba.com/p/pG6X6UG/cgKK4yhG?utm_source=fcc&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_launch_article">Check out the cast</a> to test out your news Svelte skills and see the solution.</p>
<h2 id="heading-outro">Outro</h2>
<p>That brings us to the end of the course. Great job for finishing it! And if you're eager to learn more Svelte, do check out the official docs at <a target="_blank" href="https://svelte.dev/">svelte.dev</a> for topics like: <code>Context</code>, <code>Stores</code>, <code>Lifecycle methods</code>, <code>Actions</code>, <code>Sapper</code> and more.</p>
<p>You can also follow my <a target="_blank" href="https://www.youtube.com/channel/UCg6SQd5jnWo5Y70rZD9SQFA">SvelteMaster Youtube Channel</a> and do sign up for the <a target="_blank" href="https://rebrand.ly/sveltebootcamp">Scrimba Svelte Bootcamp</a> to be the first to know about the launch and any discounts.</p>
<p>I hope you've found it useful and can put your brand-new knowledge to good use very soon.</p>
<p>In the meantime, why not <a target="_blank" href="https://scrimba.com/?utm_source=fcc&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_launch_article">head over to Scrimba</a> to see what other courses are on offer to help you reach your coding goals?</p>
<p>If you also want to hang out with your fellow learners or chat with more experienced folks and the creators of Scrimba courses, do join our <a target="_blank" href="https://discord.gg/mF6PcNU">Scrimba Discord server</a>.</p>
<p>Happy learning :)</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/SU25upz4WCI" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
