<?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: Leonardo Maldonado</title>
    <description>The latest articles on Forem by Leonardo Maldonado (@leonardomso).</description>
    <link>https://forem.com/leonardomso</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%2F46852%2F556abe6d-56a2-4910-8bbf-a4d0ca843189.jpeg</url>
      <title>Forem: Leonardo Maldonado</title>
      <link>https://forem.com/leonardomso</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/leonardomso"/>
    <language>en</language>
    <item>
      <title>Introducing Roover – a lightweight audio library for React</title>
      <dc:creator>Leonardo Maldonado</dc:creator>
      <pubDate>Thu, 10 Jun 2021 13:12:02 +0000</pubDate>
      <link>https://forem.com/leonardomso/introducing-roover-a-lightweight-audio-library-for-react-1lh0</link>
      <guid>https://forem.com/leonardomso/introducing-roover-a-lightweight-audio-library-for-react-1lh0</guid>
      <description>&lt;p&gt;Modern applications are using audio all the time. Audio can turn a boring application into an interesting one, adding emotion to the content. Most of the modern applications that we use daily are using audio for at least in some part.&lt;/p&gt;

&lt;p&gt;Work with audio in React applications is painful. There are not too many good libraries to manage audio and most of the time we need to create our solutions. Manage audio in a modern application is important and should be made by using the best tools and libraries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introducing Roover
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/leonardomso/roover" rel="noopener noreferrer"&gt;Roover&lt;/a&gt; is a powerful and lightweight library for working with audio in React apps. It is a simple custom React hook that can be used anywhere in your application.&lt;/p&gt;

&lt;p&gt;It is very easy to get started with Roover. Inside your React project, just run the command to install it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add roover
```



Now, just import the `useRoover` hook and start to use it:



```
import React from 'react';
import useRoover from 'roover';

const src =
  'https://storage.googleapis.com/media-session/elephants-dream/the-wires.mp3';

const App = () =&amp;gt; {
  const {
    initial,
    loading,
    ready,
    playing,
    paused,
    onPlay,
    onPause,
  } = useRover({
    src,
    autoplay: true,
  });

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;Loading: {loading ? 'true' : 'false'}&amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;Ready: {ready ? 'true' : 'false'}&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={onPlay}&amp;gt;Play&amp;lt;/button&amp;gt;
      &amp;lt;button onClick={onPause}&amp;gt;Pause&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};
