<?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: tpostoliuk</title>
    <description>The latest articles on DEV Community by tpostoliuk (@tpostoliuk).</description>
    <link>https://dev.to/tpostoliuk</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%2F259114%2Ff84b5126-3870-4476-a091-0714a5b64b7a.jpg</url>
      <title>DEV Community: tpostoliuk</title>
      <link>https://dev.to/tpostoliuk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tpostoliuk"/>
    <language>en</language>
    <item>
      <title>Why do we have to write functional instead of class components?</title>
      <dc:creator>tpostoliuk</dc:creator>
      <pubDate>Fri, 14 Aug 2020 19:14:08 +0000</pubDate>
      <link>https://dev.to/tpostoliuk/why-do-we-have-to-write-functional-instead-of-class-components-522k</link>
      <guid>https://dev.to/tpostoliuk/why-do-we-have-to-write-functional-instead-of-class-components-522k</guid>
      <description>&lt;p&gt;Yo! Today we talk about nowadays of ReactJS. The front-end industry is growing up increasingly, and we have to get used to it and prepare for all changes in the programming that can happen.&lt;/p&gt;

&lt;p&gt;Recently, we write all ReactJS applications on class components. Now, we have React Hooks that provide our functional component, for example, with the state.&lt;br&gt;
Well, let's talk about the advantages of the functional components. Take a look at this small class that just handle change&lt;br&gt;
and render it.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5jnkvq1028wbbl1awc67.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F5jnkvq1028wbbl1awc67.png" alt="Class component" width="800" height="691"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It looks a bit great. Next, I rewrite this component to functional.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0zyvrcwjw3b5lylmmyrq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0zyvrcwjw3b5lylmmyrq.png" alt="Functional component" width="800" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, it is a small example, but even it shows us how functional components reduce code, and it is the first advantage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Functional components reduce approximately 25 percent of code that is in class components&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The second reason is that React is going to functional programming.&lt;/strong&gt;&lt;br&gt;
The official documentation says that it is good to&lt;br&gt;
practice using Hooks in new and non-critical components. It does not mean that class would not be supported in the future, it will.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The third reason is not to think about context.&lt;/strong&gt;&lt;br&gt;
If you write on class, you always thinking about how not to lose context and bind all methods. In the function, you can forget about it in most situations that can happen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The last reason is reusability.&lt;/strong&gt; In the function, you can reuse logic, for example, by creating a custom hook and reuse it in every component you want. In class, you can't do it, you must rewrite the whole component.&lt;/p&gt;

&lt;p&gt;So, I recommend you to write functional instead of class components.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>frontend</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What is actually CORS?</title>
      <dc:creator>tpostoliuk</dc:creator>
      <pubDate>Fri, 14 Aug 2020 09:19:06 +0000</pubDate>
      <link>https://dev.to/tpostoliuk/what-is-actually-cors-285h</link>
      <guid>https://dev.to/tpostoliuk/what-is-actually-cors-285h</guid>
      <description>&lt;p&gt;Probably you run into CORS trying to make some request, and don't even understand why it throws you an error in your console. In this post, i want to make it clear what is CORS. Let's begin.&lt;/p&gt;

&lt;p&gt;Cross-Origin-Resource-Sharing(CORS) - is just a mechanism that gives access to browser to download resource across domain boundaries. What does it mean? This means that browser restricts cross-origin HTTP request initiated from script for security reason. Fetch API and XMLHttpRequest follow the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy" rel="noopener noreferrer"&gt;same-origin policy&lt;/a&gt;. It means that unless the response from other origins has the right CORS headers you cannot download resource from origin other than application was loaded.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Here we have requests that use CORS:&lt;/strong&gt;
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Invocations of the XMLHttpRequest or Fetch APIs.&lt;/li&gt;
&lt;li&gt;Web Fonts (for cross-domain font usage in @font-face within CSS), so that servers can deploy TrueType fonts that can only be cross-site loaded and used by web sites that are permitted to do so.&lt;/li&gt;
&lt;li&gt;WebGL textures.&lt;/li&gt;
&lt;li&gt;Images/video frames drawn to a canvas using drawImage().&lt;/li&gt;
&lt;li&gt;CSS Shapes from images.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Accessible methods&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;There are "simple" requests that don't trigger CORS preflight. But this requests must follow all the conditions below:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;One of the allowed methods:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GET&lt;/li&gt;
&lt;li&gt;HEAD&lt;/li&gt;
&lt;li&gt;POST&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Apart from the headers automatically set by the user agent the only headers which are allowed to be manually set are those which the Fetch spec defines as a "CORS-safelisted request-header", which are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Accept&lt;/li&gt;
&lt;li&gt;Accept-Language&lt;/li&gt;
&lt;li&gt;Content-Language&lt;/li&gt;
&lt;li&gt;Content-Type (but note the additional requirements below)&lt;/li&gt;
&lt;li&gt;DPR&lt;/li&gt;
&lt;li&gt;Downlink&lt;/li&gt;
&lt;li&gt;Save-Data&lt;/li&gt;
&lt;li&gt;Viewport-Width&lt;/li&gt;
&lt;li&gt;Width&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The only allowed values for the Content-Type header are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;application/x-www-form-urlencoded &lt;/li&gt;
&lt;li&gt;multipart/form-data &lt;/li&gt;
&lt;li&gt;text/plain&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No event listeners are registered on any XMLHttpRequestUpload object used in the request; these are accessed using the XMLHttpRequest.upload property.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No ReadableStream object is used in the request.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Let's imagine a little dialog between server and client:
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Client: Hey server! Give me some data, please.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Server: Hi, firstly let me check if your request is &lt;br&gt;
      "simple" or not. If yes i'll give you data and list of &lt;br&gt;
allowed methods and allowed origins in response.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Client: Okay, no problem. Do your work.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For additional information thanks &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS" rel="noopener noreferrer"&gt;MDN&lt;/a&gt; and &lt;a href="https://en.wikipedia.org/wiki/Cross-origin_resource_sharing" rel="noopener noreferrer"&gt;Wikipedia&lt;/a&gt;&lt;/p&gt;

</description>
      <category>http</category>
      <category>webdev</category>
      <category>cors</category>
    </item>
  </channel>
</rss>
