<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Sławek Kołodziej</title>
    <description>The latest articles on Forem by Sławek Kołodziej (@slawomirkolodziej).</description>
    <link>https://forem.com/slawomirkolodziej</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F302877%2F3a0d5b5a-789c-4870-a255-094c6c0220db.jpeg</url>
      <title>Forem: Sławek Kołodziej</title>
      <link>https://forem.com/slawomirkolodziej</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/slawomirkolodziej"/>
    <language>en</language>
    <item>
      <title>Tailwind CSS: The future of styling or just another CSS framework?</title>
      <dc:creator>Sławek Kołodziej</dc:creator>
      <pubDate>Fri, 15 Jan 2021 15:21:36 +0000</pubDate>
      <link>https://forem.com/slawomirkolodziej/tailwind-css-the-future-of-styling-or-just-another-css-framework-35fo</link>
      <guid>https://forem.com/slawomirkolodziej/tailwind-css-the-future-of-styling-or-just-another-css-framework-35fo</guid>
      <description>&lt;p&gt;My first encounter with Tailwind CSS was through Twitter. The creators of Tailwind are the same people who published a very popular ebook Refactoring UI. I also recognized Steve (one of the creators) from his Youtube series &lt;a href="https://www.youtube.com/c/SteveSchoger/videos"&gt;Refactoring UI&lt;/a&gt; where he redesigns views of real application while explaining all of his choices.&lt;/p&gt;

&lt;p&gt;With this in mind I knew Tailwind isn't just a random CSS framework but something bigger.&lt;/p&gt;

&lt;p&gt;I didn't had to wait too long. Creators of Tailwind CSS quickly released &lt;a href="https://tailwindui.com/"&gt;Tailwind UI&lt;/a&gt; - a paid set of UI components built on top of Tailwind CSS making &lt;a href="https://adamwathan.me/tailwindcss-from-side-project-byproduct-to-multi-mullion-dollar-business/"&gt;$2 million in revenue in 2020&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I decided to use Tailwind CSS for my blog redesign
&lt;/h2&gt;

&lt;p&gt;I never really liked CSS frameworks. Back in the days, when Bootstrap was as its peak, the only feature I found useful was its grid system. Yes, I used the one based on &lt;code&gt;float: left&lt;/code&gt;. Then flex and grid became widely supported by browsers and using ready-made grid system didn't make sense to me anymore.&lt;/p&gt;

&lt;p&gt;Also what I didn't like was how ugly and outdated default styles of Bootstrap are.&lt;/p&gt;

&lt;p&gt;The other thing was it became nearly impossible to use any CSS Framework while creating UIs based on a custom design.&lt;/p&gt;

&lt;p&gt;Tailwind CSS looked like the first framework I would enjoy using. I already saw how easily you can create beautiful UIs with it (thanks to Tailwind UI project). It also offers easy customization options allowing to work with custom designs, although right now I'm still not 100% convinced on this one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pros of using Tailwind CSS
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Tailwind CSS just looks good
&lt;/h3&gt;

&lt;p&gt;Although it's primarily an utility CSS framework it offers very modern and pleasing styling options. Authors already made design decisions when it comes to colors, shadows, borders, typography and also spacing options. It's a way easier to come up with a slick UI when you have limited options that work well together than writing CSS from scratch. Trust me, I tried both.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TTo4H3u9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pg8px2ik45srper86e6g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TTo4H3u9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pg8px2ik45srper86e6g.png" alt="https://tailwindcss.com/"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tailwindcss.com/"&gt;https://tailwindcss.com/&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Tailwind CSS has a great IDE support
&lt;/h3&gt;

&lt;p&gt;I'm using VS Code and thanks to &lt;a href="https://github.com/tailwindlabs/tailwindcss-intellisense"&gt;Tailwind CSS Intellisense extension&lt;/a&gt; I was able to see all available Tailwind CSS classes as suggestions.&lt;/p&gt;

&lt;p&gt;But the real power of this extension comes from its integration with the Tailwind configuration for given project. Let's say you added your custom color and modified some spacing option. You will see your changes as suggestions when writing CSS classes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a-2CgDcG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/k0xr1qac3jgwqyi2duty.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a-2CgDcG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/k0xr1qac3jgwqyi2duty.png" alt="https://tailwindcss.com/docs/intellisense"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tailwindcss.com/docs/intellisense"&gt;https://tailwindcss.com/docs/intellisense&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  It allows for very quick prototyping
&lt;/h3&gt;

&lt;p&gt;Developing a new feature often comes with trying different solutions to see what's working and what's not.&lt;/p&gt;

&lt;p&gt;My standard workflow for creating a new piece of UI is coming up with a good name, going to a separate place to create a styled components (I use CSS-in-JS a lot) and then using this component. For the plain CSS the steps are quite similar.&lt;/p&gt;

&lt;p&gt;When working with Tailwind CSS I don't not have to switch between my HTML and the place where I define styles. I can use few classes to define the final look of HTML element. I don't have to come up with weird names like &lt;code&gt;container&lt;/code&gt;, &lt;code&gt;content-container&lt;/code&gt; or &lt;code&gt;page-header-wrapper&lt;/code&gt; just to add a &lt;code&gt;display: flex&lt;/code&gt; to some element.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cons of using Tailwind CSS
&lt;/h2&gt;

&lt;p&gt;Although on paper Tailwind looks like a perfect tool, after using it in real project you will start to notice some downsides.&lt;/p&gt;

&lt;h3&gt;
  
  
  You still have to style the UI by yourself
&lt;/h3&gt;

&lt;p&gt;Tailwind doesn't style any elements by default. More than that, it removes default styles from elements like lists and inputs. While developing your own site you still have to choose typography, colors, sizing and position of elements. &lt;/p&gt;

&lt;p&gt;Tailwind doesn't offer any ready-made components by default. Thankfully there are already two plugins that introduce default styling for elements: &lt;a href="https://github.com/tailwindlabs/tailwindcss-typography"&gt;tailwindcss-typography&lt;/a&gt; and &lt;a href="https://github.com/tailwindlabs/tailwindcss-custom-forms"&gt;tailwindcss-typography&lt;/a&gt;. If you are struggling with coming up with good design watch &lt;a href="https://youtube.com/playlist?list=PL7CcGwsqRpSM3w9BT_21tUU8JN2SnyckR"&gt;Designing with TailwindCSS on Youtube&lt;/a&gt; from Adam Wathan - creator of Tailwind.&lt;/p&gt;

&lt;h3&gt;
  
  
  Looong list of CSS classes
&lt;/h3&gt;

&lt;p&gt;This is the argument you will hear a lot as a downside of Tailwind. While for simple layout elements it isn't that much overwhelming, you will start notice the issue when styling UI components. Other than that it will be harder to recognize parts of the website when reading the code.&lt;br&gt;
In the usual approach CSS classes usually contain name of the element and describe its function. With utility-first approach this part is missing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gdh7vMQu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9rqcxz0f8t21z5ng4cb6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gdh7vMQu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9rqcxz0f8t21z5ng4cb6.png" alt="Pagination link component from my blog"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pagination link component from my blog&lt;/p&gt;

&lt;p&gt;The first solution to this issue is creating regular css files and using &lt;code&gt;@apply&lt;/code&gt; to include Tailwind utilities to CSS classes. You can read more about it in the &lt;a href="https://tailwindcss.com/docs/installation#using-a-custom-css-file"&gt;documentation&lt;/a&gt;. It sounds right but then we might as well not use Tailwind at all and write regular CSS.&lt;/p&gt;

&lt;p&gt;The second solution is to use the power of JavaScript frameworks and separate UI elements as components. You might still have a button with 13 different CSS classes but now it will be a proper component. Usually after creating such component once, you might not look into it for a while. You will be able to ignore the styling part when the component is done and do not bother reading all of the CSS classes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Limited options when working with designers
&lt;/h3&gt;

&lt;p&gt;This is my main problem with all of the CSS frameworks. Custom designs usually do not respect the boundaries of CSS framework. Thankfully Tailwind is very flexible and you can recreate almost any design. &lt;/p&gt;

&lt;p&gt;The main limitations are with sizing and spacing values. I would recommend talking with your designer about it before you start working together on something. I would also want to see some official style guide of Tailwind so designers could base their work on it. Also remember that Tailwind is highly customizable and you can add your own sizes, colors etc. if you need to.&lt;/p&gt;

&lt;h2&gt;
  
  
  My conclusions after using Tailwind CSS
&lt;/h2&gt;

&lt;h3&gt;
  
  
  I need more experience with it
&lt;/h3&gt;

&lt;p&gt;Tailwind at its own isn't too hard to learn. What I would want to explore is the tooling around it ex. &lt;a href="https://github.com/ben-rogerson/twin.macro"&gt;twin.macro&lt;/a&gt; which aims to solve issue with long CSS class names and avoid creating separate CSS files at the same time. I also want discover more good practices.&lt;/p&gt;

&lt;h3&gt;
  
  
  I won't use it for commercial projects yet
&lt;/h3&gt;

&lt;p&gt;I usually avoid using any CSS frameworks for more complex commercial projects due to its limitations. For now, Tailwind is no exception for me. I don't want to experiment in a commercial project when not everyone in a team is familiar with Tailwind and knows about its good and bad practices. Creating components and using SCSS or CSS-in-JS is usually enough for this type of work.&lt;/p&gt;

