<?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>DEV Community: Jakob Lind</title>
    <description>The latest articles on DEV Community by Jakob Lind (@jakoblind).</description>
    <link>https://dev.to/jakoblind</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%2F22766%2Ff0ac0ffb-3d7e-45bf-8d8c-94e315cd1f58.jpg</url>
      <title>DEV Community: Jakob Lind</title>
      <link>https://dev.to/jakoblind</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jakoblind"/>
    <language>en</language>
    <item>
      <title>What is babel-preset-env and why do I need it?</title>
      <dc:creator>Jakob Lind</dc:creator>
      <pubDate>Tue, 23 Apr 2019 18:04:40 +0000</pubDate>
      <link>https://dev.to/jakoblind/what-is-babel-preset-env-and-why-do-i-need-it-5dni</link>
      <guid>https://dev.to/jakoblind/what-is-babel-preset-env-and-why-do-i-need-it-5dni</guid>
      <description>&lt;p&gt;If you have followed any recent tutorial on how to set up a modern JavaScript project, you have installed Babel and then added &lt;em&gt;babel-preset-env&lt;/em&gt; to your &lt;em&gt;.babelrc&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  presets: ['@babel/preset-env']
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;...and things works fine. It transpiles the ES6 for you just like you wanted to and you move on with the tutorial.&lt;/p&gt;

&lt;p&gt;But what did you just do with your &lt;em&gt;.babelrc&lt;/em&gt; file and why does it work?&lt;/p&gt;

&lt;p&gt;It's not a nice feeling to just type something that you read in a tutorial without really understand why you should use it. Let's look into what &lt;em&gt;babel-preset-env&lt;/em&gt; really do, and why you need it.&lt;/p&gt;

&lt;p&gt;This is part 2 of my post about implementing ES6 with Babel and webpack. In &lt;a href="http://blog.jakoblind.no/babel-webpack-es6/"&gt;the first part&lt;/a&gt;, you learned the basics of what problems Babel solves.&lt;/p&gt;

&lt;p&gt;Before I can tell you what babel-preset-env does, I need to explain the basics of Babel to you. It's good to refresh even if you feel you already know it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Babel from scratch
&lt;/h2&gt;

&lt;p&gt;The most common way to use Babel is together with a build system such as webpack. When using Babel with a build tool it's easy to overlook how Babel really works. It feels like Babel and webpack is the same thing.&lt;/p&gt;

&lt;p&gt;A good exercise is to learn Babel without a build system - even though you don't intend to use it that way in production. So get your editor and terminal ready and code along.&lt;/p&gt;

&lt;p&gt;First create a new NPM project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir babel-test
cd babel-test
npm init -y
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next install Babel as dependency to your empty project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev @babel/core @babel/cli
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Add a file called &lt;em&gt;input.js&lt;/em&gt; and add the following to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hello&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="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;hello world!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That is an &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions"&gt;arrow function&lt;/a&gt; which is an ES6 feature. This is supported in most browsers but &lt;a href="https://caniuse.com/#feat=arrow-functions"&gt;not&lt;/a&gt; all, that's why it's a good idea to transpile it to ES5. Now let's run this file through Babel:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx babel input.js --out-file output.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you open &lt;em&gt;output.js&lt;/em&gt;, you'll see that nothing has changed. It's exactly the same content as &lt;em&gt;input.js&lt;/em&gt;. That's not what you expected, was it? The reason for this is that Babel doesn't do anything out-of-the-box but Babel is built on presets and plugins. If you don't add any presets or plugins, then Babel will do nothing.&lt;/p&gt;

&lt;blockquote&gt;Babel doesn't do anything out-of-the-box
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  It's the Babel plugins that does the work
&lt;/h3&gt;

&lt;p&gt;To make Babel actually &lt;em&gt;do&lt;/em&gt; something, we need to add a plugin. It's the plugins that does the heavy lifting.&lt;/p&gt;