```



The library is fully open-source on [GitHub](https://github.com/leonardomso/roover) and we have a very clear documentation page where you can check it out and the use-cases and how to use the library properly.

Your contributions are welcome! If you have any questions or want to start to contribute to this library in any form, please open an issue. Feel free to open PR.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>A letter for those who want to learn JavaScript</title>
      <dc:creator>Leonardo Maldonado</dc:creator>
      <pubDate>Wed, 27 Jan 2021 17:59:04 +0000</pubDate>
      <link>https://forem.com/leonardomso/a-letter-for-those-who-want-to-learn-javascript-5ad0</link>
      <guid>https://forem.com/leonardomso/a-letter-for-those-who-want-to-learn-javascript-5ad0</guid>
      <description>&lt;p&gt;Yesterday I received an email from a young developer who told me that was having difficulties learning JavaScript. He told me that he looked at some of my open source projects and found them pretty interesting and was asking for some advice about how he could learn JavaScript.&lt;/p&gt;

&lt;p&gt;I'm not the best JavaScript developer in the world, in fact I am really distant from where I want to be in a few years from now, but I decided to help him.&lt;/p&gt;

&lt;p&gt;I started to write the email to him right away and after almost 1 hour writing, I wrote this mini-blog post that you guys will read. I decided to post here because I think it might have helped other developers as well how are starting to learn JavaScript.&lt;/p&gt;

&lt;p&gt;Hope it might be useful for those who are starting to learn JavaScript. Feel free to share in case you guys like it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hi Developer,&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I appreciate that you liked my open source contributions. I think I can help you with a few tips that helped me to get started with JavaScript:&lt;/p&gt;

&lt;p&gt;JavaScript is the best programming language to get started right now if you don't have any programming background and want to learn it. The JavaScript ecosystem has matured over the years and new libraries are created every day, to solve an enormous range of different problems. &lt;/p&gt;

&lt;p&gt;I think this piece of advice can help not only you but many others who are starting to learn JavaScript. &lt;/p&gt;

&lt;p&gt;Here are a few things that I learned throughout the years and I think can help you: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learn the basics.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You need to start learning JavaScript by the basics, after that you can start to learn and build more complex things. Your goal here is to learn JavaScript, so start to search for content for JavaScript beginners, find what works for you. Take a few courses. Read articles. Watch talk videos. Listen to podcasts. There are a lot of different ways that you can learn it, you need to find the way that works for you. Don't compare yourself with developers that are in the field for a long time, you will get frustrated. Compare yourself to who you were yesterday as a developer, try to learn new things every day. A few years from now you will see how long you have improved and mastered JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learn in public.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;This is the fastest way to learn, you will not only learn but also build a network while helping others as well. You might have been experiencing a problem that another person might have been experiencing as well, you might provide value to them showing how you solved or how to solve it. Start to write articles, you can write about the most basic JavaScript concept, you will not only help others but learn in the process, that's a powerful way to learn in my opinion.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Build different projects.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I could easily say here to you, after have you learned JavaScript, to start to learn React. That would be unfair. You want to learn JavaScript but don't know exactly which way as a developer you're going to follow it, there are a lot of different ways that you could go from here. That's why you need to build a lot of different projects and work with a range of different JavaScript technologies. Build a REST API, learn how APIs work, and how to build using different approaches. Create a simple calculator using different projects such as React and Vue, learn what problems each one of them solves. Learn and work with different types of databases, know the difference between SQL and NoSQL databases. Build different things. You'll find yourself along the way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Contribute to projects that you like.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open source is the most powerful thing for a developer. You will work with different people from across the globe, create a network, solve people's problems, will help developers who want to start to contribute to that project, etc. Contribute to different projects that you like or that you use daily. You don't need to create the most complex thing for that project, you can easily start with a simple documentation suggestion. Try to mess a little bit with the code, read how the code works and how the project works under the hood. Open source contribution brings value not only for you who are contributing to the project but for people and companies who will use your code in the future to scale applications for millions of users.&lt;/p&gt;

&lt;p&gt;These are the pieces of advice that I can give to you. You need to keep grinding and learning new things every day. JavaScript, like any other programming language, can be very hard for those who are not determined to learn it the right way.&lt;/p&gt;

&lt;p&gt;Wish you success and hope you can learn JavaScript and become and fantastic developer.&lt;/p&gt;

&lt;p&gt;Cheers,&lt;/p&gt;

&lt;p&gt;Leonardo&lt;/p&gt;

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

&lt;p&gt;Hope you enjoyed this content, follow me on &lt;a href="https://twitter.com/leonardomso" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; and tell me which piece of advice to you have for JavaScript beginners. You will help me a lot by liking and sharing this post with your friends, it will encourage me to make more content like this one 🙏&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Why GraphQL is the future of APIs</title>
      <dc:creator>Leonardo Maldonado</dc:creator>
      <pubDate>Mon, 08 Apr 2019 19:47:42 +0000</pubDate>
      <link>https://forem.com/leonardomso/why-graphql-is-the-future-of-apis-3632</link>
      <guid>https://forem.com/leonardomso/why-graphql-is-the-future-of-apis-3632</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff5pczb1qgyfb8vakqevk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff5pczb1qgyfb8vakqevk.png" width="800" height="333"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since the beginning of the web, developing APIs has been a difficult task for developers. The way we develop our APIs must evolve with time so that we can always build good, intuitive and well-designed APIs.&lt;/p&gt;

&lt;p&gt;In the last few years, GraphQL has been growing in popularity among developers, and a lot of companies have started adopting this technology to build their APIs. GraphQL is a query language developed by Facebook in 2012 and released publicly in 2015. It has been gaining a lot of traction and been adopted by a lot of big companies such as Spotify, Facebook, GitHub, NYTimes, Netflix, Walmart, and so on.&lt;/p&gt;

&lt;p&gt;In this series of tutorials, we're going to examine GraphQL, understand what it is, and see what features make this query language so intuitive and easy to use.&lt;/p&gt;

&lt;p&gt;So, let's get started by examining the problems with REST, and how GraphQL solves them. We will also find out why companies have been building their APIs with GraphQL, and why it is the future of APIs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Oh, REST
&lt;/h2&gt;

&lt;p&gt;A long time ago, when we changed our API design from SOAP to REST, we thought that move would give developers more flexibility in their work. We can't deny that it worked pretty well for some time and was a good move at the time. As the applications and the web have been getting more and more sophisticated, the APIs naturally evolved as well, following these changes.&lt;/p&gt;

&lt;p&gt;However, REST does have a lot of problems. Let's see what they are:&lt;/p&gt;

&lt;h3&gt;
  
  
  A lot of endpoints
&lt;/h3&gt;

&lt;p&gt;Each resource in REST is represented by an endpoint. So, in a real-world application we would end up having a lot of endpoints for a lot of resources. If you want to make a GET request, you would need an endpoint specific to that request, with specific parameters. If you want to make a POST request, you would need another endpoint just for that request.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1549963076038%2Fcghk9o5H7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1549963076038%2Fcghk9o5H7.png" title="A lot of endpoints" alt="A lot of endpoints" width="700" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But, what's the problem with that? Let's imagine we are building a huge social media application like Facebook. We will end up with a lot of endpoints which means more developer time is going to be spent developing and maintaining these APIs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Over-fetching and under-fetching of information
&lt;/h3&gt;

&lt;p&gt;A real problem that annoys a lot of developers is over-fetching and under-fetching information through REST APIs. This is because REST APIs always return a fixed structure. We can't get exactly the data that we want unless we create a specific endpoint for that.&lt;/p&gt;

&lt;p&gt;So, if we need only a tiny piece of data, we have to work with the whole object. For example, if we only need to get the &lt;code&gt;firstName&lt;/code&gt;, &lt;code&gt;lastName&lt;/code&gt;, and &lt;code&gt;age&lt;/code&gt; of a user in a REST API, there's no way we can get exactly this data without fetching the whole object.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1549963150358%2Fbj9bWqOHY.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1549963150358%2Fbj9bWqOHY.png" title="fetching data" alt="fetching data" width="700" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There's also a problem with under-fetching of information. If we want to get data from two different resources, we need to make different calls to two different endpoints. In a huge application, this doesn't scale so well since there will be cases where we only need to get a specific piece of data, not the entire object. Now, imagine we're building an application that's going to have 100 endpoints. Imagine the amount of work and code that we need to write. This will become more difficult with time. The code also gets hard to maintain and developers feel lost in the process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Versioning
&lt;/h3&gt;

&lt;p&gt;One of the painful points in REST, in my opinion, is versioning. With REST APIs, it is very common to see a lot of APIs with v1 or v2, but in GraphQL there's no need for it since you can evolve your APIs by adding new types or removing old ones.&lt;/p&gt;

&lt;p&gt;In GraphQL, all you need to do to evolve your API is to write new code. You can write new types, queries, and mutations without the need to ship another version of your API.&lt;/p&gt;

&lt;p&gt;So, you won't see GraphQL APIs with endpoints like the following:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&lt;a href="https://example.com/api/v1/users/12312" rel="noopener noreferrer"&gt;https://example.com/api/v1/users/12312&lt;/a&gt;&lt;br&gt;
&lt;a href="https://example.com/api/v2/users/12312" rel="noopener noreferrer"&gt;https://example.com/api/v2/users/12312&lt;/a&gt;&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Why GraphQL is the future&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;Back in 2012, Facebook faced a problem while they were developing their mobile applications which led them to create GraphQL. Those problems are very common, especially when we're talking about RESTful API design. As discussed these problems are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Poor performance&lt;/li&gt;
&lt;li&gt;A lot of endpoints&lt;/li&gt;
&lt;li&gt;Over-fetching or under-fetching of data&lt;/li&gt;
&lt;li&gt;Shipping another version every time we need to include or remove something&lt;/li&gt;
&lt;li&gt;Difficulty understanding APIs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With a lot of concepts in mind, developers from Facebook developed a better way to design APIs, and later named it GraphQL. Basically, it's the replacement for REST, with a lot of improvements.&lt;/p&gt;

&lt;p&gt;With GraphQL, we get a lot of new features that give you superpowers when you are building your APIs. Let's examine them one by one:&lt;/p&gt;

&lt;h3&gt;
  
  
  Single endpoint
&lt;/h3&gt;

&lt;p&gt;There's no need to build a lot of endpoints! With GraphQL, we only get one endpoint, and with that we can get as much data as we want in a single request. Basically, GraphQL wraps all of your queries, mutations, and subscriptions in one endpoint and makes it available to you. It improves your development cycle because you don't need to make two requests to get data from two different resources. Also, imagine that we're building a huge application, we won't get a lot of endpoints and a ton of code as with REST. We will get a single endpoint, and with that endpoint we can make as many requests as we want.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1549963408236%2F3KO-VaJDU.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1549963408236%2F3KO-VaJDU.png" title="GraphQL endpoint" alt="Graphql endpoint" width="700" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, as I said above, an "endpoint-only" approach makes your API self-documented since there's no need for you to build documentation because your developers already know how to use it. They can understand the API just by looking at the code, or by looking at the playground. We're going to learn more about it later on (next tutorial in this series). Seems magical, but it is just GraphQL!&lt;/p&gt;

&lt;h3&gt;
  
  
  With GraphQL you fetch only the data you need
&lt;/h3&gt;

&lt;p&gt;No more over-fetching or under-fetching of information. You fetch only the data that you need. Remember the poor performance issues that we discussed initially? We don't have that anymore since GraphQL improves the performance of your API, especially in case of slow network connection.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1549963485585%2F42Iy7rbzw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1549963485585%2F42Iy7rbzw.png" title="Fetching with GraphQL" alt="Fetching with GraphQL" width="700" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  GraphQL makes it easy to start building APIs and be consistent
&lt;/h3&gt;

&lt;p&gt;A lot of people think that GraphQL is pretty complicated because it involves a schema and a single endpoint. Once you start developing APIs with it, you discover that it's easier than you thought. An "endpoint-only" API helps a lot when you're developing your website/app. It makes your API more self-documented and there's no need for you to write a lot of documentation about it.&lt;/p&gt;

&lt;p&gt;If you don't use JavaScript as your main language, that's not a problem since GraphQL is an agnostic query language which means you can use it with any language. At the time of writing this tutorial, GraphQL has support for more than 12 languages.&lt;/p&gt;

&lt;h2&gt;
  
  
  GraphQL Is The Future
&lt;/h2&gt;

&lt;p&gt;The fact that GraphQL is an open source query language means that the community can contribute to it and make improvements to it. When Facebook released it to the community, it gained a lot of traction and approval from developers. Now, GraphQL has been growing rapidly as more and more developers are starting to build APIs with it. However, some people have been asking if this is really going to replace REST or become the new way to build APIs for real-world applications.&lt;/p&gt;

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

&lt;p&gt;At first, I thought that GraphQL was only hype and just another way to create APIs. However, when I started to study it, I found out that GraphQL has the essential features that are required to create modern APIs for modern applications because it really plays well with modern stacks.&lt;/p&gt;

&lt;p&gt;So if I could say something to you now is: yes, &lt;strong&gt;GraphQL is really the future of APIs&lt;/strong&gt;. That's why big companies are betting on it.&lt;/p&gt;

&lt;p&gt;In November 2018, GraphQL created a GraphQL Foundation, in partnership with the Linux Foundation, which means that this query language is encouraging its developers to build more documentation, tools, and support for the language. This foundation will ensure a stable, neutral, and sustainable future for GraphQL. So, this is another reason to consider GraphQL to be the future of APIs.&lt;/p&gt;

&lt;p&gt;Of course, it won't replace REST immediately because many apps still use it and it's impossible to rewrite them overnight. As more and more companies adopt GraphQL, both UX and DX will improve.&lt;/p&gt;

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

&lt;p&gt;GraphQL is really the future of APIs and we need to learn more about it. That's why I decided to create a series of 4 tutorials that will show how we can work with the best of GraphQL, starting from Queries and Mutations, then Subscriptions, and Authentication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This article was originally posted at Hashnode. If you enjoy this article read it there too so you can support me and help me to write more articles! &lt;a href="https://hashnode.com/post/why-graphql-is-the-future-of-apis-cjs1r2hhe000rn9s23v9bydoq" rel="noopener noreferrer"&gt;You can read it here!&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>graphql</category>
      <category>api</category>
    </item>
    <item>
      <title>Forms with Formik + TypeScript</title>
      <dc:creator>Leonardo Maldonado</dc:creator>
      <pubDate>Tue, 02 Apr 2019 14:25:25 +0000</pubDate>
      <link>https://forem.com/leonardomso/forms-with-formik-typescript-20p9</link>
      <guid>https://forem.com/leonardomso/forms-with-formik-typescript-20p9</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fouk5e0r4pmc0eqm3a54z.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fouk5e0r4pmc0eqm3a54z.jpeg" width="800" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One of the most painful topics for React developers always was how to build nice forms and have a nice clean code. Some people might think that it’s not necessary to use a third-party library, but in some cases, that’s needed especially when we need more complex forms. First, we started with Redux Form, a lot of people used it for a long time but then we started to ask ourselves if it’s a good idea and the best way to manage our form state using our Redux store. We don’t need to have our form state in our Redux store, it’s such a not good practice at all.&lt;/p&gt;

&lt;p&gt;Then, Formik really came to change it for us and let our forms so easy to build and our code so readable and well-written that now we don’t have to worry too much about it. We know that Formik code is written in TypeScript but a lot of people still don’t know how to use it the right way.&lt;/p&gt;

&lt;p&gt;So, in this article, we’re going to learn about how to use Formik with TypeScript, since a lot of developers has been startedto use it lately, let’s jump into this hype and see how we can improve more our forms.&lt;/p&gt;

&lt;h3&gt;
  
  
  Starting
&lt;/h3&gt;

&lt;p&gt;First, let’s start installing some dependencies:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add formik yup @types/yup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, we’re going to start to build our form importing some things that we’re going to need: we’re going to import the &lt;code&gt;withFormik&lt;/code&gt; HOC that passes our props and form handlers, and also import the &lt;code&gt;FormikProps&lt;/code&gt;. We’re going also import yup to validate our fields.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { withFormik, FormikProps } from "formik";
import * as Yup from "yup";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, to start to build our forms, we need first define some interfaces. Let’s defined an interface called &lt;code&gt;FormValues&lt;/code&gt; that’s going to define all the values&lt;br&gt;
that we’re going to have in our form:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface FormValues {
    email: string;
    password: string;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We’ll also define other interface called &lt;code&gt;OtherProps&lt;/code&gt;, that in case we want to&lt;br&gt;
pass other props to our component. In our case, we’re going to pass a property&lt;br&gt;
called &lt;code&gt;title&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface OtherProps {
    title?: string;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Our last interfaces it’s going to be called &lt;code&gt;MyFormProps&lt;/code&gt;, and with that interface, we can define some properties for our initial values, in case we want&lt;br&gt;
to have some initial values.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface MyFormProps {
    initialEmail?: string;
    initialPassword?: string;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, we’re going to write our component called &lt;code&gt;InnerForm&lt;/code&gt;, pass the interfaces&lt;br&gt;
that we created, and also put some extra code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const InnerForm = (props: OtherProps &amp;amp; FormikProps&amp;lt;FormValues&amp;gt;) =&amp;gt; {
const {
    values,
    errors,
    touched,
    handleChange,
    handleBlur,
    handleSubmit,
    isSubmitting,
    title
} = props;

return (
    &amp;lt;Wrapper&amp;gt;
        &amp;lt;h1&amp;gt;{title}&amp;lt;/h1&amp;gt;
        &amp;lt;form onSubmit={handleSubmit}&amp;gt;
            &amp;lt;InputWrapper&amp;gt;
                &amp;lt;Label&amp;gt;Email&amp;lt;/Label&amp;gt;
                &amp;lt;Input
                    width={50}
                    type="email"
                    name="email"
                    onChange={handleChange}
                    onBlur={handleBlur}
                    value={values.email}
                /&amp;gt;
            &amp;lt;/InputWrapper&amp;gt;

            &amp;lt;InputWrapper&amp;gt;
                &amp;lt;Label&amp;gt;Password&amp;lt;/Label&amp;gt;
                &amp;lt;Input
                    width={50}
                    type="password"
                    name="password"
                    onChange={handleChange}
                    onBlur={handleBlur}
                    value={values.password}
                /&amp;gt;
            &amp;lt;/InputWrapper&amp;gt;

            &amp;lt;button
                type="submit"
                disabled={
                    isSubmitting ||
                    !!(errors.email &amp;amp;&amp;amp; touched.email) ||
                    !!(errors.password &amp;amp;&amp;amp; touched.password)
                }
            &amp;gt;
                Sign In
            &amp;lt;/button&amp;gt;
        &amp;lt;/form&amp;gt;
    &amp;lt;/Wrapper&amp;gt;
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;};&lt;/p&gt;

&lt;p&gt;We passed our props with &lt;code&gt;OtherProps&lt;/code&gt; and we also wrapped our &lt;code&gt;FormValues&lt;/code&gt; inside the &lt;code&gt;FormikProps&lt;/code&gt;. The rest of the code it’s pretty self-explained, now we’re going to create our final component wrapped with the &lt;code&gt;withFormik&lt;/code&gt; HOC.&lt;/p&gt;

&lt;p&gt;First, let’s write our component called &lt;code&gt;App&lt;/code&gt; and pass the &lt;code&gt;MyFormProps&lt;/code&gt; and &lt;code&gt;FormValues&lt;/code&gt; inside the withFormik.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const App = withFormik&amp;lt;MyFormProps, FormValues&amp;gt;({
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;...&lt;/p&gt;

&lt;p&gt;Now, inside our wrapped component, inside our &lt;code&gt;mapPropsToValues&lt;/code&gt; method, if we&lt;br&gt;
want to pass an initial value to one of our fields, we can, or we can just pass&lt;br&gt;
an empty string.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mapPropsToValues: props =&amp;gt; ({
    email: props.initialEmail || "",
    password: props.initialPassword || ""
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}),&lt;/p&gt;

&lt;p&gt;We’re going to use yup to validate our fields so after the &lt;code&gt;mapPropsToValues&lt;/code&gt;&lt;br&gt;
method, let’s put the following code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;validationSchema: Yup.object().shape({
    email: Yup.string()
        .email("Email not valid")
        .required("Email is required"),
    password: Yup.string().required("Password is required")
}),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, let’s write the &lt;code&gt;handleSubmit&lt;/code&gt; function and also pass the &lt;code&gt;FormValues&lt;/code&gt; to&lt;br&gt;
validate our props.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;handleSubmit({ email, password }: FormValues, { props, setSubmitting, setErrors }) {
    console.log(email, password);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Pretty simple, now our whole &lt;code&gt;App&lt;/code&gt; component should look like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const App = withFormik&amp;lt;MyFormProps, FormValues&amp;gt;({
    mapPropsToValues: props =&amp;gt; ({
        email: props.initialEmail || "",
        password: props.initialPassword || ""
    }),

    validationSchema: Yup.object().shape({
        email: Yup.string()
        .email("Email not valid")
        .required("Email is required"),
        password: Yup.string().required("Password is required")
    }),

    handleSubmit(
        { email, password }: FormValues,
        { props, setSubmitting, setErrors }
    ) {
        console.log(email, password);
    }
})(InnerForm);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://codesandbox.io/s/0vx7lk97xp" rel="noopener noreferrer"&gt;You can find all the code from this article&lt;br&gt;
here.&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;As you can see, Formik is a really helpful lib to let us write better forms and&lt;br&gt;
let our code more readable.&lt;/p&gt;

&lt;p&gt;This is a simple example of how to use Formik with TypeScript, but you can improve it and use it the way you want. The goal here is to show how to use it the best way and let our code strongly-typed and safer.&lt;/p&gt;

</description>
      <category>formik</category>
      <category>typescript</category>
      <category>react</category>
    </item>
    <item>
      <title>A Complete React Boilerplate Tutorial — From Zero to Hero</title>
      <dc:creator>Leonardo Maldonado</dc:creator>
      <pubDate>Sat, 05 Jan 2019 12:15:51 +0000</pubDate>
      <link>https://forem.com/leonardomso/a-complete-react-boilerplate-tutorialfrom-zero-to-hero-jig</link>
      <guid>https://forem.com/leonardomso/a-complete-react-boilerplate-tutorialfrom-zero-to-hero-jig</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhaptoj6t5bvzb2hf7btj.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhaptoj6t5bvzb2hf7btj.jpeg" alt="enter image description here" width="800" height="248"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we’re starting learn React, to make our projects we need to make a boilerplate from scratch or use some provided by the community. Almost all the times it’s the &lt;em&gt;create-react-app&lt;/em&gt; that we use to create an app with no build configuration. Or we just make our own simple boilerplate from scratch.  &lt;/p&gt;

&lt;p&gt;From this, it comes to mind: why not make a boilerplate with all dependencies that I always use and leave it ready? The community also thought that way, so now we have several community-created boilerplates. Some are more complex than others, but they always have the same goal of saving the maximum amount of time.  &lt;/p&gt;

&lt;p&gt;This article will teach you how you can build your own boilerplate from scratch with the main dependencies used in the React community today. We’re gonna use some of the moderns features most common these days and from there you can customize it any way you want.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/leonardomso/react-bolt" rel="noopener noreferrer"&gt;The boilerplate created by this article will be available here!&lt;/a&gt;&lt;/strong&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;First of all, we’re going to create a folder to start our boilerplate. You can name it whatever you want, I’m gonna name mine &lt;strong&gt;&lt;em&gt;react-bolt&lt;/em&gt;&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;Open your terminal, and create it like this:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir react-bolt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, go to your created folder, and type the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;code&gt;npm&lt;/code&gt; will create a &lt;code&gt;package.json&lt;/code&gt; file for you, and all the dependencies that you installed and your commands will be there.  &lt;/p&gt;

&lt;p&gt;Now, we’re going to create the basic folder structure for our boilerplate. It’s gonna be like this for now:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;react-bolt    
    |--config    
    |--src    
    |--tests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Webpack
&lt;/h2&gt;

&lt;p&gt;Webpack is the most famous module-bundler for JavaScript applications nowadays. Basically, it bundles all your code and generates one or more bundles. You can learn more about it &lt;a href="https://webpack.js.org/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;In this boilerplate we’re going to use it, so install all these dependencies:  &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev webpack webpack-cli webpack-dev-server webpack-merge html-webpack-plugin clean-webpack-plugin img-loader url-loader file-loader 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now in our &lt;code&gt;config&lt;/code&gt; folder, we’re going to create another folder called &lt;code&gt;webpack&lt;/code&gt;, then inside that &lt;code&gt;webpack&lt;/code&gt; folder create 5 files.  &lt;/p&gt;

&lt;p&gt;Create a file called &lt;code&gt;paths.js&lt;/code&gt;. Inside that file is going to be the target directory for all your output files.&lt;/p&gt;

&lt;p&gt;Inside it, put all this code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import path from 'path';

module.exports = {    
    root: path.resolve(__dirname, '../', '../'),    
    outputPath: path.resolve(__dirname, '../', '../', 'build'),    
    entryPath: path.resolve(__dirname, '../', '../', 'src/index.js'),    
    templatePath: path.resolve(__dirname, '../', '../', 'src/index.html'),    
    imagesFolder: 'images',    
    fontsFolder: 'fonts',    
    cssFolder: 'css',    
    jsFolder: 'js'    
};  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, create another file called &lt;code&gt;rules.js&lt;/code&gt;, and put the following code there:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = [    
    {
        test: /\.js$/,    
        exclude: /node_modules/,    
        use: {    
        loader: 'babel-loader'    
    }    
},    
    {    
        test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,    
        exclude: /node_modules/,    
        loader: 'file-loader'    
    },    
    {    
        test: /\.(woff|woff2)$/,    
        exclude: /node_modules/,    
        loader: 'url-loader?prefix=font/&amp;amp;limit=5000'    
    },    
    {
        test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,    
        exclude: /node_modules/,    
        loader: 'url-loader?limit=10000&amp;amp;mimetype=application/octet-stream'    
    },    
    {    
        test: /\.(jpe?g|png|gif|svg)$/i,    
        use: ['url-loader?limit=10000', 'img-loader'] 
    }    
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After that, we’re going to create 3 more files:  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;webpack.common.babel.js&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';

import paths from './paths';
import rules from './rules';

module.exports = {
    entry: paths.entryPath,
    module: {
        rules
    },
    resolve: {
        modules: ['src', 'node_modules'],
        extensions: ['*', '.js', '.scss', '.css']
    },
    plugins: [
        new webpack.ProgressPlugin(),
        new HtmlWebpackPlugin({
            template: paths.templatePath,
            minify: {
                collapseInlineTagWhitespace: true,
                collapseWhitespace: true,
                preserveLineBreaks: true,
                minifyURLs: true,
                removeComments: true,
                removeAttributeQuotes: true
            }
        })
    ]
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;webpack.dev.babel.js&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import webpack from 'webpack';

import paths from './paths';
import rules from './rules';

module.exports = {
    mode: 'development',
    output: {
        filename: '[name].js',
        path: paths.outputPath,
        chunkFilename: '[name].js'
    },
    module: {
        rules
    },
    performance: {
        hints: 'warning',
        maxAssetSize: 450000,
        maxEntrypointSize: 8500000,
        assetFilter: assetFilename =&amp;gt; {
            return (
                assetFilename.endsWith('.css') || assetFilename.endsWith('.js')
            );
        }
    },
    optimization: {
        splitChunks: {
            chunks: 'all'
        }
    },
    devServer: {
        contentBase: paths.outputPath,
        compress: true,
        hot: true,
        historyApiFallback: true
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin()
    ]
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;webpack.prod.babel.js&lt;/strong&gt; &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import CleanWebpackPlugin from 'clean-webpack-plugin';

import paths from './paths';
import rules from './rules';

module.exports = {
    mode: 'production',
    output: {
        filename: `${paths.jsFolder}/[name].[hash].js`,
        path: paths.outputPath,
        chunkFilename: '[name].[chunkhash].js'
    },
    module: {
        rules
    },
    plugins: [
        new CleanWebpackPlugin([paths.outputPath.split('/').pop()], {
            root: paths.root
        })
    ],
    devtool: 'source-map'
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Basically, in our &lt;code&gt;webpack.common.babel.js&lt;/code&gt; file, we’ve set up our entry and output configuration and included as well any plugins that are required. In the &lt;code&gt;webpack.dev.babel.js&lt;/code&gt; file, we’ve set the mode to development. And in our &lt;code&gt;webpack.prod.babel.js&lt;/code&gt; file, we’ve set the mode to production.  &lt;/p&gt;

&lt;p&gt;After that, in our root folder, we’re going to create the last webpack file called &lt;code&gt;webpack.config.js&lt;/code&gt; and put in the following code:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require('@babel/register');
const webpackMerge = require('webpack-merge');

const common = require('./config/webpack/webpack.common.babel');

const envs = {
    development: 'dev',
    production: 'prod'
};

/* eslint-disable global-require,import/no-dynamic-require */
const env = envs[process.env.NODE_ENV || 'development'];
const envConfig = require(`./config/webpack/webpack.${env}.babel`);
module.exports = webpackMerge(common, envConfig);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Our webpack config is ready, so now we’re going to work on other parts of the boilerplate with &lt;em&gt;Babel&lt;/em&gt;, &lt;em&gt;ESLint&lt;/em&gt;, &lt;em&gt;Prettier&lt;/em&gt;, etc.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Babel
&lt;/h2&gt;

&lt;p&gt;I think that almost everyone who works with React has probably heard about Babel and how this simple transpiler helps our lives. If you don’t know what it is, Babel it’s basically a transpiler that converts your JavaScript code into plain old ES5 JavaScript that can run in any browser.  &lt;/p&gt;

&lt;p&gt;We’re going to use a bunch of Babel plugins, so in our root folder, install:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev @babel/core @babe/cli @babel/node @babel/plugin-proposal-class-properties @babel/plugin-proposal-object-rest-spread @babel/plugin-syntax-dynamic-import @babel/plugin-syntax-import-meta @babel/plugin-transform-async-to-generator @babel/plugin-transform-runtime @babel/preset-env @babel/preset-react @babel/register @babel/runtime babel-eslint babel-jest babel-loader babel-core@7.0.0-bridge.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After this, we’re gonna create a file in our root folder called &lt;code&gt;.babelrc&lt;/code&gt; and inside that file, we’re going to put the following code:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{    
  presets:        
    [        
        [            
            "@babel/preset-env",                
            {                
                useBuiltIns:  "entry"
            }
        ],
        "@babel/preset-react"
    ],
    plugins:        
    [        
        "@babel/plugin-proposal-object-rest-spread",            
        "@babel/plugin-transform-runtime",            
        "@babel/plugin-transform-async-to-generator",            
        "@babel/plugin-proposal-class-properties"
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now our project is compiled by Babel, and we can use the next-generation JavaScript syntax without any problems.&lt;/p&gt;

&lt;h2&gt;
  
  
  ESLint
&lt;/h2&gt;

&lt;p&gt;The most used tool for linting projects nowadays is ESLint. It is really helpful to find certain classes of bugs, such as those related to variable scope, assignment to undeclared variables, and so on.  &lt;/p&gt;

&lt;p&gt;First, install the following dependencies:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev eslint eslint-config-airbnb eslint-config-prettier eslint-loader eslint-plugin-babel eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-prettier eslint-plugin-react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then, in our root folder, create a file called &lt;code&gt;.eslintrc&lt;/code&gt; and put the following code there:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "parser": "babel-eslint",
    "extends": ["airbnb", "prettier", "prettier/react"],
    "plugins": ["prettier"],
    "parserOptions": {
        "ecmaVersion": 6,
        "ecmaFeatures": {
            "jsx": true
        }
    },
    "env": {
        "browser": true,
        "node": true,
        "mocha": true,
        "es6": true,
        "jest": true
    },
    "rules": {
        "indent": ["error", 4],
        "space-before-function-paren": "off",
        "react/prefer-stateless-function": "warn",
        "react/jsx-one-expression-per-line": "off",
        "import/no-extraneous-dependencies": [
            "error",
            { "devDependencies": true }
        ],
        "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
        "linebreak-style": "off",
        "global-require": "off",
        "semi": "warn",
        "arrow-body-style": "off",
        "no-multiple-empty-lines": ["warn", { "max": 1 }],
        "no-unused-expressions": [
            "error",
            {
                "allowTaggedTemplates": true
            }
        ],
        "no-underscore-dangle": [
            2,
            { "allow": ["__REDUX_DEVTOOLS_EXTENSION__"] }
        ]
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Prettier
&lt;/h2&gt;

&lt;p&gt;Prettier is basically a code formatter. It parses your code and re-prints it with its own rules that take the maximum line length into account, wrapping code when necessary.  &lt;/p&gt;

&lt;p&gt;You just need to install it:  &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev prettier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And in our root folder, create a file called &lt;code&gt;.prettierrc&lt;/code&gt; and put the following code there:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "printWidth": 80,
    "tabWidth": 4,
    "semi": true,
    "singleQuote": true,
    "bracketSpacing": true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  React
&lt;/h2&gt;

&lt;p&gt;React is an open-source JavaScript application library to build user interfaces. It was developed by Facebook and has a huge community behind it. If you are reading this article, I assume that you already know about React, but if you want to learn more about it, you can read up &lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;We’re going to install the following dependencies:  &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save react react-dom cross-env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And inside our src folder, we’re going to create a simple HTML file &lt;code&gt;index.html&lt;/code&gt; and put in the following code:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
    &amp;lt;head&amp;gt;
        &amp;lt;meta charset="UTF-8" /&amp;gt;
        &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&amp;gt;
        &amp;lt;meta http-equiv="X-UA-Compatible" content="ie=edge" /&amp;gt;
        &amp;lt;title&amp;gt;React Bolt&amp;lt;/title&amp;gt;
    &amp;lt;/head&amp;gt;

    &amp;lt;body&amp;gt;
        &amp;lt;div id="root"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After that, we’re going to create a simple React project. Inside our &lt;code&gt;src&lt;/code&gt; folder, create a &lt;code&gt;index.js&lt;/code&gt; file like this:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import ReactDOM from 'react-dom';

import App from './components/App';

ReactDOM.render(
    &amp;lt;App /&amp;gt;,
    document.getElementById('root')
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Inside our &lt;code&gt;src&lt;/code&gt; folder we’re going to have the following structure:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*src
    |--actions
    |--components
    |--reducers
    |--reducers
    |--store*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Create a file called &lt;code&gt;App.js&lt;/code&gt; inside the &lt;code&gt;components&lt;/code&gt; folder, and put in the following code:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';

const App = () =&amp;gt; &amp;lt;h1&amp;gt;React Bolt&amp;lt;/h1&amp;gt;;

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Redux
&lt;/h2&gt;

&lt;p&gt;Redux makes it easy to manage the state of your application. Another way of looking at this is that it helps you manage the data you display and how you respond to user actions. These days a lot of people prefer other options like &lt;em&gt;MobX&lt;/em&gt; or just the &lt;em&gt;setState&lt;/em&gt; itself, but I’m gonna stick with Redux for this boilerplate.  &lt;/p&gt;

&lt;p&gt;First, we’re going to install some dependencies:  &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save redux react-redux redux-thunk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then, we’re going to create our Redux store, and put some state there. In our store folder, create an &lt;code&gt;index.js&lt;/code&gt; file and put that following code there:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import logger from 'redux-logger';

import rootReducer from '../reducers';

const middleware = applyMiddleware(thunk, logger);

const reduxDevTools =
    window.__REDUX_DEVTOOLS_EXTENSION__ &amp;amp;&amp;amp;
    window.__REDUX_DEVTOOLS_EXTENSION__();

const store = createStore(
    rootReducer,
    compose(
        middleware,
        reduxDevTools
    )
);

export default store;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, inside our &lt;code&gt;reducers&lt;/code&gt; folder create an &lt;code&gt;index.js&lt;/code&gt; and put the following code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { combineReducers } from 'redux';

const rootReducer = combineReducers({
    state: () =&amp;gt; ({})
});

export default rootReducer;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Last, we’re gonna to our &lt;code&gt;index.js&lt;/code&gt; in our &lt;code&gt;src&lt;/code&gt; folder, and wrap the code with the &lt;code&gt;&amp;lt;Provider /&amp;gt;&lt;/code&gt; and pass our store as props to make it available to our application.  &lt;/p&gt;

&lt;p&gt;It’s going to be like this:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { Fragment } from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';

import store from './store';
import App from './components/App';

ReactDOM.render(  
    &amp;lt;Provider store={store}&amp;gt;
        &amp;lt;App /&amp;gt;
    &amp;lt;/Provider&amp;gt;,
    document.getElementById('root')
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;All done. Our Redux store is configured and ready to go.  &lt;/p&gt;

&lt;h2&gt;
  
  
  React Router
&lt;/h2&gt;

&lt;p&gt;React Router is the standard routing library for React. Basically, it &lt;em&gt;keeps your UI in sync with the URL&lt;/em&gt;. We’re gonna use it in our boilerplate, so install it:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save react-router-dom  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After that, go to our &lt;code&gt;index.js&lt;/code&gt; in our &lt;code&gt;src&lt;/code&gt; folder and wrap all the code there with the &lt;code&gt;&amp;lt;BrowserRouter&amp;gt;&lt;/code&gt;.  &lt;/p&gt;

&lt;p&gt;Our &lt;code&gt;index.js&lt;/code&gt; in our &lt;code&gt;src&lt;/code&gt; folder it’s going to end up like this:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { Fragment } from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import { Provider } from 'react-redux';

import store from './store';
import App from './components/App';

ReactDOM.render(
    &amp;lt;BrowserRouter&amp;gt;       
        &amp;lt;Provider store={store}&amp;gt;
            &amp;lt;App /&amp;gt;
        &amp;lt;/Provider&amp;gt;
    &amp;lt;/BrowserRouter&amp;gt;,
    document.getElementById('root')
); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Styled Components
&lt;/h2&gt;

&lt;p&gt;Styled Components makes CSS easy for everyone, as it helps you organize your React project. Its objective is to write more small and reusable components. We’re gonna use it, and if you want to learn more about it, read up &lt;a href="https://www.styled-components.com/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;First, install it:  &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save styled-components  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then, in our &lt;code&gt;App.js&lt;/code&gt; file inside our &lt;code&gt;components&lt;/code&gt; folder, we’re going to create a simple title using Styled Components. Our title is going to be like this:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Title = styled.h1`
    color: black;
    font-size: 2.5rem;
    font-weight: 700;