&lt;p&gt;The only place where I would consider using it are marketing pages with a short time to deliver.&lt;/p&gt;

&lt;p&gt;This opinion might change if we will have more experience with Tailwind as a community.&lt;/p&gt;

&lt;h3&gt;
  
  
  I will still use it for my own projects
&lt;/h3&gt;

&lt;p&gt;Styling with Tailwind is very fast and fun. I think is the only tool since I learned React that I truly enjoy using.&lt;/p&gt;

&lt;p&gt;The redesign of my blog took overall few hours to complete. I know I would struggle longer with plain CSS to come up with good looking UI.&lt;/p&gt;

&lt;p&gt;As for my own projects I don't care that much about great code quality since the scale and the need of maintenance is usually very low. It's a good place to make mistakes and experiment with new tools.&lt;/p&gt;




&lt;p&gt;I'm regularly publishing my insights on web development. &lt;br&gt;
Consider &lt;a href="https://slawkolodziej.com/newsletter"&gt;subscribing to my newsletter&lt;/a&gt;.&lt;br&gt;
Visit my blog at &lt;a href="https://slawkolodziej.com"&gt;slawkolodziej.com&lt;/a&gt; to find out more interesting content.&lt;br&gt;
Follow me on &lt;a href="https://twitter.com/slawkolodziej"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Arrow functions in JavaScript: Everything you need to know about them</title>
      <dc:creator>Sławek Kołodziej</dc:creator>
      <pubDate>Wed, 06 Jan 2021 14:58:37 +0000</pubDate>
      <link>https://forem.com/slawomirkolodziej/arrow-functions-in-javascript-everything-you-need-to-know-about-them-5c10</link>
      <guid>https://forem.com/slawomirkolodziej/arrow-functions-in-javascript-everything-you-need-to-know-about-them-5c10</guid>
      <description>&lt;p&gt;&lt;strong&gt;Arrow function&lt;/strong&gt; is an alternative form of creating a function in JavaScript. It was introduced in ES6.&lt;/p&gt;

&lt;p&gt;They go by name &lt;code&gt;arrow functions&lt;/code&gt;, because they are created with arrow symbol - &lt;code&gt;=&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The main benefit of arrow functions is a short syntax which most of the times increases code readability. They come really handy when you need to quickly create a function that is an argument for another function.&lt;/p&gt;

&lt;p&gt;In most cases they can be used interchangeably with regular functions but you need to remember about few differences.&lt;/p&gt;

&lt;p&gt;Arrow functions are anonymous functions. It means they cannot have a name. You can bypass it by assigning them to a variable and call them with this variable name.&lt;/p&gt;

&lt;p&gt;Let's take a look at the simple conversion from regular function to arrow function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// we assign an anonymous to a variable&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// we remove "function" keyword and add an arrow after arguments&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code sample above shows 3 ways to declare a function. In the last one we are using &lt;code&gt;=&amp;gt;&lt;/code&gt;. Notice we don't need a &lt;code&gt;function&lt;/code&gt; keyword anymore to declare a function. We also added &lt;code&gt;=&amp;gt;&lt;/code&gt; after list of arguments.&lt;/p&gt;

&lt;p&gt;Arrow function allow us to use even shorter syntax.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// returns x + y&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// the same function in one line&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;

&lt;span class="c1"&gt;// you can skip parentheses when using only one argument&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;add1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If your function contains only the &lt;code&gt;return&lt;/code&gt; you can use the short form of arrow functions.&lt;/p&gt;

&lt;p&gt;You can omit &lt;code&gt;{&lt;/code&gt; &lt;code&gt;}&lt;/code&gt; and &lt;code&gt;return&lt;/code&gt; keyword and the expression after &lt;code&gt;=&amp;gt;&lt;/code&gt; will be the value returned from this function.&lt;/p&gt;

&lt;p&gt;When you return an object you need to remember about adding &lt;code&gt;(&lt;/code&gt; &lt;code&gt;)&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// this won't work&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;createUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case the curly braces used to create the object will conflict with curly braces used to create a function body. You need to add parentheses to ensure you are returning an object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;createUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using short form to improve code readability
&lt;/h2&gt;

&lt;p&gt;Let's take a look how using short form of arrow function can improve code readability when returning a function from other function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;createAddFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;createAddFunction&lt;/code&gt; is a function which creates other function. This pattern is called &lt;code&gt;currying&lt;/code&gt; and you can read about it more at &lt;a href="https://slawkolodziej.com/posts/what-is-function-currying-in-javascript-and-when-to-use-it"&gt;What is Function Currying in JavaScript and When to Use It&lt;/a&gt;. You can use it for example to create a function which increments a number by &lt;code&gt;1&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;add1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createAddFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;add1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The definition of &lt;code&gt;createAddFunction&lt;/code&gt; can be shortened by using features of arrow function we just learned. Let's take a look at the steps to reduce it to one line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// initial version&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;createAddFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// changing the inner function to arrow function&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;createAddFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// changing the outer function to arrow function&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;createAddFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// one line version&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;createAddFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What are the differences between regular and arrow functions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;this&lt;/code&gt; in arrow functions
&lt;/h3&gt;

&lt;p&gt;The most important difference is how &lt;code&gt;this&lt;/code&gt; behaves inside those 2 function declaration types.&lt;/p&gt;

&lt;p&gt;Arrow functions do not create its own &lt;code&gt;this&lt;/code&gt; but use its value from the place they were defined.&lt;/p&gt;

&lt;p&gt;The explanation of &lt;code&gt;this&lt;/code&gt; in JavaScript would need a separate blog post, but I will show you few examples illustrating the differences.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;logThisOutside&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;My Button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;logThis&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;logThisArrow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;logThis&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// Window&lt;/span&gt;
    &lt;span class="nx"&gt;logThisArrow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// { name: 'My Button' }&lt;/span&gt;
    &lt;span class="nx"&gt;logThisOutside&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// Window&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see &lt;code&gt;logThisArrow&lt;/code&gt; and &lt;code&gt;logThisOutside&lt;/code&gt; use the value of &lt;code&gt;this&lt;/code&gt; from the place they were defined in. It happens because as apposed to regular function, arrow functions do not create its own &lt;code&gt;this&lt;/code&gt;, but use the value from the outer scope.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using &lt;code&gt;this&lt;/code&gt; in arrow functions to your advantage
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;My Button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;that&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Button DOM Element&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;that&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;that&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// { name: 'My Button' }&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Button Clicked&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="c1"&gt;// won't work as expected&lt;/span&gt;
    &lt;span class="nx"&gt;that&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Button Clicked&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="c1"&gt;// name value changed&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click arrow&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// { name: 'My Button' }&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Button Clicked&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="c1"&gt;// name value changed&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We created two event listeners. In one of the we used regular function and arrow function in the other one.&lt;/p&gt;

&lt;p&gt;In case of regular function in event listener, when you click on a button &lt;code&gt;this&lt;/code&gt; will have a value of DOM element that was clicked. If we would want to change the value of &lt;code&gt;this.name&lt;/code&gt; we would have to first create a variable &lt;code&gt;const that = this&lt;/code&gt; and then modify it by &lt;code&gt;that.name = 'Button Clicked'&lt;/code&gt;. It's a common hack used to modify &lt;code&gt;this&lt;/code&gt; from outer scope.&lt;/p&gt;

&lt;p&gt;As a mentioned before, arrow functions do not create its own &lt;code&gt;this&lt;/code&gt; so you can safely change value of &lt;code&gt;name&lt;/code&gt; by &lt;code&gt;this.name = 'Button Clicked&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Accessing arguments in arrow functions
&lt;/h3&gt;

&lt;p&gt;The other feature of arrow functions is they do not create a special variable &lt;code&gt;arguments&lt;/code&gt; inside a function body.&lt;/p&gt;

&lt;p&gt;Let's see how &lt;code&gt;arguments&lt;/code&gt; work in regular function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// console: [1, 2, 3]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Regular function has access to special &lt;code&gt;arguments&lt;/code&gt; variable that stores all arguments that function was called with even if they were not defined between the parenthesis.&lt;/p&gt;

&lt;p&gt;Arrow functions do not create &lt;code&gt;arguments&lt;/code&gt; variable but there is other solution we can use to achieve the same - rest parameters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// console: [1, 2, 3]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Arrow functions offer a short syntax for creating functions. They allow to omit keywords like &lt;code&gt;function&lt;/code&gt; and &lt;code&gt;return&lt;/code&gt; to improve readability of your code. Please use it we caution because too much nested arrow functions can create code which is confusing for readers.&lt;/p&gt;

&lt;p&gt;Arrow functions do not create its own &lt;code&gt;this&lt;/code&gt; and &lt;code&gt;arguments&lt;/code&gt; special variables which is its main difference from regular functions.&lt;/p&gt;