&lt;p&gt;Each plugin is it's own NPM library. So for every plugin you want to install, you have to install a new NPM library or you can use a preset that we'll come back to in the next section.&lt;/p&gt;

&lt;p&gt;In the code you have written in &lt;em&gt;input.js&lt;/em&gt; you only have one ES6 feature: an arrow function. So what we are going to now is to install a Babel plugin that transpiles ES6 arrow functions.&lt;/p&gt;

&lt;p&gt;Let's start by installing a plugin that transpiles the function you have written in &lt;em&gt;input.js&lt;/em&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev @babel/plugin-transform-arrow-functions
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next, you need to tell Babel to use the dependency. Add a file called &lt;em&gt;.babelrc&lt;/em&gt; file to the root of your project. This is the configuration file for Babel, and you'll use it to tell babel to use the plugin &lt;a href="https://babeljs.io/docs/en/babel-plugin-transform-arrow-functions"&gt;@babel/plugin-transform-arrow-functions&lt;/a&gt; when doing the transpliation. This plugin only transpiles ES6 arrow functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  plugins: ['@babel/plugin-transform-arrow-functions']
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Ok, that's it. Now you can re-run babel and look at the generated output.js file. It now contains the transpiled code!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hello&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="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&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;hello world!&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;That's awesome! But if you want to use more ES6 features you would need to install one NPM package and add an entry in &lt;em&gt;.babelrc&lt;/em&gt; for &lt;em&gt;every&lt;/em&gt; feature. That's just too much work. But there is a solution to this: presets!&lt;/p&gt;

&lt;h3&gt;
  
  
  Babel presets bundles together common Babel plugins
&lt;/h3&gt;

&lt;p&gt;The Babel foundation has created presets that contains common bundles of plugins. That means you only have to do the NPM installation and babel configuration once and then a bunch of plugins are automatically installed for you.&lt;/p&gt;

&lt;p&gt;There are many different Babel presets, both official presets from Babel foundation and unofficial presets from other organizations such as &lt;a href="https://github.com/airbnb/babel-preset-airbnb"&gt;Airbnb&lt;/a&gt;. Heck, you could even create your own preset if you want.&lt;/p&gt;

&lt;p&gt;The official presets are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;@babel/preset-env&lt;/li&gt;
&lt;li&gt;@babel/preset-flow&lt;/li&gt;
&lt;li&gt;@babel/preset-react&lt;/li&gt;
&lt;li&gt;@babel/preset-typescript&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every preset is its own NPM dependency that you need to install and configure. Ok, now you are &lt;em&gt;finally&lt;/em&gt; ready to learn about babel-preset-env.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ok, now babel-preset-env
&lt;/h2&gt;

&lt;p&gt;Let's convert you mini-code base to use babel-preset-env instead of @babel/plugin-transform-arrow-functions&lt;/p&gt;

&lt;p&gt;Install the NPM dependency:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev @babel/preset-env
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next, configure in the preset section of your &lt;em&gt;.babelrc&lt;/em&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  presets: ['@babel/preset-env']
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;What you have done now, is that you have installed the basic configuration of babel-preset-env. Out-of-the-box you get all plugins you need to transpile all ES6 features!&lt;/p&gt;

&lt;p&gt;But babel preset env is smarter than this. You can have even more fine grained controll over what plugins should be installed&lt;/p&gt;

&lt;h2&gt;
  
  
  The unique selling point with babel-preset-env is that you can define what browsers you support
&lt;/h2&gt;

&lt;p&gt;By default, babel-preset-env just installs &lt;em&gt;all&lt;/em&gt; ES6 plugin you'll need. But this can bloat up your bundle. Look at this example how modern ES6 is transpiled to old legacy JavaScript code&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5nq0An4i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://d4jyn86spyrm8.cloudfront.net/unnamed.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5nq0An4i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://d4jyn86spyrm8.cloudfront.net/unnamed.jpg" alt=""&gt;&lt;/a&gt;From &lt;a href="https://twitter.com/jamiebuilds/status/1022568923726639104"&gt;this tweet&lt;/a&gt; by &lt;a href="https://twitter.com/jamiebuilds/"&gt;@jamiebuilds﻿&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the left is the ES6 code, then you can see in the middle how much code is generated if you must support very old browsers. And the amount of code needed to support not-super-old browsers to the right.&lt;/p&gt;