`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And inside our file, we need to import &lt;code&gt;styled-components&lt;/code&gt;, so our file is going to end up like this: &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import styled from 'styled-components';

const Title = styled.h1`
    color: black;
    font-size: 2.5rem;
    font-weight: 700;
`;

const App = () =&amp;gt; &amp;lt;Title&amp;gt;React Bolt&amp;lt;/Title&amp;gt;;

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Jest &amp;amp; React Testing Library
&lt;/h2&gt;

&lt;p&gt;Jest is an open-source JavaScript testing library from Facebook. It makes it easy to test your application, and gives us a lot of information about what is giving the right output and what’s not. React Testing Library is a very light-weight solution for testing React components. Basically, this library is a replacement for Enzyme.  &lt;/p&gt;

&lt;p&gt;Every application needs some kind of tests. I’m not gonna write tests in this article but I’m gonna show you how you can configure these tools to start testing your applications.  &lt;/p&gt;

&lt;p&gt;First, we’re gonna install both:  &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev jest jest-dom react-testing-library  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After that, go to our &lt;code&gt;package.json&lt;/code&gt; and put the following after all:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; "jest": {
    "setupFiles": [
        "&amp;lt;rootDir&amp;gt;/config/tests/jest.config"
    ],
    "transform": {
        "^.+\\.js$": "babel-jest"
    }
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then, go to our &lt;code&gt;config&lt;/code&gt; folder, and inside it created another folder called &lt;code&gt;tests&lt;/code&gt; and inside that folder, create 2 files.  &lt;/p&gt;

&lt;p&gt;First, create a file called &lt;code&gt;jest.config.js&lt;/code&gt; and put in the following code:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
    automock: false,
    browser: false,
    bail: false,
    collectCoverageFrom: [
        'src/**/*.{js,jsx}',
        '!**/node_modules/**',
        '!**/vendor/**'
    ],
    coverageDirectory: '&amp;lt;rootDir&amp;gt;/coverage',
    globals: {
        __DEV__: true
    },
    moduleFileExtensions: ['js', 'json', 'jsx', 'node'],
    transform: {
        '^.+\\.js?$': 'babel-jest'
    },
    verbose: true,
    setupTestFrameworkScriptFile: './rtl.setup.js'
};  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then, create a file called &lt;code&gt;rtl.setup.js&lt;/code&gt; and put in the following code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// See https://github.com/kentcdodds/react-testing-library#global-config
import 'jest-dom/extend-expect';
import 'react-testing-library/cleanup-after-each';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;All done. Our boilerplate is ready to go and you can use it now.  &lt;/p&gt;

&lt;p&gt;Now go to our file &lt;code&gt;package.json&lt;/code&gt; and put in the following code:  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
    "start": "cross-env NODE_ENV=development webpack-dev-server --open",
    "build": "cross-env NODE_ENV=production webpack",
    "lint": "eslint ./src/**/**.js",
    "lint:fix": "eslint ./src/**/**.js --fix",
    "test": "jest",
    "test:watch": "npm run test --watch",
    "test:cover": "npm run test --coverage"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, if you run the command npm start and go to &lt;code&gt;localhost:8080&lt;/code&gt;, we should see our application working fine!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/leonardomso/react-bolt" rel="noopener noreferrer"&gt;If you want to see my final code, the boilerplate created by this article is available here!&lt;/a&gt;&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;I have some ideas for some features that I’d love to include in the boilerplate, so please feel free to contribute!  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🐦 &lt;a href="https://twitter.com/leonardomso" rel="noopener noreferrer"&gt;Follow me on Twitter! &lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;⭐ &lt;a href="https://github.com/leonardomso" rel="noopener noreferrer"&gt;Follow me on GitHub!&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A Beginner’s Guide to GraphQL</title>
      <dc:creator>Leonardo Maldonado</dc:creator>
      <pubDate>Sat, 05 Jan 2019 11:45:31 +0000</pubDate>
      <link>https://forem.com/leonardomso/a-beginners-guide-to-graphql-3kjj</link>
      <guid>https://forem.com/leonardomso/a-beginners-guide-to-graphql-3kjj</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F978k0dspx3r17fxtfvkq.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F978k0dspx3r17fxtfvkq.jpeg" alt="enter image description here" width="800" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One of the most commonly discussed terms today is the API. A lot of people don’t know exactly what an API is. Basically, API stands for &lt;strong&gt;Application Programming Interface.&lt;/strong&gt; It is, as the name says, an interface with which people — developers, users, consumers — can interact with data.&lt;/p&gt;

&lt;p&gt;You can think of an API as a bartender. You ask the bartender for a drink, and they give you what you wanted. Simple. So why is that a problem?&lt;/p&gt;

&lt;p&gt;Since the start of the modern web, building APIs has not been as hard as it sounds. But learning and understanding APIs was. Developers form the majority of the people that will use your API to build something or just consume data. So your API should be as clean and as intuitive as possible. A well-designed API is very easy to use and learn. It’s also intuitive, a good point to keep in mind when you’re starting to design your API.&lt;/p&gt;

&lt;p&gt;We’ve been using REST to build APIs for a long time. Along with that comes some problems. When building an API using REST design, you’ll face some problems like:&lt;/p&gt;

&lt;p&gt;1) you’ll have a lot of endpoints&lt;/p&gt;

&lt;p&gt;2) it’ll be much harder for developers to learn and understand your API&lt;/p&gt;

&lt;p&gt;3) there is over- and under-fetching of information&lt;/p&gt;

&lt;p&gt;To solve these problems, Facebook created GraphQL. Today, I think GraphQL is the best way to build APIs. This article will tell you why you should start to learn it today.&lt;/p&gt;

&lt;p&gt;In this article, you’re going to learn how GraphQL works. I’m going to show you how to create a very well-designed, efficient, powerful API using GraphQL.&lt;/p&gt;

&lt;p&gt;You’ve probably already heard about GraphQL, as a lot of people and companies are using it. Since GraphQL is open-source, its community has grown huge.&lt;/p&gt;

&lt;p&gt;Now, it’s time for you start to learn in practice how GraphQL works and all about its magic.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is GraphQL?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://graphql.org" rel="noopener noreferrer"&gt;&lt;strong&gt;GraphQL&lt;/strong&gt;&lt;/a&gt; is an open-source query language developed by Facebook. It provides us with a more efficient way design, create, and consume our APIs. Basically, it’s the replacement for REST.&lt;/p&gt;

&lt;p&gt;GraphQL has a lot of features, like:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;You write the data that you want, and you get exactly the data that you want. &lt;strong&gt;No more over-fetching of information&lt;/strong&gt; as we are used to with REST.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It gives us a &lt;strong&gt;single endpoint&lt;/strong&gt;, no more version 2 or version 3 for the same API.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;GraphQL is &lt;strong&gt;strongly-typed&lt;/strong&gt;, and with that you can validate a query within the GraphQL type system before execution. It helps us build more powerful APIs.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is a basic introduction to GraphQL — why it’s so powerful and why it’s gaining a lot of popularity these days. If you want to learn more about it, I recommend you to go the &lt;a href="https://graphql.org/" rel="noopener noreferrer"&gt;GraphQL website&lt;/a&gt; and check it out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;The main objective in this article is not to learn how to set up a GraphQL server, so we’re not getting deep into that for now. The objective is to learn how GraphQL works in practice, so we’re gonna use a zero-configuration GraphQL server called ☄️ &lt;a href="https://github.com/glennreyes/graphpack" rel="noopener noreferrer"&gt;Graphpack&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To start our project, we’re going to create a new folder and you can name it whatever you want. I’m going to name it &lt;code&gt;graphql-server&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;Open your terminal and type:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir graphql-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, you should have &lt;code&gt;npm&lt;/code&gt; or &lt;code&gt;yarn&lt;/code&gt; installed in your machine. If you don’t know what these are, &lt;code&gt;npm&lt;/code&gt; and &lt;code&gt;yarn&lt;/code&gt; are package managers for the JavaScript programming language. For Node.js, the default package manager is &lt;code&gt;npm&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Inside your created folder type the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Or if you use &lt;code&gt;yarn&lt;/code&gt;:&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;code&gt;npm&lt;/code&gt; will create a &lt;code&gt;package.json&lt;/code&gt; file for you, and all the dependencies that you installed and your commands will be there.&lt;/p&gt;

&lt;p&gt;So now, we’re going to install &lt;strong&gt;the only dependency&lt;/strong&gt; that we’re going to use.&lt;/p&gt;

&lt;p&gt;☄️&lt;a href="https://github.com/glennreyes/graphpack" rel="noopener noreferrer"&gt;Graphpack&lt;/a&gt; lets you create a GraphQL server &lt;strong&gt;with zero configuration&lt;/strong&gt;. Since we’re just starting with GraphQL, this will help us a lot to go on and learn more without getting worried about a server configuration.&lt;/p&gt;

&lt;p&gt;In your terminal, inside your root folder, install it like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev graphpack
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Or, if you use &lt;code&gt;yarn&lt;/code&gt;, you should go like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add --dev graphpack
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After &lt;em&gt;Graphpack&lt;/em&gt; is installed, go to our scripts in &lt;code&gt;package.json&lt;/code&gt; file, and put the following code there:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
    "dev": "graphpack",
    "build": "graphpack build"
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We’re going to create a folder called &lt;code&gt;src&lt;/code&gt;, and it’s going to be the only folder in our entire server.&lt;/p&gt;

&lt;p&gt;Create a folder called &lt;code&gt;src&lt;/code&gt;, after that, inside our folder, we’re going to create three files only.&lt;/p&gt;

&lt;p&gt;Inside our &lt;code&gt;src&lt;/code&gt; folder create a file called &lt;code&gt;schema.graphql&lt;/code&gt;. Inside this first file, put the following code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Query {    
    hello: String    
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this &lt;code&gt;schema.graphql&lt;/code&gt; file is going to be our entire GraphQL schema. If you don’t know what it is, I’ll explain later — don't worry.&lt;/p&gt;

&lt;p&gt;Now, inside our &lt;code&gt;src&lt;/code&gt; folder, create a second file. Call it &lt;code&gt;resolvers.js&lt;/code&gt; and, inside this second file, put the following code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { users } from "./db";

const resolvers = {    
    Query: {    
        hello: () =&amp;gt; "Hello World!"    
    }    
};

export default resolvers;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This &lt;code&gt;resolvers.js&lt;/code&gt; file is going to be the way we provide the instructions for turning a GraphQL operation into data.&lt;/p&gt;

&lt;p&gt;And finally, inside your &lt;em&gt;src&lt;/em&gt; folder, create a third file. Call this &lt;code&gt;db.js&lt;/code&gt; and, inside this third file, put the following code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export let users = [    
    { id: 1, name: "John Doe", email: "john@gmail.com", age: 22 },    
    { id: 2, name: "Jane Doe", email: "jane@gmail.com", age: 23 }    
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this tutorial we’re not using a real-world database. So this &lt;code&gt;db.js&lt;/code&gt; file is going to simulate a database, just for learning purposes.&lt;/p&gt;

&lt;p&gt;Now our &lt;code&gt;src&lt;/code&gt; folder should look like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src
  |--db.js
  |--resolvers.js
  |--schema.graphql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, if you run the command &lt;code&gt;npm run dev&lt;/code&gt; or, if you’re using &lt;code&gt;yarn&lt;/code&gt;, &lt;code&gt;yarn dev&lt;/code&gt;, you should see this output in your terminal:&lt;/p&gt;

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

&lt;p&gt;You can now go to &lt;code&gt;localhost:4000&lt;/code&gt;. This means that we’re ready to go and start writing our first queries, mutations, and subscriptions in GraphQL.&lt;/p&gt;

&lt;p&gt;You see the GraphQL Playground, a powerful GraphQL IDE for better development workflows. If you want to learn more about GraphQL Playground, &lt;a href="https://www.prisma.io/blog/introducing-graphql-playground-f1e0a018f05d/" rel="noopener noreferrer"&gt;click here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Schema
&lt;/h2&gt;

&lt;p&gt;GraphQL has its own type of language that’s used to write schemas. This is a human-readable schema syntax called &lt;strong&gt;Schema Definition Language (SDL)&lt;/strong&gt;. The SDL will be the same, no matter what technology you’re using — you can use this with any language or framework that you want.&lt;/p&gt;

&lt;p&gt;This schema language its very helpful because it’s simple to understand what types your API is going to have. You can understand it just by looking right it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types
&lt;/h2&gt;

&lt;p&gt;Types are one of the most important features of GraphQL. Types are custom objects that represent how your API is going to look. For example, if you’re building a social media application, your API should have types such as Posts, Users, Likes, Groups.&lt;/p&gt;

&lt;p&gt;Types have fields, and these fields return a specific type of data. For example, we’re going to create a User type, we should have some name, email, and age fields. Type fields can be anything, and always return a type of data as Int, Float, String, Boolean, ID, a List of Object Types, or Custom Objects Types.&lt;/p&gt;

&lt;p&gt;So now to write our first Type, go to your &lt;code&gt;schema.graphql&lt;/code&gt; file and replace the type Query that is already there with the following:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type User {    
    id: ID!    
    name: String!    
    email: String!    
    age: Int    
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Each User is going to have an ID, so we gave it an ID type. User is also going to have a name and email, so we gave it a String type, and an age, which we gave an Int type. Pretty simple, right?&lt;/p&gt;

&lt;p&gt;But, what about those ! at the end of every line? The exclamation point means that the fields are &lt;strong&gt;non-nullable&lt;/strong&gt;, which means that every field must return some data in each query. The only &lt;strong&gt;nullable&lt;/strong&gt; field that we’re going to have in our User type will be age.&lt;/p&gt;

&lt;p&gt;In GraphQL, you will deal with three main concepts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;queries&lt;/strong&gt; — the way you’re going to get data from the server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;mutations&lt;/strong&gt; — the way you’re going to modify data on the server and get updated data back (create, update, delete).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;subscriptions&lt;/strong&gt; — the way you’re going to maintain a real-time connection with the server.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I’m going to explain all of them to you. Let’s start with Queries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Queries
&lt;/h2&gt;

&lt;p&gt;To explain this in a simple way, queries in GraphQL are how you’re going to get data. One of the most beautiful things about queries in GraphQL is that you are just going to get the exact data that you want. No more, no less. This has a huge positive impact in our API — no more over-fetching or under-fetching information as we had with REST APIs.&lt;/p&gt;

&lt;p&gt;We’re going to create our first type Query in GraphQL. All our queries will end up inside this type. So to start, we’ll go to our &lt;code&gt;schema.graphql&lt;/code&gt; and write a new type called Query:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Query {    
    users: [User!]!    
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;It’s very simple: the users query &lt;strong&gt;will return to us an array of one or more Users&lt;/strong&gt;. It will not return null, because we put in the &lt;strong&gt;!&lt;/strong&gt;, which means it’s a non-nullable query. It should always return something.&lt;/p&gt;

&lt;p&gt;But we could also return a specific user. For that we’re going to create a new query called user. Inside our Query type, put the following code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user(id: ID!): User!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now our Query type should look like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Query {    
    users: [User!]!    
    user(id: ID!): User!    
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As you see, with queries in GraphQL we can also pass arguments. In this case, to query for a specific user, we’re going to pass its ID.&lt;/p&gt;

&lt;p&gt;But, you may be wondering: how does GraphQL know where get the data? That’s why we should have a &lt;code&gt;resolvers.js&lt;/code&gt; file. That file tells GraphQL how and where it's going to fetch the data.&lt;/p&gt;

&lt;p&gt;First, go to our &lt;code&gt;resolvers.js&lt;/code&gt; file and import the &lt;code&gt;db.js&lt;/code&gt; that we just created a few moments ago. Your &lt;code&gt;resolvers.js&lt;/code&gt; file should look like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { users } from "./db";

const resolvers = {    
    Query: {    
        hello: () =&amp;gt; "Hello World!"    
    }    
};

export default resolvers;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, we’re going to create our first Query. Go to your &lt;code&gt;resolvers.js&lt;/code&gt; file and replace the hello function. Now your Query type should look like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { users } from "./db";

const resolvers = {    
    Query: {    
        user: (parent, { id }, context, info) =&amp;gt; {    
        return users.find(user =&amp;gt; user.id == id);    
        },    
        users: (parent, args, context, info) =&amp;gt; {    
            return users;    
        }    
    }    
};

export default resolvers;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, to explain how is it going to work:&lt;/p&gt;

&lt;p&gt;Each query resolver has four arguments. In the user function, we’re going to pass id as an argument, and then return the specific user that matches the passed id. Pretty simple.&lt;/p&gt;

&lt;p&gt;In the users function, we’re just going to return the users array that already exists. It’ll always return to us all of our users.&lt;/p&gt;

&lt;p&gt;Now, we’re going to test if our queries are working fine. Go to &lt;code&gt;localhost:4000&lt;/code&gt; and put in the following code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;query {    
    users {    
        id    
        name    
        email    
        age    
    }    
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;It should return to you all of our users.&lt;/p&gt;

&lt;p&gt;Or, if you want to return a specific user:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;query {    
    user(id: 1) {    
        id    
        name    
        email    
        age    
    }    
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, we’re going to start learning about &lt;strong&gt;mutations&lt;/strong&gt;, one of the most important features in GraphQL.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mutations
&lt;/h2&gt;

&lt;p&gt;In GraphQL, mutations are the way you’re going to modify data on the server and get updated data back. You can think like the CUD (Create, Update, Delete) of REST .&lt;/p&gt;

&lt;p&gt;We’re going to create our first type mutation in GraphQL, and all our mutations will end up inside this type. So, to start, go to our &lt;code&gt;schema.graphql&lt;/code&gt; and write a new type called mutation:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Mutation {    
    createUser(id: ID!, name: String!, email: String!, age: Int): User!    
    updateUser(id: ID!, name: String, email: String, age: Int): User!    
    deleteUser(id: ID!): User!    
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As you can see, we’re going to have three mutations:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;createUser&lt;/strong&gt;: we should pass an ID, name, email, and age. It should return a new user to us.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;updateUser&lt;/strong&gt;: we should pass an ID, and a new name, email, or age. It should return a new user to us.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;deleteUser&lt;/strong&gt;: we should pass an ID. It should return the deleted user to us.&lt;/p&gt;

&lt;p&gt;Now, go to our &lt;code&gt;resolvers.js&lt;/code&gt; file and &lt;strong&gt;below&lt;/strong&gt; the Query object, create a new mutation object like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Mutation: {    
    createUser: (parent, { id, name, email, age }, context, info) =&amp;gt; {    
        const newUser = { id, name, email, age };    
        users.push(newUser);    
        return newUser;    
},   
    updateUser: (parent, { id, name, email, age }, context, info) =&amp;gt; {    
        let newUser = users.find(user =&amp;gt; user.id == id);    
        newUser.name = name;    
        newUser.email = email;    
        newUser.age = age;

        return newUser;
    },    
    deleteUser: (parent, { id }, context, info) =&amp;gt; {    
        const userIndex = users.findIndex(user =&amp;gt; user.id == id);

        if (userIndex === -1) throw new Error("User not found.");

        const deletedUsers = users.splice(userIndex, 1);

        return deletedUsers[0];     
    }    
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, our &lt;code&gt;resolvers.js&lt;/code&gt; file should look like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { users } from "./db";

const resolvers = {    
    Query: {        
        user: (parent, { id }, context, info) =&amp;gt; {      
            return users.find(user =&amp;gt; user.id == id);       
        },      
        users: (parent, args, context, info) =&amp;gt; {       
            return users;       
        }       
    },    
    Mutation: {    
        createUser: (parent, { id, name, email, age }, context, info) =&amp;gt; {    
            const newUser = { id, name, email, age };    
            users.push(newUser);    
            return newUser;    
    },   
        updateUser: (parent, { id, name, email, age }, context, info) =&amp;gt; {    
            let newUser = users.find(user =&amp;gt; user.id == id);    
            newUser.name = name;    
            newUser.email = email;    
            newUser.age = age;

            return newUser;
        },    
        deleteUser: (parent, { id }, context, info) =&amp;gt; {    
            const userIndex = users.findIndex(user =&amp;gt; user.id === id);

            if (userIndex === -1) throw new Error("User not found.");

            const deletedUsers = users.splice(userIndex, 1);

            return deletedUsers[0];         
        }    
    }    
};

export default resolvers;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, we’re going to test if our mutations are working fine. Go to &lt;code&gt;localhost:4000&lt;/code&gt; and put in the following code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mutation {    
    createUser(id: 3, name: "Robert", email: "robert@gmail.com", age: 21) {    
        id    
        name    
        email    
        age    
    }    
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;It should return a new user to you. If you want to try making new mutations, I recommend you to try for yourself! Try to delete this same user that you created to see if it’s working fine.&lt;/p&gt;

&lt;p&gt;Finally, we’re going to start learning about &lt;strong&gt;subscriptions&lt;/strong&gt;, and why they are so powerful.&lt;/p&gt;

&lt;h2&gt;
  
  
  Subscriptions
&lt;/h2&gt;

&lt;p&gt;As I said before, subscriptions are the way you’re going to maintain a real-time connection with a server. That means that whenever an event occurs in the server and whenever that event is called, the server will send the corresponding data to the client.&lt;/p&gt;

&lt;p&gt;By working with subscriptions, you can keep your app updated to the latest changes between different users.&lt;/p&gt;

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

&lt;p&gt;A basic subscription is like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;subscription {    
    users {    
        id    
        name    
        email    
        age    
    }    
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You will say it’s very similar to a query, and yes it is. But it works differently.&lt;/p&gt;

&lt;p&gt;When something is updated in the server, the server will run the GraphQL query specified in the subscription, and send a newly updated result to the client.&lt;/p&gt;

&lt;p&gt;We’re not going to work with subscriptions in this specific article, but if you want to read more about them &lt;a href="https://hackernoon.com/from-zero-to-graphql-subscriptions-416b9e0284f3" rel="noopener noreferrer"&gt;click here&lt;/a&gt;.&lt;/p&gt;

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

&lt;p&gt;As you have seen, GraphQL is a new technology that is really powerful. It gives us real power to build better and well-designed APIs. That’s why I recommend you start to learn it now. For me, it will eventually replace REST.&lt;/p&gt;

&lt;p&gt;Thanks for reading the article, please give a comment below!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🐦 &lt;a href="https://twitter.com/leonardomso" rel="noopener noreferrer"&gt;&lt;strong&gt;Follow me on Twitter!&lt;/strong&gt;&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;⭐ &lt;a href="https://github.com/leonardomso" rel="noopener noreferrer"&gt;&lt;strong&gt;Follow me on GitHub!&lt;/strong&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>graphql</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