&lt;p&gt;If you want to read about other differences check out &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions"&gt;MDN Arrow function expressions&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;I'm regularly publishing my insights on web development. &lt;br&gt;
Consider &lt;a href="https://slawkolodziej.com/newsletter"&gt;subscribing to my newsletter&lt;/a&gt;.&lt;br&gt;
Visit my blog at &lt;a href="https://slawkolodziej.com"&gt;slawkolodziej.com&lt;/a&gt; to find out more interesting content.&lt;br&gt;
Follow me on &lt;a href="https://twitter.com/slawkolodziej"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>My 2020 In Review: What I Learned and Accomplished as Senior Front-end Developer</title>
      <dc:creator>Sławek Kołodziej</dc:creator>
      <pubDate>Mon, 28 Dec 2020 19:15:04 +0000</pubDate>
      <link>https://forem.com/slawomirkolodziej/my-2020-in-review-what-i-learned-and-accomplished-as-senior-front-end-developer-3n34</link>
      <guid>https://forem.com/slawomirkolodziej/my-2020-in-review-what-i-learned-and-accomplished-as-senior-front-end-developer-3n34</guid>
      <description>&lt;p&gt;With 2020 coming to an end (finally!) I decided to do a little summary of things I learned during this year.&lt;/p&gt;

&lt;p&gt;At first I wanted to point out I would not be able to remember every thing I will list here without a journal. To be more specific, in the place I work in we have quarterly performance reviews and to make it more smooth we maintain a document with list of all our accomplishments and observations. It made creating this post a lot easier and I would recommend it for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  January
&lt;/h2&gt;

&lt;h3&gt;
  
  
  I was promoted to Senior Front-end Developer
&lt;/h3&gt;

&lt;p&gt;A very happy start of the year. After more than 2 years working at this company I became a &lt;code&gt;Senior&lt;/code&gt;. It was preceded by promotion proposal made by my leader and discussion about my accomplishments with management of Frontend Unit.&lt;/p&gt;

&lt;h3&gt;
  
  
  I created a tool to automatically export SVG icons from Figma
&lt;/h3&gt;

&lt;p&gt;I open sourced &lt;a href="https://github.com/slawomirkolodziej/figma-api-exporter"&gt;Figma API Exporter&lt;/a&gt;. A package to export all SVG icons from Figma using JavaScript. The idea about Figma automation started with my project where we implemented &lt;a href="https://github.com/tiltshift/figmint"&gt;Figmint&lt;/a&gt; to sync colors and typography styles from Figma to our code on every deployment. We wanted to also include sync our custom icons, but there wasn't any tool available at the time. So I decided to create it.&lt;/p&gt;

&lt;h3&gt;
  
  
  I finished &lt;a href="https://frontendmasters.com/courses/angular-core/"&gt;Angular Core&lt;/a&gt; course on Frontend Masters
&lt;/h3&gt;

&lt;p&gt;Frontend Masters is still my favourite platform for learning. They say it's good to keep your friends close but enemies closer so I decided to learn more about Angular. My key observations are that it works very well with TS and has strong opinions about the project structure. When Angular developer switches projects the chances are he will feel familiar as opposed to React where everything is a wild west.&lt;/p&gt;

&lt;p&gt;The interesting part of this course was also introduction of &lt;a href="https://github.com/nrwl/nx"&gt;nrwl/nx&lt;/a&gt;. It's a tool to manage monorepos. It made me thing about using monorepos more in React projects.&lt;/p&gt;

&lt;p&gt;The downside of Angular for me was its flexibility. I remember when I wanted to create a modal in Angular and I spend too much time looking for suitable solution. Maybe it's my lack of experience in Angular, but I appreciate React ecosystem more for creating a very dev friendly components.&lt;/p&gt;

&lt;h2&gt;
  
  
  February
&lt;/h2&gt;

&lt;h3&gt;
  
  
  I finished &lt;a href="https://testingjavascript.com/"&gt;Testing JavaScript&lt;/a&gt; course by Kent C.Dodds
&lt;/h3&gt;

&lt;p&gt;I was already familiar with Kent C. Dodds from Frontend Masters, but this course is a very good introduction into the world of JavaScript/React testing. The most interesting for me were solutions for mocking modules in Jest and working with external libraries in tests. Kent presented very well thought solutions in form of short screencasts (there is a lot of them).&lt;/p&gt;

&lt;h3&gt;
  
  
  I've read &lt;a href="https://www.goodreads.com/book/show/44333183-the-unicorn-project"&gt;The Unicorn Project by Gene Kim&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;I think it was the only work related book I fully enjoyed reading (besides The Phoenix Project). Gene tells a story from his other book, The Phoenix Project, but this time from a point of view of developer. It gave me a motivation to look for improvements in my daily life at work and question the rules if they make no sense.&lt;/p&gt;

&lt;h2&gt;
  
  
  March
&lt;/h2&gt;

&lt;h3&gt;
  
  
  I co-created a template for Create React App
&lt;/h3&gt;

&lt;p&gt;At this time new version of CRA was published with a feature called &lt;a href="https://create-react-app.dev/docs/custom-templates/"&gt;Custom Templates&lt;/a&gt;. It allows to customize the default project structure and dependencies of new Create React App project. I created it within a team at work to configure Prettier, ESLint, Commitizen and custom deployment scripts for all new React projects in a company. I turned out to be very successful, allowing developers to deploy their first applications to AWS in 10-15 minutes.&lt;/p&gt;

&lt;h3&gt;
  
  
  I finished &lt;a href="https://frontendmasters.com/courses/complete-intro-containers/"&gt;Complete Intro to Containers&lt;/a&gt; and &lt;a href="https://frontendmasters.com/courses/fullstack-v2/"&gt;Full Stack for Front-End Engineers&lt;/a&gt; on Frontend Masters
&lt;/h3&gt;

&lt;p&gt;I wanted to move more into Fullstack role at the time so I decided to pick up those 2 courses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Complete Intro to Containers&lt;/strong&gt; starts with setting up containers by hand using &lt;code&gt;chown&lt;/code&gt; command and moves to everything you should know about Docker. I knew how to set up Docker before but this course for sure gave me full information to work with it comfortably.&lt;/p&gt;

&lt;p&gt;On the other hand &lt;strong&gt;Full Stack for Front-End Engineers&lt;/strong&gt; talks more about setting up your own server and tons of other thing you didn't know about web development if you only focused on Frontend development. Definitely a good introduction to so many good topics you might want to explore more yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  April
&lt;/h2&gt;

&lt;h3&gt;
  
  
  I finally started using React hooks at work!
&lt;/h3&gt;

&lt;p&gt;When I started working in this project it was React 0.14, but in April we finally migrated it to React 16.8+. It was a year and 2 months after the stable version of hooks was published. I had a chance to learn them before, but didn't put too much attention because I couldn't use them at work. &lt;/p&gt;

&lt;h2&gt;
  
  
  May
&lt;/h2&gt;

&lt;h3&gt;
  
  
  I finished &lt;a href="https://learn.particular.net/courses/adsd-online"&gt;Advanced Distributed Systems Design Course&lt;/a&gt; by Udi Dahan
&lt;/h3&gt;

&lt;p&gt;Although it now costs $2500 😵  it was available for free for some time. I took this course as a part of learning more about backend stuff. Udi is a great and engaging teacher. He was giving a lot of example how distributed systems could be used in practice, ex. in booking systems. The great value of this course was also the fact it was recorded with very experienced participants, who attended this workshop live.&lt;/p&gt;

&lt;h2&gt;
  
  
  June
&lt;/h2&gt;

&lt;h3&gt;
  
  
  I finished &lt;a href="https://frontendmasters.com/courses/go-for-js-devs/"&gt;Go for JavaScript Developers&lt;/a&gt; course on Frontend Masters
&lt;/h3&gt;

&lt;p&gt;I already knew some basics from languages like Ruby, PHP, Python, Java, but Go was entirely new to me. What I liked the most about Go was that it is strongly typed language. If I figured out the types then I was almost sure the program would run correctly, I had a similar experience with Haskell. The other nice thing was the ability to explicitly pass variables by value or reference.&lt;/p&gt;

&lt;h2&gt;
  
  
  July
&lt;/h2&gt;

&lt;h3&gt;
  
  
  I started doing &lt;a href="https://gophercises.com/"&gt;Gophercises&lt;/a&gt; - exercises to learn Go
&lt;/h3&gt;

&lt;p&gt;I think these are one of the best exercises for learning new language I've seen. I expected building a dummy REST API, but it ended up building a quiz, choose your own adventure game and url shortener. There is a total of 20 video tutorials with introduction and a complete solution.&lt;/p&gt;

&lt;p&gt;If I would want to invest more time into Go I would definitely buy other paid courses from the same author.&lt;/p&gt;

&lt;h2&gt;
  
  
  August
&lt;/h2&gt;

&lt;h3&gt;
  
  
  I took a long vacation!
&lt;/h3&gt;

&lt;h2&gt;
  
  
  September
&lt;/h2&gt;

&lt;h3&gt;
  
  
  I worked with &lt;a href="https://github.com/marmelab/react-admin"&gt;React Admin&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;I started working in a new project in my job and had a chance to see React Admin in use for the first time. I knew about it before but I wasn't aware how great it is. It's definitely not for everyone, I would use it if I wouldn't care about the visuals and more custom features. It helped us create an admin panel in a very short time.&lt;/p&gt;

&lt;h2&gt;
  
  
  October
&lt;/h2&gt;

&lt;h3&gt;
  
  
  I started working as a Node.js developer in a project
&lt;/h3&gt;

&lt;p&gt;The project I joined in September had a backend written in Node.js and I saw it as an opportunity to work more on backend. The app was built with Nest.js. I started with simple changes to the REST API we needed on frontend and progressed with more advanced stuff. The most interesting feature I've built was generating PDFs.&lt;/p&gt;