&lt;p&gt;The amount of code needed to support old legacy browsers in this example is extreme.&lt;/p&gt;

&lt;p&gt;So if you only use the default babel-preset-env you might end up in a bloated bundle. What can we do about this?&lt;/p&gt;

&lt;p&gt;It would be nice if there were a way to tell Babel to not use &lt;em&gt;all&lt;/em&gt; plugins, but only a subset of plugins that you &lt;em&gt;really&lt;/em&gt; need. That way less of your code gets transpiled to bloated ES5 code.&lt;/p&gt;

&lt;p&gt;If you read my &lt;a href="http://blog.jakoblind.no/babel-webpack-es6/"&gt;previous&lt;/a&gt; post on this subject, you learned that most modern browsers already support most ES6 features. If you look at Google analytics for your site you might realize that 99% are on modern browsers. So maybe you don't have to support &lt;em&gt;all&lt;/em&gt; old browsers that have ever existed.&lt;/p&gt;

&lt;p&gt;When you have made a decision on what browsers you want to support, you can tell babel exactly what browsers you should support with babel-preset-env. You do that with the config file called &lt;em&gt;.browserlistrc&lt;/em&gt; which is part of a &lt;a href="https://github.com/browserslist/browserslist"&gt;standard&lt;/a&gt; that defines what browsers your app supports. Babel-preset-env reads from this config file.&lt;/p&gt;

&lt;p&gt;You can, for example, say you don't support IE by adding the following to your &lt;em&gt;.browserlistrc&lt;/em&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;not ie all
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;or that you define that you only support browsers with a market share of 0.25% or more:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;0.25%
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you describe to babel-preset-env what browsers you support, it can use less plugins, and that means less unneeded code.&lt;/p&gt;

&lt;h2&gt;
  
  
  How should my browserconfig look like?
&lt;/h2&gt;

&lt;p&gt;Read your Google Analytics stats (or whatever tool you are using) to get an impression of what browsers your users are using, then use the &lt;a href="https://github.com/browserslist/browserslist"&gt;browerlist&lt;/a&gt;&lt;a href="https://github.com/browserslist/browserslist"&gt; docs&lt;/a&gt; to compose your configuration.&lt;/p&gt;

&lt;p&gt;If you don't use Google Analytics then a good default can be to support all browsers with a market share of 0.25% or higher like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;0.25%
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Using "last 2 versions" is &lt;a href="https://jamie.build/last-2-versions"&gt;not&lt;/a&gt; recommended.&lt;/p&gt;

&lt;p&gt;You can get a list of all browsers supported by your browserlist config by running following command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx browserslist
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It will list all browsers in the console.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next step is to learn how to configure webpack
&lt;/h2&gt;

&lt;p&gt;As I mentioned earlier, the most common way to use Babel is with webpack. So now that you know how babel works, a natural next step is to start looking into webpack.&lt;/p&gt;

&lt;p&gt;I have created an email course that gives you one email per day that will only take a few minutes to read. After five days you have learned how to build a complete production ready webpack app. Get access today by &lt;a href="https://pages.convertkit.com/8eeb9f21b0/26777fab4c"&gt;signing up&lt;/a&gt;. It's free!&lt;/p&gt;

