<?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: Arkadii Berezkin</title>
    <description>The latest articles on DEV Community by Arkadii Berezkin (@aberezkin).</description>
    <link>https://dev.to/aberezkin</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%2F28500%2Fd144c87e-226f-46ef-9017-48782169d966.jpeg</url>
      <title>DEV Community: Arkadii Berezkin</title>
      <link>https://dev.to/aberezkin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aberezkin"/>
    <language>en</language>
    <item>
      <title>React. The key points.</title>
      <dc:creator>Arkadii Berezkin</dc:creator>
      <pubDate>Thu, 15 Mar 2018 08:11:49 +0000</pubDate>
      <link>https://dev.to/aberezkin/react-the-key-points--4h83</link>
      <guid>https://dev.to/aberezkin/react-the-key-points--4h83</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flogos-download.com%2Fwp-content%2Fuploads%2F2016%2F09%2FReact_logo_wordmark.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flogos-download.com%2Fwp-content%2Fuploads%2F2016%2F09%2FReact_logo_wordmark.png" alt="React logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  TL;DR
&lt;/h1&gt;

&lt;p&gt;In this post, I'm talking about what I think are the key points of React. These are facts that I would happy to know while learning about the (spoiler alert) library.&lt;/p&gt;

&lt;p&gt;By the way, it's my first post on dev.to. Hope you'll like it!&lt;/p&gt;




&lt;h1&gt;
  
  
  It's not a framework
&lt;/h1&gt;

&lt;p&gt;React has cool features, huge and active community and even its own javascript syntax! These facts can trick you into thinking that React is a framework. But it's not. As I spoiled before it's just a library.&lt;/p&gt;

&lt;p&gt;Usually, a framework can provide you with everything you need to build an application. Look at angular, for example, it has so many features. View rendering, HTTP interaction, animations, form validation, you can find all of these in angular. React does only one of these - view rendering, and it does it pretty damn well.&lt;/p&gt;

&lt;p&gt;Anything that is not about rendering a view is not a Reacts responsibility. Even if you want to render some part of an application using other tools, React is okay with that.&lt;/p&gt;

&lt;p&gt;Every tool in software development has its cost. A Framework gives you more features for a greater cost. But despite its great features, the cost of React is relatively small. And I think that's why it's so popular. You can use it to render just one page or even just some component of your app. You don't need to pause feature development to migrate your whole app to React. If you think that react can do the job better, give it a try and implement just one component with React. React does give you this flexibility.&lt;/p&gt;

&lt;h1&gt;
  
  
  It embraces javascript
&lt;/h1&gt;

&lt;p&gt;This is also a good part of React not being a framework. Yeah, there is an additional syntax in JSX but this is just a syntactic sugar, unlike in Typescript which introduces new features like static typing to Javascript. The JSX code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;Title&lt;/span&gt; &lt;span class="na"&gt;large&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"darkgray"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  Hello, World!
&lt;span class="nt"&gt;&amp;lt;/Title&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;simply compiles into&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;Title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;large&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;darkgray&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&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's all.&lt;/p&gt;

&lt;p&gt;Furthermore, it's still possible to write code for React components using pure Javascript but it's just not practical. Developers at Facebook could have developed much more features into JSX, but these would be just bells and whistles. Instead of that, React tries to make a developer use javascript as is and encourages one to find out and use the best practices.&lt;/p&gt;

&lt;p&gt;It's also good news for javascript beginners. A developer learning React also learns vanilla Javascript and more flexible than developer learning Angular + Typescript. I myself learned Angular at first and then switched to React so I know what I'm talking about.&lt;/p&gt;

&lt;h1&gt;
  
  
  Logic is fully your responsibility
&lt;/h1&gt;

&lt;p&gt;As I said before React doesn't care about anything that's not rendering views. Despite the fact that many React apps are built in conjunction with Redux, nobody forces developers to do so. It's just a convenient way to build data flows in an app.&lt;/p&gt;

&lt;p&gt;Components just need to get data to show as props. Where do you find it? None of their business.&lt;/p&gt;

&lt;h1&gt;
  
  
  It's declarative
&lt;/h1&gt;

&lt;p&gt;At this point, you can think. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If React is so small and does so few, why everybody think that it's so great?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Yes, react is small yet powerful. But it gains its powers not from many features but from great (and at first glance pretty sophisticated) paradigms. One of them is &lt;strong&gt;declarative programming&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To keep it short, in the declarative paradigm you describe &lt;strong&gt;what&lt;/strong&gt; program should do, not &lt;strong&gt;how&lt;/strong&gt; to do it. The way a developer describes a components view in React is declarative. You &lt;strong&gt;declare&lt;/strong&gt; how a component should look with every possible set of props. &lt;/p&gt;

&lt;p&gt;For example, let's consider a simple checkbox-like component built with pure Javascript and React. &lt;/p&gt;

&lt;p&gt;Pure javascript version would look something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;onclick=&lt;/span&gt;&lt;span class="s"&gt;"check()"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Check&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;the flag is &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"not"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;not&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt; checked&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/javascript"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;checked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;notEl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;not&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;checked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;checked&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;notEl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;checked&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;not&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here you should directly &lt;strong&gt;mutate&lt;/strong&gt; the DOM. What's the problem with that? None, if there's only one node to mutate. But when app getting larger usually there is more than one mutation and that is when things become tricky. DOM mutations are hard to maintain, debug and test. And React is trying to tackle it (by not allowing mutations at all).&lt;/p&gt;

&lt;p&gt;Here's what it would look like in react.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;KindaCheckbox&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;onCheck&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;isChecked&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;onCheck&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Check&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;the flag is &lt;span class="si"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;isChecked&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;not&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="si"&gt;}&lt;/span&gt; checked&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// these 2 lines are not best practices don't write code like that&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;isChecked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;onCheck&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;isChecked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isChecked&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;KindaCheckbox&lt;/span&gt; &lt;span class="na"&gt;onCheck&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;onCheck&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;isChecked&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isChecked&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;,&lt;/span&gt; 
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&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;This may seem a bit complicated but the core idea is that you describe how your view should look at any moment in time no matter if the flag is checked or not. In other words, you declare &lt;strong&gt;what&lt;/strong&gt; to show not &lt;strong&gt;how&lt;/strong&gt; to &lt;strong&gt;mutate&lt;/strong&gt; over time. And now you can focus on working with data, not with DOM. &lt;/p&gt;

&lt;p&gt;And that's why developers are freaking love it. Programming is not about moving divs around a web page it's about working with data! And React lets you forget about maintaining DOM and just do your job.&lt;/p&gt;




&lt;h1&gt;
  
  
  Wrapping up
&lt;/h1&gt;

&lt;p&gt;In my opinion, these are the most important considerations that you need to take into account before (or while) getting your hands on React. I hope these will help you to tackle the steep learning curve of React and build great applications using it.&lt;/p&gt;




&lt;p&gt;Frankly, I was going to write about 3-4 more key points but it looks like this post is getting big. I'm thinking about part 2. If you think this is a good idea drop me a line in comments or on Twitter.&lt;/p&gt;

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