&lt;h3&gt;
  
  
  I started my &lt;a href="https://slawkolodziej.com"&gt;developer blog&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;It all started with signing up for &lt;a href="https://bloggingfordevs.com/"&gt;BloggingForDevs&lt;/a&gt; newsletter, which inspired me to start my own blog. I create one post a week and posted it on &lt;a href="https://dev.to/slawomirkolodziej"&gt;dev.to&lt;/a&gt; with a link to my original blog. Most of the traffic came from this source, but after few weeks it started gaining organic traffic from Google. For my blog I used Gatsby and a theme I didn't modified. My goal was focus on content first and then take care of technical stuff. I didn't wanted to build my blog from scratch for few weeks and have no content 😃 .&lt;/p&gt;

&lt;h2&gt;
  
  
  November
&lt;/h2&gt;

&lt;h3&gt;
  
  
  I started working on an internal course about testing React components
&lt;/h3&gt;

&lt;p&gt;I took one day a week to work entirely on this project. I wrote several chapters about testing components, mocking API calls, working with libraries like Redux and React Router and more. It was definitely the biggest project outside of programming I've ever made. It wasn't launched yet but I expect it to help many people and introduce better testing practices.&lt;/p&gt;

&lt;h2&gt;
  
  
  December
&lt;/h2&gt;

&lt;h3&gt;
  
  
  I redesigned my blog with &lt;a href="https://tailwindcss.com/"&gt;Tailwind CSS&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;You can love or hate Tailwind. For me it made it possible to do the redesign very quickly, I think it was only a couple of hours. The best think about it is that the final effect just looks good, you don't have to put too much time into the details. &lt;a href="https://tailwindcss.com/docs/typography-plugin"&gt;Tailwind typography plugin&lt;/a&gt; works great with content generated by Gatsby. Also I didn't have to write a single line of CSS! I think I will create a separate post about good and bad parts of Tailwind I learned during the redesign.&lt;/p&gt;




&lt;p&gt;I'm regularly publishing my insights on web development. &lt;br&gt;
Consider &lt;a href="https://slawkolodziej.com/newsletter"&gt;subscribing to my newsletter&lt;/a&gt;.&lt;br&gt;
Visit my blog at &lt;a href="https://slawkolodziej.com"&gt;slawkolodziej.com&lt;/a&gt; to find out more interesting content.&lt;br&gt;
Follow me on &lt;a href="https://twitter.com/slawkolodziej"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>career</category>
      <category>react</category>
    </item>
    <item>
      <title>What is Function Currying in JavaScript and When to Use It</title>
      <dc:creator>Sławek Kołodziej</dc:creator>
      <pubDate>Mon, 21 Dec 2020 20:39:34 +0000</pubDate>
      <link>https://forem.com/slawomirkolodziej/what-is-function-currying-in-javascript-and-when-to-use-it-2nmd</link>
      <guid>https://forem.com/slawomirkolodziej/what-is-function-currying-in-javascript-and-when-to-use-it-2nmd</guid>
      <description>&lt;p&gt;Currying is a way of building functions in a way that it is possible to call them with arguments one by one, instead of all of them at once. It will allow us to create new functions, which have some arguments already remembered. Currying helps with creating specialized functions based on general ones, ex. &lt;code&gt;getName&lt;/code&gt;, &lt;code&gt;findId&lt;/code&gt;, &lt;code&gt;joinWithSpaces&lt;/code&gt; from &lt;code&gt;get&lt;/code&gt;, &lt;code&gt;find&lt;/code&gt;, &lt;code&gt;join&lt;/code&gt;. It helps reducing code duplication.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a curried function
&lt;/h2&gt;

&lt;p&gt;Let me start with very simple example, &lt;code&gt;sum&lt;/code&gt; function in curried form:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// using arrow function&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks strange at first sight, but let me explain it.&lt;/p&gt;

&lt;p&gt;After calling &lt;code&gt;sum(5)&lt;/code&gt; it won't return a number, but a new function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// a was changed to 5&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// using arrow function&lt;/span&gt;

&lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only after we call it the second time we will get the final result - sum of two numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// using arrow function&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;addTo5&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// function(b) { return 5 + b }&lt;/span&gt;

&lt;span class="nx"&gt;addTo5&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 8&lt;/span&gt;
&lt;span class="c1"&gt;// is the same as&lt;/span&gt;
&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 8&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Summing up, we created specialized function &lt;code&gt;addTo5&lt;/code&gt; which has only one purpose - adding some number to 5. Function &lt;code&gt;sum&lt;/code&gt; is more general.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to use the curried function
&lt;/h2&gt;

&lt;p&gt;Let's see another curried function, which you might use in your application. Function &lt;code&gt;get&lt;/code&gt; will take &lt;code&gt;key&lt;/code&gt; name, return a function which takes &lt;code&gt;object&lt;/code&gt; and in the end return a value for provided &lt;code&gt;key&lt;/code&gt;. One use-case if using it as an argument for &lt;code&gt;Array.map&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// using arrow function&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Emma&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;namesList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// normal way&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;namesList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;getName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// using specialized function&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;namesList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// using general function&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see this example is more practical. Because &lt;code&gt;object&lt;/code&gt; is the last argument, we can pass this "unfinished" function to &lt;code&gt;map&lt;/code&gt;, which calls this function with object. As a result we get value of &lt;code&gt;name&lt;/code&gt; from the object.&lt;/p&gt;

&lt;p&gt;Notice how more readable is this example when using &lt;code&gt;get&lt;/code&gt; function -  &lt;code&gt;users.map(getName)&lt;/code&gt;, you immediately understand what this code fragment does.&lt;/p&gt;

&lt;h2&gt;
  
  
  Good practices of creating curried functions
&lt;/h2&gt;

&lt;p&gt;When creating your own curried function you should follow one important rule.&lt;/p&gt;

&lt;p&gt;Always leave the source of data as the last argument. To determine the order of other "configuration" arguments, think about function use-cases.&lt;/p&gt;

&lt;p&gt;Let's take a look at the &lt;code&gt;get&lt;/code&gt; function where source of data (&lt;code&gt;object&lt;/code&gt;) is NOT the last argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// using arrow function&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Adam&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Maciej&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}]&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;namesList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see using &lt;code&gt;get&lt;/code&gt; function in this form doesn't make sense. And you can't really create a specialized function since you don't have access to the object yet. It is a good practice to leave the source of data as the last argument, because looking at the use-cases it usually comes at the end when executing the code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating curried functions from standard function
&lt;/h2&gt;

&lt;p&gt;In JavaScript world we are not used to curried functions, but looking at the use-cases it looks very promising. Actually we can create a function which is both curried and not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 8&lt;/span&gt;
&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 8&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;add&lt;/code&gt; is called with one argument &lt;code&gt;args.length === 1&lt;/code&gt;, then we return new function where first argument is remembered, just like we did before. But if we call it with two arguments, it will just add them and return a sum.&lt;/p&gt;

&lt;p&gt;You have to admit that it is very impressive, but the definition of this function is very complicated now and it's only summing up two numbers.&lt;/p&gt;

&lt;p&gt;Thankfully there is a helper function which will help us with it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;curry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;argsLength&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;originalFunction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prevArgs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;curriedFunction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nextArgs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;allArgs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;prevArgs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;nextArgs&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;allArgs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;argsLength&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// all arguments are provided, call the function&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;originalFunction&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;allArgs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;([])&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It looks even more complicated but with it, we can simply transform the standard function into a curried one. Just remember that the first argument of &lt;code&gt;curry&lt;/code&gt; is the number of arguments it can take, and the second one is the function itself;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;curry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;addTo5&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 8&lt;/span&gt;
&lt;span class="nx"&gt;addTo5&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 8&lt;/span&gt;
&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 8&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you don't have to worry about how many arguments you call the function with. You call the function like you did before you got to know about currying or call the function, by one argument at a time.&lt;/p&gt;




&lt;p&gt;I'm regularly publishing my insights on web development. &lt;br&gt;
Consider &lt;a href="https://slawkolodziej.com/newsletter"&gt;subscribing to my newsletter&lt;/a&gt;.&lt;br&gt;
Visit my blog at &lt;a href="https://slawkolodziej.com"&gt;slawkolodziej.com&lt;/a&gt; to find out more interesting content.&lt;br&gt;
Follow me on &lt;a href="https://twitter.com/slawkolodziej"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Personal Story: My journey to find a perfect job as JavaScript Developer</title>
      <dc:creator>Sławek Kołodziej</dc:creator>
      <pubDate>Mon, 16 Nov 2020 12:26:30 +0000</pubDate>
      <link>https://forem.com/slawomirkolodziej/personal-story-my-journey-to-find-a-perfect-job-as-javascript-developer-2m48</link>
      <guid>https://forem.com/slawomirkolodziej/personal-story-my-journey-to-find-a-perfect-job-as-javascript-developer-2m48</guid>
      <description>&lt;p&gt;I've always been interested in programming, but only in high school I got hooked into web development. It was (and still is) very approachable for newcomers, with great free resources and tools available online. This is why I decided to learn all about web development and look for a programming job immediately after high school. I didn't wanted to go to college at the time. I considered it a waste of time, time which I could use to gain experience and money on the job.&lt;/p&gt;