&lt;p&gt;→→&lt;a href="https://pages.convertkit.com/8eeb9f21b0/26777fab4c"&gt;Free webpack email course&lt;/a&gt; ←←&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>babel</category>
      <category>webpack</category>
    </item>
    <item>
      <title>How to build a large React application</title>
      <dc:creator>Jakob Lind</dc:creator>
      <pubDate>Fri, 01 Sep 2017 05:24:08 +0000</pubDate>
      <link>https://dev.to/jakoblind/how-to-build-a-large-react-application</link>
      <guid>https://dev.to/jakoblind/how-to-build-a-large-react-application</guid>
      <description>&lt;p&gt;You have a vision for your next big application. It’s a SPA with many routes. It should handle authentication and registration. A nice UI with animations. And it should communicate with external and internal APIs.&lt;/p&gt;

&lt;p&gt;Then you think to yourself: Where do I start? Is there a tutorial I can use that describes how to code this app?&lt;/p&gt;

&lt;p&gt;It’s difficult to find such extensive tutorial. Even if you find a tutorial which shows you how to build a large app, it’s unlikely it will teach you to build an app that is exactly like yours.&lt;/p&gt;

&lt;p&gt;You need a process to build it yourself.&lt;/p&gt;

&lt;h1&gt;
  
  
  Break it down to tasks
&lt;/h1&gt;

&lt;p&gt;To succeed building your large application, you must take control over it. The way you do that is by breaking it down into smaller and more manageable tasks. This is an example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a “hello world react app&lt;/li&gt;
&lt;li&gt;Add forms&lt;/li&gt;
&lt;li&gt;Add a /dashboard page&lt;/li&gt;
&lt;li&gt;Add a backend for handling API requests&lt;/li&gt;
&lt;li&gt;Where to persist data, DB or SaaS such as Firebase?&lt;/li&gt;
&lt;li&gt;Where to host the app?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You don’t need to do this perfectly. Don’t spend too much time on this exercise, 10 min max. The reason is not to create “todos for everything, but to realize your app is not a big monster. It consists of small tasks that are completely possible to finish.&lt;/p&gt;

&lt;p&gt;You will be able to code some of the tasks without learning anything new. And some of the tasks will require researching to learn how to solve it.&lt;/p&gt;

&lt;p&gt;Some of the tasks might be questions that you need to answer, for example, “where to persist data?”. You don’t need to answer all those questions in advance. You will answer them when you decide to implement the task. You don’t want to overwhelm yourself by doing all research upfront.&lt;/p&gt;

&lt;h1&gt;
  
  
  Keep it simple
&lt;/h1&gt;

&lt;p&gt;When you pick a task to start work on you only have to solve a small well-defined task. If you don’t know how to solve it, you have to do some googling. Most likely you are going to find a lot of different solutions and many opinions on how to resolve the task. It’s easy to spend hours reading blog post after blog post even about minor details. Time quickly gets wasted.&lt;/p&gt;

&lt;p&gt;To keep your focus and not be overwhelmed you must use a guiding principle: &lt;strong&gt;&lt;em&gt;“what is the most simple thing I can do?”&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is so important that I am going to repeat it for you:&lt;/p&gt;

&lt;p&gt;Your guiding principle when solving tasks is &lt;strong&gt;&lt;em&gt;“what is the most simple thing I can do?”&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is so easy to get distracted away from this. There are so many smart solutions out there. But those smart solutions are not that smart when they distract you from reaching your goal.&lt;/p&gt;

&lt;p&gt;You will require more advanced solutions when you need to scale up the code base. But not now.&lt;/p&gt;

&lt;p&gt;This approach to software development applies both for hobby projects and most production applications.&lt;/p&gt;

&lt;h1&gt;
  
  
  Don’t overthink
&lt;/h1&gt;

&lt;p&gt;You might read about Presentational/Container pattern, Higher order components, and other best practices. You start to lay out your architecture and you want to take the patterns into consideration.&lt;/p&gt;

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

&lt;p&gt;Learning best practices and setting an architecture at the same time will almost guarantee you to get stuck.&lt;/p&gt;

&lt;p&gt;Your approach should be different: &lt;strong&gt;&lt;em&gt;Only add stuff when you have felt the pain of not having it.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With the stuff I mean:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Best practices&lt;/li&gt;
&lt;li&gt;Libraries&lt;/li&gt;
&lt;li&gt;Programming patterns&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When your application grows you need to continuously revisit your code and think about how you can improve it. When you feel pain, improve your code base and reduce technical debt.&lt;/p&gt;

&lt;h1&gt;
  
  
  But am I ready for X?
&lt;/h1&gt;

&lt;p&gt;If you are new to the React ecosystem you might have gotten the advice to start with React, and only move over to Redux when you are ready. But how do you know when you are ready? And how do you know when you are ready for other “advanced technology such as routing, authentication, Ajax calls, etc?&lt;/p&gt;

&lt;p&gt;If you are using the approach “start small, and only add tech when you feel the pain you don’t have to think about if you are ready or not. If you feel the pain, you know what kind of library/tool you need. And if you start small and simple, you will not get overwhelmed.&lt;/p&gt;

&lt;p&gt;Stop thinking about you and think about the app you are building.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;When you want to build a large application there are many things that can overwhelm you. Your own application can overwhelm you, and the React ecosystem can overwhelm you.&lt;/p&gt;

&lt;p&gt;That’s why it’s important to have a process to take back control. To make it manageable you have to make it simple.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>productivity</category>
      <category>architecture</category>
    </item>
    <item>
      <title>4 questions to ask yourself when you get stuck</title>
      <dc:creator>Jakob Lind</dc:creator>
      <pubDate>Tue, 04 Jul 2017 11:03:12 +0000</pubDate>
      <link>https://dev.to/jakoblind/4-questions-to-ask-yourself-when-you-get-stuck</link>
      <guid>https://dev.to/jakoblind/4-questions-to-ask-yourself-when-you-get-stuck</guid>
      <description>&lt;p&gt;Hi, I wrote this article with React developers in mind, but it applies to all kinds of languages and libraries! Enjoy!&lt;/p&gt;




&lt;p&gt;Take a look at these common questions and answers:&lt;/p&gt;

&lt;p&gt;Q: Where should I put my state?&lt;br&gt;
A: &lt;em&gt;2 options for putting it in React components. Or use Redux. Or Mobx. Or…&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Q: Where should I put my logic?&lt;br&gt;
A: &lt;em&gt;Container components or actions creators or util libs or…&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Q: How should I do testing?&lt;br&gt;
A: &lt;em&gt;You have 5 options for assertions, 4 for stubs, 3 for spies, 4 test runners…&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;See the pattern? For every problem you have a list of several idiomatic ways to solve the problem.&lt;/p&gt;

&lt;p&gt;Which solution should you pick? Ideally you want just the one idiomatic way to solve your problem, but instead you get a long list of options without guidance on when to choose which one.&lt;/p&gt;

&lt;p&gt;So you get confused. And then you get stuck.&lt;/p&gt;

&lt;p&gt;And sometimes there doesn’t even exist an idiomatic way to solve the problems you are having. Even though they are common problems.&lt;/p&gt;

&lt;p&gt;“What file structure should I use? &lt;em&gt;Do what you want.&lt;/em&gt;&lt;br&gt;
“What is the minimum set of tools I need? &lt;em&gt;It depends…&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That doesn’t help either…&lt;/p&gt;

&lt;p&gt;All we want is one clear and simple by-the-book solution. But in the React ecosystem there isn’t one, so what should we do?&lt;/p&gt;

&lt;p&gt;Give up?&lt;/p&gt;

&lt;h1&gt;
  
  
  The question you ask yourself is important
&lt;/h1&gt;

&lt;p&gt;So when you run into a problem you ask yourself the question &lt;em&gt;“What’s the most correct/idiomatic way to solve this problem?“.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That question can many times help you solve the problem you have, or lead you in the right direction. But it can also be leading to more confusion than clarity.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"Judge a man by his questions rather than by his answers." – Voltaire&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The real world is complex, and finding a suitable solution requires that you look at the problem from more than one angle.&lt;/p&gt;