&lt;p&gt;I will tell you a story about my first 3 (almost 4) jobs as Front-end Developer. Why those 3 in particular? Because only at the last one I felt like in the right place and working with technologies I really wanted to work with. The first two were very important part of my journey so I wanted to include them.&lt;/p&gt;

&lt;h2&gt;
  
  
  The job I never treated like a job
&lt;/h2&gt;

&lt;p&gt;During high school I really wanted to do some commercial work. I wanted to prove my parents and myself that it's a right profession for me and I can make money out of it. I started to look for a side job online and reply to the listings. I've got one answer from a Pole living in UK asking if I can do WordPress stuff. I just started learning WordPress few weeks ago, but I've send him what I did so far. He said it was a little, but I can start working for him.&lt;/p&gt;

&lt;p&gt;There wasn't any interview, we didn't even saw each other. All the communication was done via text. Maybe it was sketchy but I was determined to try it.&lt;/p&gt;

&lt;p&gt;Because I was still a student, I started working remotely for 2-3 hours a day. I was helping other full time developers with small tasks. The salary was very low but for me who never had a job before and was still studying it was huge. With this money I bought myself a fancy ergonomic desk chair (I still use it!) and a graphic card to play GTA V 😄.&lt;/p&gt;

&lt;p&gt;I left the job after few months, because I was tired working and going to school at the same time, but it gave me confidence that I should follow this path. The fun fact is, during all the time I was working there, we only communicated via text (using Gadu Gadu - Polish communicator) and organized our work on Basecamp. I never saw or heard my employer or people I worked with.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I've got the job and never started working there
&lt;/h2&gt;

&lt;p&gt;In my location it was hard to find a developer job where I could use "cool" technologies and work with great teams on great products. But there were a lot of places doing WordPress.&lt;/p&gt;

&lt;p&gt;Just before I finished high school I decided it is the time I should look for a first full-time job. I applied for a position very close to me and got invited to an interview.&lt;/p&gt;

&lt;p&gt;I was never as stressed as I was before this interview. The office of this company was at the 10th floor. For some reason I didn't go to the elevator, but I took stairs instead. I had to wait few minutes before I left the staircase to catch my breath. When I came to the office and said I was here for the interview they said they don't know anything about it! It turned out that the person who replied to my email didn't informed anyone. I had the interview anyway, it was very easy and informal but I've got the job.&lt;/p&gt;

&lt;p&gt;When they asked me when can I start I said I would want to still have my holiday so I want to start in September. I knew it was a bold move but they agreed and I was supposed to contact them in two months. When I was living my future boss walked my to the elevator. &lt;/p&gt;

&lt;p&gt;I was very happy I've got the job. I knew getting the first job is very difficult. While my colleagues were worrying about the upcoming exams, I was in very comfortable position. At the same time my friend got accepted at Netguru as Junior Front-end Developer (it will become important later).&lt;/p&gt;

&lt;p&gt;September came and I made a call to the company that I want to start working with them. To my surprise they said the project I was supposed to work in was cancelled and they can't hire me. I remember I was devastated. Why they didn't inform me sooner? Maybe I shouldn't take this vacation? At the same time my colleagues were going to start their first year at the university and it was too late for me to apply. I thought to myself sarcastically: "I'm unemployed now".&lt;/p&gt;

&lt;h2&gt;
  
  
  My first full time job
&lt;/h2&gt;

&lt;p&gt;It didn't take a long time I applied for another WordPress position in my city. I remember I was sitting at in the park waiting for my girlfriend when the email came. They invited me to the interview! It was more format one, there were both technical and soft skills questions. The next day I've got invited to the office again. They offered me a job, I didn't get the salary I wanted, but they promised me to increase it after 3 month probation period. I accepted the offer and signed a contract.&lt;/p&gt;

&lt;p&gt;The first weeks were very interesting. My official title was Junior Front-end Developer, but I was the only developer in the very small team, working along with designer, copywriter and project manager.  Later I've got asked to review the code of website they presented to me. I said it looks like some inexperienced person was working on it. My boss said it was the work of other software company and he was outsourcing some projects to them 😄.&lt;/p&gt;

&lt;p&gt;I was so happy I can finally do what I love and get paid. I was fixing some past projects and as I was doing for my own projects I setup whole ecosystem in Gulp to combine single JS files into one, optimize images automatically and so on. It turned out the setup took me more time than I ever worked on this project.&lt;/p&gt;

&lt;p&gt;Before my first real project my boss asked me if I can work with WooCommerce and create an e-commerce site. I said I've never worked with it, but I can do it for sure. Later it became clear I couldn't. I didn't knew anything about WooCommerce and I was doing things my way instead of using solutions recommended by official documentation. The site went live, It was working somehow, but not everything from the CMS was working as it was supposed to. Every time client came with some small improvement I was scared the whole thing will collapse.&lt;/p&gt;

&lt;p&gt;At the same time my friend was working at Netguru. He was very happy with the job. They offered him a very good salary, possibility to work remotely, flexible working hours and a Macbook he could take home. I'm mentioning a Macbook, because in Poland Apple products are still very premium and not everyone can afford it. By the way this is not advertisement for Netguru 😄.&lt;/p&gt;

&lt;p&gt;After few months in this company it became clear to me I want to built more complicated products and have a better opportunity for a promotion.&lt;/p&gt;

&lt;p&gt;I bought a $10 Udemy course and started learning React so I could work in Netguru.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting my first job as JavaScript Developer
&lt;/h2&gt;

&lt;p&gt;Netguru was one of few places in Poland where they offered remote work for Junior Front-end Developer and were transparent about the salary. Sadly when I felt like I was ready to apply for the Junior position it was now longer available. I remember I refreshed their site almost daily to find out if they opened it again.&lt;/p&gt;

&lt;p&gt;After almost a month I could finally apply for Junior Front-end Developer. I was accepted to take part in the recruitment process and I received a task to develop a small application. After they reviewed my work I was invited to the interview with the recruiter and other Front-end Developers. With the recruiter I answered some questions about myself and how do I work with others.&lt;/p&gt;

&lt;p&gt;During the technical part I was asked few questions how I would solve some problems and we did pair programming to solve few JavaScript exercises.&lt;/p&gt;

&lt;p&gt;After few days I was invited to the last part of the process. It was the interview with the department manager. I was asked about my motivation to be a developer and what I want to learn in the future. At the end he informed me I will receive a job offer in few days.&lt;/p&gt;

&lt;p&gt;I was so happy to start this job. Finally I was working in the environment where there were people I could learn from and a project that would take more than a few weeks. I've got assigned a mentor, who by the way took part in the interview, and we closely worked together for almost 2 months. After this time I was promoted to a regular position.&lt;/p&gt;

&lt;p&gt;Only at this job I felt like I'm finally doing what I always wanted to do.&lt;/p&gt;




&lt;p&gt;I'm regularly publishing my insights on web development. &lt;br&gt;
Consider &lt;a href="https://slawkolodziej.com/newsletter"&gt;subscribing to my newsletter&lt;/a&gt;.&lt;br&gt;
Visit my blog at &lt;a href="https://slawkolodziej.com"&gt;slawkolodziej.com&lt;/a&gt; to find out more interesting content.&lt;br&gt;
Follow me on &lt;a href="https://twitter.com/slawkolodziej"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>career</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>7 Tips to Get Up to Speed Quickly in New Job or Project</title>
      <dc:creator>Sławek Kołodziej</dc:creator>
      <pubDate>Mon, 09 Nov 2020 15:19:57 +0000</pubDate>
      <link>https://forem.com/slawomirkolodziej/7-tips-to-get-up-to-speed-quickly-in-new-job-or-project-58b3</link>
      <guid>https://forem.com/slawomirkolodziej/7-tips-to-get-up-to-speed-quickly-in-new-job-or-project-58b3</guid>
      <description>&lt;p&gt;I've been working for three years in my current company and at the same time I took part in over 10 different projects for various clients. Changing projects this often taught me how to onboard quickly to new project and contribute as soon as possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Meet with your project manager / team leader
&lt;/h2&gt;

&lt;p&gt;This should be the person who knows the most about the project, especially from the business side. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ask her/him about project background - what we are developing and why&lt;/li&gt;
&lt;li&gt;ask about the last milestone they achieved&lt;/li&gt;
&lt;li&gt;ask about what they currently work on and what will you do&lt;/li&gt;
&lt;li&gt;what is the team currently struggling with - maybe you can offer your help here&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Meet with your team mates
&lt;/h2&gt;

&lt;p&gt;Project teams may have various sizes. It could be 2 developers working together or even team of 25+ people. In small teams it will be very easy to work closely together. In bigger ones, usually there will be a person or two who will coordinate the work of the team.&lt;/p&gt;

&lt;p&gt;When you meet your new team mates get to know them from personal level, but also ask what are their responsibilities in the project. It will be easier to find a person who can help you later.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Look for a mentor
&lt;/h2&gt;

&lt;p&gt;This will be the person you can ask questions directly about the projects. Usually it will be the team leader or some other experienced person in the project. Ask them to show you how they work, what is the development flow here and how is the application working.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Setup the project
&lt;/h2&gt;

&lt;p&gt;It should be your first technical task. Depending on the project it may be as trivial as running 1-2 commands or require even a few days to install and configure all dependencies. While setting up your local development look for things there are missing or outdated in project documentation and offer to fix them. The new person who will join the project will thank you for sure.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Do not worry about not delivering
&lt;/h2&gt;

&lt;p&gt;You are just beginning your work in this project. Do not expect from yourself to deliver something meaningful in the first weeks. It will take time to get to know all details of how your application works. Your team mates are months, if not years, ahead of you when it comes to project knowledge and they are able to quickly find a place in the code where this small change is needed, while you might spend several hours on the same thing. Do not worry about it, you will get there.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Start with something small
&lt;/h2&gt;

&lt;p&gt;I know you would want to put you knowledge into practice and deliver great feature in your first week, but it would likely take 2-3 more time than initial estimates of your teammates and that's ok. I would suggest to look for small tasks at first - changing a translation, improving the design, adding some field to form. You will pick up knowledge from different places of the application and you will be able to use it soon.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Look for improvements
&lt;/h2&gt;

&lt;p&gt;While working in the project look for ways to improve the project. It could be contribution to documentation or refactoring some parts of application everyone wanted but nobody did it. Looking at project with fresh eyes you may discover some improvements that were obvious, but went unnoticed by your team mates. Maybe you can introduce some interesting practice or tool you used in previous project / job?&lt;/p&gt;




&lt;p&gt;Working in a new place and new people is always stressful, especially the first days. Remember to focus on learning as much as possible and do now worry strictly about delivering features. After few weeks or months you will start feeling comfortable and work in your standard level and pace.&lt;/p&gt;




&lt;p&gt;I'm regularly publishing my insights on web development. &lt;br&gt;
Consider &lt;a href="https://slawkolodziej.com/newsletter"&gt;subscribing to my newsletter&lt;/a&gt;.&lt;br&gt;
Visit my blog at &lt;a href="https://slawkolodziej.com"&gt;slawkolodziej.com&lt;/a&gt; to find out more interesting content.&lt;br&gt;
Follow me on &lt;a href="https://twitter.com/slawkolodziej"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>career</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What Do You Need to Know as a Junior Frontend Developer + Bonus Interview Questions</title>
      <dc:creator>Sławek Kołodziej</dc:creator>
      <pubDate>Mon, 02 Nov 2020 15:29:41 +0000</pubDate>
      <link>https://forem.com/slawomirkolodziej/what-do-you-need-to-know-as-a-junior-frontend-developer-bonus-interview-questions-32ba</link>
      <guid>https://forem.com/slawomirkolodziej/what-do-you-need-to-know-as-a-junior-frontend-developer-bonus-interview-questions-32ba</guid>
      <description>&lt;p&gt;When you start learning about frontend and gain some knowledge to develop simple webpages, you might ask yourself a question: "Am I ready to get a first job?".&lt;/p&gt;

&lt;p&gt;Requirements in job descriptions often say: "knowledge of HTML, CSS and JavaScript" or "you should know React/Angular/Vue", but what does it really mean?&lt;/p&gt;

&lt;p&gt;In this post I will try explain what you really need to know to get hired as Junior Front-end Developer. It can change from job to job, but this is a nice overview of skills you need to know.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need to know about HTML as Junior Front-end Developer
&lt;/h2&gt;

&lt;p&gt;At first glance, it is the easiest part of web development, but it can cause trouble even for experienced developers. As a Junior you should know the most common HTML elements and how they effect SEO.&lt;/p&gt;

&lt;h3&gt;
  
  
  Common HTML Interview Questions
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Rewrite given sample of code using proper HTML elements.&lt;/li&gt;
&lt;li&gt;Which parts of HTML have the greatest impact on SEO.&lt;/li&gt;
&lt;li&gt;What you should include to change site thumbnail when sharing on social media.&lt;/li&gt;
&lt;li&gt;How to optimize images for the best performance and quality?&lt;/li&gt;
&lt;li&gt;What is &lt;code&gt;defer&lt;/code&gt; and &lt;code&gt;async&lt;/code&gt; attribute in &lt;code&gt;script&lt;/code&gt; element and what's the difference?&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What you need to know about CSS as Junior Front-end Developer
&lt;/h2&gt;

&lt;p&gt;As a Junior Front-end Developer you should know most of CSS properties.&lt;/p&gt;

&lt;p&gt;You should know how to build common UI elements such as a Modal or Multi-level Navigation, how to implement CSS Animations and use Flexbox and CSS Grid.&lt;/p&gt;

&lt;p&gt;Knowledge of Responsive Design and good practices of developing for smaller screens is often must have.&lt;/p&gt;

&lt;p&gt;In commercial projects you will rarely see a plain CSS files. Learn about are CSS preprocessors such as SCSS, BEM methodology and CSS-in-JS.&lt;/p&gt;

&lt;h3&gt;
  
  
  Common CSS Interview Questions
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;What is the difference between &lt;code&gt;box-sizing: content-box&lt;/code&gt; and &lt;code&gt;box-sizing: border-box&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;What are the good practices of CSS Animations? What you should avoid and why?&lt;/li&gt;
&lt;li&gt;Rewrite given sample of code in SCSS using BEM methodology.&lt;/li&gt;
&lt;li&gt;What values of &lt;code&gt;display&lt;/code&gt; property you know? What are the differences?&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What you need to know about JavaScript as Junior Front-end Developer
&lt;/h2&gt;

&lt;p&gt;During job interview you should expect questions about DOM manipulation, using the most common array methods and many others parts of JavaScript. It's hard to list all of them. In the end you should be able to understand code written in JavaScript and write simple features. I would recommend you to take a look at &lt;a href="https://www.youtube.com/watch?v=BMUiFMZr7vk"&gt;Functional Programming in Javascript Series&lt;/a&gt; from Fun Fun Function channel on Youtube and free &lt;a href="https://learn.freecodecamp.org/"&gt;JavaScript Algorithms And Data Structures&lt;/a&gt; course on freeCodeCamp. After you complete it you should be able to answer most of the questions related to JavaScript.&lt;/p&gt;

&lt;h3&gt;
  
  
  Common JavaScript Interview Questions
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;What is the difference between var, let and const?&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;filter&lt;/code&gt; array method to remove every odd number from given array.&lt;/li&gt;
&lt;li&gt;Implement &lt;code&gt;reverse&lt;/code&gt; method, which is available on every String. Ex. using &lt;code&gt;"string".reverse()&lt;/code&gt; gives &lt;code&gt;"gnirts"&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;How does &lt;code&gt;this&lt;/code&gt; behave in arrow function and regular function?&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What you should know about JavaScript Framework such as React, Angular or Vue
&lt;/h2&gt;

&lt;p&gt;Knowledge of JavaScript framework doesn't have to be required to get hired as a Junior Frontend Developer. But for some companies it is needed to start working in the project, for others you will gain extra points  during the interview.&lt;/p&gt;

&lt;p&gt;The most common way to test your framework knowledge will be a task to complete before the interview. You should know how to interact with external REST APIs, manage and send form data, implement simple UI elements such as a modal, dropdown, tabs or slider.&lt;/p&gt;

&lt;p&gt;It's good to know code testing techniques so you can at least talk about them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Common React/Angular/Vue Interview Questions
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Create application, which fetches list of movies from API, can sort them and display movie details on a separate page (task before interview)&lt;/li&gt;
&lt;li&gt;Use state management library (ex. Redux or Mobx in React) to implement counter. You should be able to increment and decrement counter using buttons.&lt;/li&gt;
&lt;li&gt;Describe how to debug web application in given framework.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Bonus: Soft skills
&lt;/h2&gt;

&lt;p&gt;It is very important to have good soft skills when applying for a job. Developing apps is almost always done as a team. During interview you should present yourself as a person which is easy to communicate and work with.&lt;/p&gt;

&lt;p&gt;Be truly interested and engaged in a conversation. Try to explain and describe your solutions. You will have much bigger chance to get hired if the interviewer will like you.&lt;/p&gt;

&lt;p&gt;Before the interview look for information about the company you are applying for and try to use it during the conversation.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the best way to show your experience
&lt;/h2&gt;

&lt;p&gt;Remember, you don't need to have commercial experience to get Junior Front-end Developer Job. Instead, you should show your skills in side projects. Look at &lt;a href="https://slawkolodziej.com/posts/5-javascript-projects-you-should-build-as-junior-frontend-developer"&gt;5 Javascript Projects You Should Build as Junior Frontend Developer&lt;/a&gt; article for ideas.&lt;/p&gt;




&lt;p&gt;I'm regularly publishing my insights on web development. &lt;br&gt;
Consider &lt;a href="https://slawkolodziej.com/newsletter"&gt;subscribing to my newsletter&lt;/a&gt;.&lt;br&gt;
Visit my blog at &lt;a href="https://slawkolodziej.com"&gt;slawkolodziej.com&lt;/a&gt; to find out more interesting content.&lt;br&gt;
Follow me on &lt;a href="https://twitter.com/slawkolodziej"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>5 Javascript Projects You Should Build as Junior Frontend Developer</title>
      <dc:creator>Sławek Kołodziej</dc:creator>
      <pubDate>Wed, 28 Oct 2020 20:01:09 +0000</pubDate>
      <link>https://forem.com/slawomirkolodziej/5-javascript-projects-you-should-build-as-junior-frontend-developer-4gm3</link>
      <guid>https://forem.com/slawomirkolodziej/5-javascript-projects-you-should-build-as-junior-frontend-developer-4gm3</guid>
      <description>&lt;p&gt;When looking for a first job as a Junior Front-end developer it's very hard to show your experience as a programmer. Your projects used as a playground for learning new skills will rarely also offer good code quality. It's impossible to write perfect code if you write something for the first time! In the end, our public code repository will consists of a bunch of unfinished projects. You wouldn't want your future employer to see all of it. &lt;/p&gt;