&lt;p&gt;The way you do that is asking many kinds of questions. Here are some examples:&lt;/p&gt;

&lt;h2&gt;
  
  
  1. “What’s the simplest thing I can do?”
&lt;/h2&gt;

&lt;p&gt;Sometimes it is necessary to create Redux Store and Actions with Thunk Middleware to do Ajax requests.&lt;/p&gt;

&lt;p&gt;And sometimes a 4 line HTML form tag is enough.&lt;/p&gt;

&lt;p&gt;Don’t always reach for the “correct and fancy solution, but pause and reflect on what is the simplest thing you can implement to solve your problem. A simple solution is more maintainable, less risk for bugs, and usually most elegant. And also quickest to implement.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. “What kind of problem am I trying to solve?”
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Performance problem?&lt;/li&gt;
&lt;li&gt;A feature where time to market is critical?&lt;/li&gt;
&lt;li&gt;Is it a proof of concept?&lt;/li&gt;
&lt;li&gt;Internal tool?&lt;/li&gt;
&lt;li&gt;For learning?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If learning is the goal, you might want to write two or three different implementations of the same feature just to explore and compare. If time to market is important, you might go for the quickest implementation, even if it’s “wrong”.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. “What level of competency does my teammates have?”
&lt;/h2&gt;

&lt;p&gt;Many juniors? Seniors only? If you will recruit more devs, what are their profile? These are the really important question to take into consideration because it says something about the level of “smartness and room for creativity you will allow the codebase to have.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. “Can I make a decision now, and revisit later?”
&lt;/h2&gt;

&lt;p&gt;There are circumstances where the best thing to do is make a good enough solution, and revisit it later. If you think you are going to make it perfect on the first try, there is a risk you over engineer and as a consequence make the code more complicated than it has to be.&lt;/p&gt;

&lt;p&gt;You don’t yet know how the code base will develop. Maybe that piece of code wouldn’t grow as big as you thought. And maybe the feature gets removed from the product completely in a month. (has happened to me many times)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Use this question with caution!&lt;/em&gt; You don’t want to throw in a lot of quick fixes all over the place. There is a balance.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Every application is unique, and going for generalized solutions is not always the best approach. To find the best solution for the problems in your application requires you to think further than the official documentation and tutorials.&lt;/p&gt;

&lt;p&gt;Now you have a tool which takes into consideration many variables to find specialized solutions which will lead to more readable and more maintainable code.&lt;/p&gt;

&lt;p&gt;And hopefully in the end more happy end users!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to become a more productive React Developer</title>
      <dc:creator>Jakob Lind</dc:creator>
      <pubDate>Mon, 26 Jun 2017 06:04:25 +0000</pubDate>
      <link>https://dev.to/jakoblind/how-to-become-a-more-productive-react-developer</link>
      <guid>https://dev.to/jakoblind/how-to-become-a-more-productive-react-developer</guid>
      <description>&lt;p&gt;Developing complex React applications is… well, complex. You need to keep many things in your head at the same time, and it’s super easy to get distracted and lose focus.&lt;/p&gt;

&lt;p&gt;There are powerful tools to help you stay in the flow, and make you more productive. In this post, I have gathered the “must-haves”.&lt;/p&gt;

&lt;h1&gt;
  
  
  Automatic code formatter: prettier
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://github.com/prettier/prettier" rel="noopener noreferrer"&gt;Prettier&lt;/a&gt; is an opinionated code formatter for JavaScript. You don’t need to think about indenting the code and adding new lines at the correct places – prettier does it automatically for you.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fblog.jakoblind.no%2Fwp-content%2Fuploads%2F2017%2F06%2FScreenshot-from-2017-06-09-08-03-53.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/http%3A%2F%2Fblog.jakoblind.no%2Fwp-content%2Fuploads%2F2017%2F06%2FScreenshot-from-2017-06-09-08-03-53.png" alt="Before prettier to the left, and after to the right"&gt;&lt;/a&gt; &lt;em&gt;Before prettier to the left, and after to the right&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;“But wait a minute, my IDE already does that?”&lt;/p&gt;

&lt;p&gt;Yes, but prettier works fundamentally different: It parses the JavaScript into an Abstract Syntax Tree (AST) and pretty prints the AST, &lt;strong&gt;completely ignoring the original formatting&lt;/strong&gt;. This makes it much “smarter” and consistently produces a better result.&lt;/p&gt;

&lt;p&gt;Prettier has excellent support for React and the &lt;a href="https://twitter.com/dan_abramov/status/871420769947049984" rel="noopener noreferrer"&gt;official&lt;/a&gt; recommendation from Facebook is to use it.&lt;/p&gt;

&lt;p&gt;You can get started without doing any configuration. You can play around with it yourself to see how it works here: &lt;a href="https://prettier.github.io/prettier/" rel="noopener noreferrer"&gt;https://prettier.github.io/prettier/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I suggest adding a keybinding in your editor for easy access when developing. There are &lt;a href="https://github.com/prettier/prettier#editor-integration" rel="noopener noreferrer"&gt;plugins&lt;/a&gt; for most popular editors.&lt;/p&gt;
&lt;h1&gt;
  
  
  Errors and warnings in the editor: eslint
&lt;/h1&gt;

&lt;p&gt;&lt;a href="http://eslint.org/" rel="noopener noreferrer"&gt;Eslint&lt;/a&gt; is a linting utility for Javascript. You can use it to show errors and warnings straight in your editor and it can even fix those errors/warnings automatically. You can configure it from scratch or use an existing config and tweak it. Many people like to start with the &lt;a href="https://www.npmjs.com/package/eslint-config-airbnb" rel="noopener noreferrer"&gt;airbnb eslint config&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fblog.jakoblind.no%2Fwp-content%2Fuploads%2F2017%2F06%2FScreenshot-from-2017-06-09-07-59-31.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/http%3A%2F%2Fblog.jakoblind.no%2Fwp-content%2Fuploads%2F2017%2F06%2FScreenshot-from-2017-06-09-07-59-31.png" alt="Eslint in Emacs: warnings in yellow underline and errors with red."&gt;&lt;/a&gt; &lt;em&gt;Eslint in Emacs: warnings in yellow underline and errors with red.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Eslint works perfectly fine together with prettier and there are editor plugins for most &lt;a href="http://eslint.org/docs/user-guide/integrations" rel="noopener noreferrer"&gt;popular editors&lt;/a&gt;.&lt;/p&gt;
&lt;h1&gt;
  
  
  DevTools for React/Redux as Browser plugins
&lt;/h1&gt;

&lt;p&gt;There are developer plugins for both Chrome and Firefox:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi" rel="noopener noreferrer"&gt;React Developer Tools for Chrome&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd" rel="noopener noreferrer"&gt;Redux DevTools for Chrome&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://addons.mozilla.org/en-us/firefox/addon/react-devtools/" rel="noopener noreferrer"&gt;React Developer Tools for Firefox&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://addons.mozilla.org/en-US/firefox/addon/remotedev/" rel="noopener noreferrer"&gt;Redux Devtools for Firefox&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It adds itself as a new tab in the “inspect element” area that you most likely are very familiar with:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fblog.jakoblind.no%2Fwp-content%2Fuploads%2F2017%2F06%2FScreenshot-from-2017-06-07-12-49-13.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/http%3A%2F%2Fblog.jakoblind.no%2Fwp-content%2Fuploads%2F2017%2F06%2FScreenshot-from-2017-06-07-12-49-13.png" alt="React devtools"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From there you can inspect all your components visually and for each component you can see the props and state. Very convenient!&lt;/p&gt;