&lt;p&gt;This is why I encourage you to reuse your skills in practice once again. This time also taking into consideration code quality. Here is a list of project examples you could build to show off your skills.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Build a Blog Template with HTML and CSS
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7fd6fsvs0iuibo3gm4k2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7fd6fsvs0iuibo3gm4k2.png" alt="https://symu.co/freebies/templates-4/blog-psd-template/"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you just start learning front-end development it's important to consolidate your knowledge about HTML and CSS. Building a Blog Template is a good idea for your first bigger project. Do not worry about design, there are &lt;a href="https://symu.co/freebies/templates-4/blog-psd-template/" rel="noopener noreferrer"&gt;many resources available online&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Requirements:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;build a homepage, single post page, and contact page&lt;/li&gt;
&lt;li&gt;try using CSS Grid&lt;/li&gt;
&lt;li&gt;your page should be responsive (RWD)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Nice to haves:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;add a slider&lt;/li&gt;
&lt;li&gt;use real content instead of Lorem Ipsum&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Build a Tic-tac-toe game with Pure JavaScript
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F88m9yw304ec4u6c47bea.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F88m9yw304ec4u6c47bea.png" alt="https://www.google.com/search?q=tic+tac+toe"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Building a game in a browser can be a great exercise to test your JavaScript skills. You will have to react to user events, interact with DOM, and store game data. It's also a great project to show to your colleagues and family!&lt;/p&gt;

&lt;h3&gt;
  
  
  Requirements:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;welcome screen with name and symbol input for each player&lt;/li&gt;
&lt;li&gt;rendering a symbol when a user clicks on the empty cell&lt;/li&gt;
&lt;li&gt;win verification&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Nice to haves:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;creating a scoreboard and saving it to local storage&lt;/li&gt;
&lt;li&gt;playing with the computer, using ex. minmax algorithm or your own solution&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. Location sharing with Pure JavaScript and Maps Service
&lt;/h2&gt;

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

&lt;p&gt;A simple app where you can share location with your friend can be both a demanding project and a very useful tool you can use. In this project, you will use JavaScript to interact with external services for maps (ex. Google Maps or OpenStreetMap).&lt;/p&gt;

&lt;h3&gt;
  
  
  Requirements:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;displaying your current location on a map&lt;/li&gt;
&lt;li&gt;"Share" button which creates a link with your current location&lt;/li&gt;
&lt;li&gt;a page which displays a location embedded in URL&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Nice to haves:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;sharing your realtime location, you will have to save it and read it every few seconds from an external database (ex. Firebase)&lt;/li&gt;
&lt;li&gt;displaying the realtime location of your friend when he accesses the page&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. Build TV Series Tracker with JS Framework (React, Vue, Angular or other)
&lt;/h2&gt;

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

&lt;p&gt;This project will help every TV Series fan, track premieres of new episodes. It will be a great opportunity to use a JavaScript framework you are comfortable with. &lt;/p&gt;

&lt;h3&gt;
  
  
  Requirements:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;searching for TV Series using external API (ex. TVMaze API)&lt;/li&gt;
&lt;li&gt;adding TV Series to the tracking list&lt;/li&gt;
&lt;li&gt;displaying tracked TV Series list along with newest episode premiere date&lt;/li&gt;
&lt;li&gt;single page view with more details about TV Series&lt;/li&gt;
&lt;li&gt;saving tracking list to local storage&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Nice to haves:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;sending emails or push notifications when a premiere is coming&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. Home Budget App with JS Framework (React, Vue, Angular or other)
&lt;/h2&gt;

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

&lt;p&gt;Creating a home budget App will be an ultimate check for your skills as a Junior Front-end Developer. It will check your ability to create forms and store information, but it can also help you save money!&lt;/p&gt;

&lt;h3&gt;
  
  
  Requirements:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;adding a category&lt;/li&gt;
&lt;li&gt;adding expense with name, amount and category&lt;/li&gt;
&lt;li&gt;sum up of monthly spendings split into categories&lt;/li&gt;
&lt;li&gt;saving data to an external database (ex. Firebase)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Nice to haves:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;sign up, log in, and handling multiple users&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Side projects are a great way to show your skills to land first job as Junior Front-end Developer. Let your potential employer know what did you build so far. They will not only look at the webpage but also analyze your code, so make sure it's clean.&lt;/p&gt;

&lt;p&gt;Before you start building something new create a list of requirements for MVP (Minimum Valuable Product). During development, you will discover more interesting functionalities your application can have, just add it as a nice to have to the list. It will help you finish the project on schedule.&lt;/p&gt;

&lt;p&gt;Remember, you don't have to mimic those examples 1-to-1. Feel free to change, add or remove any detail you like. If you have older projects you used for learning new skills you can always refactor it and put it in a portfolio.&lt;/p&gt;




&lt;p&gt;I'm regularly publishing my insights on web development. &lt;br&gt;
Consider &lt;a href="https://slawkolodziej.com/newsletter" rel="noopener noreferrer"&gt;subscribing to my newsletter&lt;/a&gt;.&lt;br&gt;
Visit my blog at &lt;a href="https://slawkolodziej.com" rel="noopener noreferrer"&gt;slawkolodziej.com&lt;/a&gt; to find out more interesting content.&lt;br&gt;
Follow me on &lt;a href="https://twitter.com/slawkolodziej" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Guide: Testing Redux Connected Components with React Testing Library and Jest</title>
      <dc:creator>Sławek Kołodziej</dc:creator>
      <pubDate>Wed, 21 Oct 2020 18:38:30 +0000</pubDate>
      <link>https://forem.com/slawomirkolodziej/guide-testing-redux-connected-components-with-react-testing-library-and-jest-43j7</link>
      <guid>https://forem.com/slawomirkolodziej/guide-testing-redux-connected-components-with-react-testing-library-and-jest-43j7</guid>
      <description>&lt;p&gt;In my experience unit testing React components was always pretty simple until you needed to integrate with an external library like Redux. There are countless "solutions" available online, but I wanted to present you with my simple, yet powerful solution. I used it in a few commercial projects with great results. &lt;/p&gt;

&lt;p&gt;It couldn't be easier without React Testing Library, which revolutionized testing components in React. &lt;/p&gt;

&lt;h2&gt;
  
  
  A common mistake with testing Redux connected components
&lt;/h2&gt;

&lt;p&gt;One solution which was, for some reason, quite popular was testing components connected to Redux without the real connection. Here is an example of what I mean by that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;connect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-redux&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mapStateToProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;someData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;MyComponentUnwrapped&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mapStateToProps&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then in tests, you would import &lt;code&gt;MyComponentUnwrapped&lt;/code&gt; instead of your default export used everywhere else in the app.&lt;/p&gt;

&lt;p&gt;In this case, you are not testing an important part of your component. Other than that &lt;code&gt;MyComponentUnwrapped&lt;/code&gt; is used only by your tests, your real application uses the default export. You can get your tests passing where in reality the same cases could fail.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to test components in React Testing Library
&lt;/h2&gt;

&lt;p&gt;React Testing Library provides a very intuitive API. Its main goal is to test components the same way user will use them in your application. Of course, the same is possible with other testing libraries like Enzyme, but React Testing Library is very strict about it and doesn't allow to access the internals of your component.&lt;/p&gt;

&lt;p&gt;Enough with theory. Let's write some tests!&lt;/p&gt;

&lt;p&gt;Let's say we have some components, which fetch user data and display it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getUserData&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./api&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;userData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setUserData&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;getUserData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;setUserData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;userData&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;userData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Quite simple component, Now let's see how it can be tested&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;screen&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@testing-library/react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./User&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;jest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./api&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;getUserData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mock name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;}));&lt;/span&gt;

&lt;span class="nx"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;User&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;should display user name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;);&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;screen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findByText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mock name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userName&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toBeTruthy&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first thing we have to do is mock our API call with &lt;code&gt;jest.mock&lt;/code&gt;. Normally it would make a network request, but in tests, we need to mock it.&lt;/p&gt;

&lt;p&gt;Then we use &lt;code&gt;render&lt;/code&gt; function to render our component, and &lt;code&gt;screen.findByText&lt;/code&gt; to search for text in the component we just rendered.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing Redux connected components
&lt;/h2&gt;

&lt;p&gt;Now let's suppose we would need to access user data in other parts of the application. Let's move it to the Redux store. Here is how the refactored version of the component might look like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;connect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-redux&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;fetchUserData&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./actions&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;userData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;fetchUserData&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;fetchUserData&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;userData&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;userData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mapStateToProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;userData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mapDispatchToProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;fetchUserData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mapStateToProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mapDispatchToProps&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the first thing you will notice in your test is: &lt;code&gt;Could not find "store" in the context of "Connect(User)"&lt;/code&gt; error. It's because your component needs to be wrapper in &lt;code&gt;Provider&lt;/code&gt; to access Redux Store. Let's fix our tests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;screen&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@testing-library/react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createStore&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;redux&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./User&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;reducer&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./reducer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./store&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;jest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./api&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;getUserData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mock name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;}));&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mock name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Wrapper&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt; &lt;span class="na"&gt;store&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;User&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;should display user name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Wrapper&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;screen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;findByText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mock name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userName&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toBeTruthy&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We fixed the error by creating a Wrapper. This component will wrap the component we test with Provider and apply a mocked state. We can go one step further by custom render function using the one from React Testing Library.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;rtlRender&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@testing-library/react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createStore&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;redux&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Provider&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-redux&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;reducer&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./reducer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;renderWithState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;ui&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;renderOptions&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Wrapper&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt; &lt;span class="na"&gt;store&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ui&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Wrapper&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;renderOptions&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then in our case we can just import it and use like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;renderWithState&lt;/span&gt;&lt;span class="p"&gt;(&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Testing components with Redux hooks
&lt;/h2&gt;

&lt;p&gt;The approach presented above is also compatible when using React Redux hooks and selectors, as long as they use the data we provide them in the state.&lt;/p&gt;

&lt;p&gt;This is the true advantage of the React Testing Library. No matter what you use for connecting your component to Redux. It only tests what your component renders, without diving deep into implementation details.&lt;/p&gt;




&lt;p&gt;I'm regularly publishing my insights on web development. &lt;br&gt;
Consider &lt;a href="https://slawkolodziej.com/newsletter"&gt;subscribing to my newsletter&lt;/a&gt;.&lt;br&gt;
Visit my blog at &lt;a href="https://slawkolodziej.com"&gt;slawkolodziej.com&lt;/a&gt; to find out more interesting content.&lt;br&gt;
Follow me on &lt;a href="https://twitter.com/slawkolodziej"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>redux</category>
      <category>testing</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Sync your icons with Figma API</title>
      <dc:creator>Sławek Kołodziej</dc:creator>
      <pubDate>Thu, 09 Jul 2020 19:20:57 +0000</pubDate>
      <link>https://forem.com/slawomirkolodziej/sync-your-icons-with-figma-api-1m64</link>
      <guid>https://forem.com/slawomirkolodziej/sync-your-icons-with-figma-api-1m64</guid>
      <description>&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;Adding or editing assets often requires two people to make the change: designer and developer. They have to sync after every update, which is often quick but interrupts other work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;Figma API makes it possible to extract almost any data from design files into your project. &lt;/p&gt;

&lt;p&gt;One obvious integration many projects can benefit from is syncing your svg files with Figma. I will use figma-api-exporter, it is still an early version, but it was already tested in production. Feel free to contribute.&lt;/p&gt;

&lt;h3&gt;
  
  
  Requirements
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Figma Access Token - follow the &lt;a href="https://www.figma.com/developers/api#access-tokens"&gt;instruction&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Figma File with icons changed to components&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;figma-api-exporter&lt;/code&gt; installed in your project&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Downloading icons as svgs
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;figmaApiExporter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;figma-api-exporter&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;exporter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;figmaApiExporter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;YOUR_ACCESS_TOKEN&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;exporter&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getSvgs&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;fileId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;FIGMA_FILE_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Icons&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;svgsData&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;exporter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;downloadSvgs&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;saveDirectory&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./figmaIcons&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;svgsData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;svgsData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;svgs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;lastModified&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;svgsData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lastModified&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;clearDirectory&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save it as &lt;code&gt;YOUR_NAME.js&lt;/code&gt; file and run with node &lt;code&gt;YOUR_NAME.js&lt;/code&gt;. You should see files appearing in figmaIcons directory.&lt;/p&gt;

&lt;h3&gt;
  
  
  Displaying all available icons (ex. in Storybook)
&lt;/h3&gt;

&lt;p&gt;By default there is no easy way to import all files from directory. However, you can use &lt;a href="https://github.com/gajus/create-index"&gt;create-index&lt;/a&gt; to generate &lt;code&gt;index.js&lt;/code&gt; file with files exported as modules after every sync.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;writeIndex&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;create-index&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;path&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="p"&gt;...&lt;/span&gt;

  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;exporter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;downloadSvgs&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;
  &lt;span class="nx"&gt;writeIndex&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./figmaIcons&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)],&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;update&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;extensions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;svg&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;index.js&lt;/code&gt; will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;Icon1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./Icon1.svg&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;Icon2&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./Icon2.svg&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;Icon3&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./Icon3.svg&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then in Storybook you can import all svg files and iterate over them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;allSvgIcons&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./figmaIcons&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Making it work in production
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Option 1: Plug it into CI
&lt;/h4&gt;

&lt;p&gt;Make your script run on every deployment. Every deployment will update the icons to the latest version. The downside is an increased build time.&lt;/p&gt;

&lt;h4&gt;
  
  
  Option 2: Sync and push
&lt;/h4&gt;

&lt;p&gt;If you are concerned about your deployment time you can run script locally and push new/updated files to repository. It is a less preferred option, as its removes most of the automation. You have to still perform some action after designer updated the icons.&lt;/p&gt;




&lt;p&gt;I'm regularly publishing my insights on web development. &lt;br&gt;
Consider &lt;a href="https://slawkolodziej.com/newsletter"&gt;subscribing to my newsletter&lt;/a&gt;.&lt;br&gt;
Visit my blog at &lt;a href="https://slawkolodziej.com"&gt;slawkolodziej.com&lt;/a&gt; to find out more interesting content.&lt;br&gt;
Follow me on &lt;a href="https://twitter.com/slawkolodziej"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>design</category>
      <category>node</category>
    </item>
    <item>
      <title>Guide: Unit Testing React Apollo Components with React Testing Library</title>
      <dc:creator>Sławek Kołodziej</dc:creator>
      <pubDate>Sat, 28 Dec 2019 22:33:08 +0000</pubDate>
      <link>https://forem.com/slawomirkolodziej/how-to-test-components-using-apollo-with-react-testing-library-om7</link>
      <guid>https://forem.com/slawomirkolodziej/how-to-test-components-using-apollo-with-react-testing-library-om7</guid>
      <description>&lt;p&gt;In this post I will present you a quick guide how to test React components which use Apollo.&lt;/p&gt;

&lt;p&gt;At first let's see how our component looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;graphql-tag&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useQuery&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@apollo/react-hooks&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;POSTS_QUERY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt;&lt;span class="s2"&gt;`
  query Post($id: String!) {
    {
      post(id: $id) {
        title
        author
        description
      }
    }
  }
`&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;postId&lt;/span&gt; &lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;POSTS_QUERY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;variables&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;postId&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`Error: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h3&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;testId&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;post-title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h3&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h4&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;testId&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;post-author&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h4&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;testId&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;post-description&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;I always had issues with testing components which do not render desired value immediately. In our case Post component at first won't render anything, because it is in &lt;code&gt;loading&lt;/code&gt; state.&lt;/p&gt;

&lt;p&gt;Fortunately &lt;code&gt;react-testing-library&lt;/code&gt; solves this problem for us. It allows us to wait for some element to be rendered.&lt;/p&gt;

&lt;p&gt;On the other hand, Apollo has very useful &lt;code&gt;MockedProvider&lt;/code&gt; component. Thanks to this component you can mock result of your queries. Let's take a look at the code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;cleanup&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;findByTestId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;findByText&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@testing-library/react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;MockedProvider&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@apollo/react-testing&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;POSTS_QUERY&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./Post&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mocks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;POSTS_QUERY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;variables&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;postId&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;result&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;post&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;author&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;description&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="nx"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Post&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;afterEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cleanup&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;should render post title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MockedProvider&lt;/span&gt; &lt;span class="nx"&gt;mocks&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;mocks&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;addTypename&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Post&lt;/span&gt; &lt;span class="nx"&gt;postId&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;postId&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/MockedProvider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;titleElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;findByTestId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;post-title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;titleContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;findByText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;titleElement&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;titleElement&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toBeTruthy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;titleContent&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toBeTruthy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;

  &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;tests&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nx"&gt;author&lt;/span&gt; &lt;span class="nx"&gt;and&lt;/span&gt; &lt;span class="nx"&gt;description&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first we create mocked query response for &lt;code&gt;POSTS_QUERY&lt;/code&gt;. We pass the &lt;code&gt;mocks&lt;/code&gt; variable to &lt;code&gt;MockedProvider&lt;/code&gt; when rendering our component.&lt;/p&gt;

&lt;p&gt;To get title element we use &lt;code&gt;findByTestId&lt;/code&gt; function. When you go back to component code you can see we added &lt;code&gt;data-testId&lt;/code&gt; to &lt;code&gt;h3&lt;/code&gt; element.&lt;br&gt;
When we finally find this element we check whether it has expected text using &lt;code&gt;findByText&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Additional resources
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.apollographql.com/docs/react/development-testing/testing/"&gt;Apollo Docs - Testing React components&lt;/a&gt;&lt;br&gt;
&lt;a href="https://testing-library.com/docs/react-testing-library/intro"&gt;React Testing Library Docs&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;I'm regularly publishing my insights on web development. &lt;br&gt;
Consider &lt;a href="https://slawkolodziej.com/newsletter"&gt;subscribing to my newsletter&lt;/a&gt;.&lt;br&gt;
Visit my blog at &lt;a href="https://slawkolodziej.com"&gt;slawkolodziej.com&lt;/a&gt; to find out more interesting content.&lt;br&gt;
Follow me on &lt;a href="https://twitter.com/slawkolodziej"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>graphql</category>
      <category>testing</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