&lt;p&gt;Both React and Redux devtools are a must haves if you are a React/Redux developer.&lt;/p&gt;

&lt;p&gt;So what can you do with them? I use them for mainly two things: debugging and inspecting data.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to debug with Devtools
&lt;/h2&gt;

&lt;p&gt;Let’s say you have written a Redux Action/Reducer and you have &lt;code&gt;connect()&lt;/code&gt;  the React component to the store. You expect something to change in your component when you click a button. Your bug is that nothing happens when you click the button.&lt;/p&gt;

&lt;p&gt;A way to debug this is to follow the Redux flow with the devtools in your browser:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The first thing to check is if the action is dispatched from the action creator or not. You can see exactly what actions are dispatched in the Redux devtools.&lt;/li&gt;
&lt;li&gt;If the action is dispatched correctly next step is to check if the reducer updates the state correctly. Again check the diff of the state in the Redux devtools.&lt;/li&gt;
&lt;li&gt;If the state was updated correctly we move on to check if the React component receives the data in it’s props. This info is available in the React devtool.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You no longer need to throw &lt;code&gt;console.logs&lt;/code&gt;  around to understand what is happening. Instead you follow the flow of data in the browser with the devtools!&lt;/p&gt;
&lt;h2&gt;
  
  
  Inspecting data
&lt;/h2&gt;

&lt;p&gt;Another great use case for the devtools is when you need to check how the data structure looks like in the props and the state of your components. An example is the following component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person extends React.Component {
  render() {
    return (
      &amp;lt;div&amp;gt;
        &amp;lt;p&amp;gt;Name is {this.props.person.name}&amp;lt;/p&amp;gt;
        &amp;lt;p&amp;gt;Age is {this.props.person.age}&amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s say you need to display more information about the person.  Then you need to know how the data structure &lt;code&gt;this.props.person&lt;/code&gt; looks like. How will you do that?&lt;/p&gt;

&lt;p&gt;Easy, Take a look at real data in the devtools.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fblog.jakoblind.no%2Fwp-content%2Fuploads%2F2017%2F06%2FScreenshot-from-2017-06-09-07-58-12.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/http%3A%2F%2Fblog.jakoblind.no%2Fwp-content%2Fuploads%2F2017%2F06%2FScreenshot-from-2017-06-09-07-58-12.png" alt="Inspect data with React devtools"&gt;&lt;/a&gt;&lt;br&gt;
We can see that it also has city and occupation we can use!&lt;/p&gt;

&lt;h1&gt;
  
  
  React Hot Loader
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://github.com/gaearon/react-hot-loader" rel="noopener noreferrer"&gt;React Hot Loader&lt;/a&gt; (RHL) does live reloading of your code. That means that when you have saved after edited your code, your browser will automatically get the new changes without you having to manually reload. And the best part is that you will not loose your Redux state like you do when you do a manual refresh of the web page.&lt;/p&gt;

&lt;p&gt;I want to admit that RHL is not perfect. Sometimes it cannot do the hot reload and you have to do a manual reload anyway.&lt;/p&gt;

&lt;h2&gt;
  
  
  What can I do with it?
&lt;/h2&gt;

&lt;p&gt;In addition to use it for coding client side JavaScript, CSS is a great use case (requires that you have CSS in JS). When working with CSS it is often a lot back and forth adjusting pixels and colors. Many people do the tweaking in the developer tools in the browser. The only downside with that strategy is you have to replicate your changes to your code if you are happy with your changes. And if you do many changes, it can be a bit tricky to get everything correctly.&lt;/p&gt;

&lt;p&gt;When using RHL, you can do the editing of your CSS straight in your own code and still get the live changes in the browser. When you are done you don’t have to do anything more than commit your code to git!&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;There are many great tools and technology out there that remove distractions and automate repetitive tasks so you can focus on delivering value. Use them! It will significantly speed up your development speed!&lt;/p&gt;

</description>
      <category>react</category>
      <category>redux</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
