<?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: Shivam Gupta</title>
    <description>The latest articles on DEV Community by Shivam Gupta (@shivambmgupta).</description>
    <link>https://dev.to/shivambmgupta</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%2F572097%2Fb2a03209-3ac9-4c7a-986f-5f73f197c659.jpeg</url>
      <title>DEV Community: Shivam Gupta</title>
      <link>https://dev.to/shivambmgupta</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shivambmgupta"/>
    <language>en</language>
    <item>
      <title>Best React Practices</title>
      <dc:creator>Shivam Gupta</dc:creator>
      <pubDate>Sat, 28 Aug 2021 19:02:01 +0000</pubDate>
      <link>https://dev.to/shivambmgupta/best-react-practices-bp8</link>
      <guid>https://dev.to/shivambmgupta/best-react-practices-bp8</guid>
      <description>&lt;p&gt;In this blog, I’d be explaining few best practices when working with React/React-Native or any other javascript application. Following are the guidelines will not only reduce the pitfalls but can also make your code more scalable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer: This is an opinionated guide. Decide what works for you and your team and stick with those policies.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s discuss these practices one by one.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;Testing, Typescript and Linting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing.
&lt;/h2&gt;

&lt;p&gt;That’s it! There I have said it. Test your WIP (Work In Progress) as much and strictly as you can. If your code is test passed, you are almost there. Do not bypass your work from the testing. Yes, I know you have already heard it like zillionth time but let me write the tools for testing for you.&lt;/p&gt;

&lt;h3&gt;
  
  
  Jest
&lt;/h3&gt;

&lt;p&gt;The javascript testing framework backed by Facebook, Inc. It is a de-facto standard when it comes to testing JavaScript applications. Works with the project using: Node, Typescript, React, Angular, Bable and more.&lt;/p&gt;

&lt;h3&gt;
  
  
  Enzyme and/or react-testing-library
&lt;/h3&gt;

&lt;p&gt;It is a powerful tool for Integration testing. Unit tests on their own don’t guarantee that your app will work even if those tests pass because the relationship between the units might be wrong. You should test different features with integration tests.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cypress
&lt;/h3&gt;

&lt;p&gt;Cypress is an end-to-end testing tool. It enables you to write unit tests and integration tests too. These tests are usually run on the entire application.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Fast, easy and reliable testing for anything that runs in a browser.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Linting.
&lt;/h2&gt;

&lt;p&gt;Your test passed codebase can still be a pain for the other developers. If a codebase does not follow strict coding standard guidelines — it will directly impact its scalability. Scalable code is as important as bug-free and tested code. ESLint lets you put uniform, standard coding guidelines. The project should follow one and only one standard protocol. For more details, please check my blog on ESLint.&lt;/p&gt;

&lt;h2&gt;
  
  
  Typescript.
&lt;/h2&gt;

&lt;p&gt;TypeScript is a strongly typed programming language that builds on JavaScript giving you better tooling at any scale. TypeScript adds additional syntax to JavaScript to support a tighter integration with your editor. Catch errors early in your editor. Using Typescript in trivial applications is often looked like little over the top. However, if your project is medium to large scale you should consider developing it in Typescript.&lt;/p&gt;

&lt;p&gt;While Typescripting, Testing and Linting cover the major part following are few other practices that you can follow:&lt;/p&gt;

&lt;h3&gt;
  
  
  Libraries
&lt;/h3&gt;

&lt;p&gt;With the npm, you have thousands of third party libraries at your hand that you can use. But you should be cautious of the third parties you are adding to your project. In general, the more third parties you add, the more control you lose over your project, the bulkier it gets. Here are few rules to help you out.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check how often the dependency gets updated or maintained. You can visit the Github repository and check the open issues and the recent activities.&lt;/li&gt;
&lt;li&gt;You can check the weekly downloads. It gives you a brief idea about the popularity of that dependency.&lt;/li&gt;
&lt;li&gt;Make sure the dependency you are adding is backed by the authentic contributor(s).&lt;/li&gt;
&lt;li&gt;You should also consider checking the unpacked size, last published date.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Strict CI/CD
&lt;/h3&gt;

&lt;p&gt;It is needless to say. You should set up the CI/CD that runs all the test cases, lint scripts. Feel free to set up the lenient CI/CD if you want bugs to enter in your production. Consider using Github actions or CircleCI. Every time someone merges or pushes their changes into the main branch there should be an action that runs all the test scenarios and lint scripts beforehand.&lt;/p&gt;

&lt;h3&gt;
  
  
  Comments
&lt;/h3&gt;

&lt;p&gt;Do you think your piece of code requires commenting for better understanding? Chances are, you are right. Write comments when and where it is necessary. However, you should consider few important things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Update your comment(s) when required.&lt;/li&gt;
&lt;li&gt;Feel free to mention Tickets ID for reference in the comment.&lt;/li&gt;
&lt;li&gt;Do not write unnecessary comments. For example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// assigning 10 to the x

let x = 10;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Code Refactoring &amp;amp; maintaining the docs
&lt;/h3&gt;

&lt;p&gt;They say that the first rule of programming is,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“dOn’T tOuCh If iT’s wOrKiNG!”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I don’t want to sound rude but, I do not believe this. I believe — improve it if it can be improved. Optimize if it can be optimised. With the luxury of having a version control system, I wouldn’t even mind experimenting with it. You should consider your codebase refactoring every once in a while. Monthly if not weekly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Contribute? Found a mistake?
&lt;/h2&gt;

&lt;p&gt;Feel free to connect with me, I’d love to hear from you! Thanks for reading.&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactnative</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Containment, Specialization and Inheritance in React-Native/React</title>
      <dc:creator>Shivam Gupta</dc:creator>
      <pubDate>Sat, 03 Jul 2021 17:37:00 +0000</pubDate>
      <link>https://dev.to/shivambmgupta/containment-specialization-and-inheritance-in-react-native-react-dlo</link>
      <guid>https://dev.to/shivambmgupta/containment-specialization-and-inheritance-in-react-native-react-dlo</guid>
      <description>&lt;p&gt;In this blog, I’m going to talk about Containment, Specialization and Inheritance in React-Native/React, the difference between them and how you can use them to reuse your code.&lt;/p&gt;

&lt;p&gt;First, while the examples shown below are related to react-native, the theory is also applicable to react. The concepts might help you to go DRY. Let’s discuss these points one by one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Containment
&lt;/h2&gt;

&lt;p&gt;When you wrap your component(s) within a higher-order component, it’s a containment. Some components don’t know their children ahead of time. Some common cases are Sidebar, Dialog. And for the sake of reusability, some components better be generic.&lt;/p&gt;

&lt;p&gt;The following problem can make this clear:&lt;/p&gt;

&lt;h3&gt;
  
  
  Problem Statement:
&lt;/h3&gt;

&lt;p&gt;We have a table of n rows and two columns. The columns can hold not just the text but any other JSX component (Button, Image, Icon) too. &lt;strong&gt;However, it’s is known that it’s going to be a text for 80% of the time&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Solution:
&lt;/h3&gt;

&lt;p&gt;React containment model can be useful in these cases.&lt;br&gt;
The idea is to create a wrapper — GenericRow that can hold any JSX component. Furthermore, we can create a CustomRow for Text component only. This is also called Specialization. Yes, I know that I’ve been talking a lot, so let me write the code for you:&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="cm"&gt;/* Generic Row that doesn’t know about its children */&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;GenericRow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;View&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="cm"&gt;/* Left column or Left child */&lt;/span&gt;
   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;View&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;column&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;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/View&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
   &lt;span class="cm"&gt;/* Right column or Right child */&lt;/span&gt;    
   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;View&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;column&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;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/View&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/View&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * Specialization of our Generic Row
 * This component is going to be used when it’s known that left and right are texts
 **/&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CustomRow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Generic&lt;/span&gt;
   &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="cm"&gt;/* Left child */&lt;/span&gt;
   &lt;span class="nx"&gt;left&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;lt;&lt;/span&gt;&lt;span class="nx"&gt;Text&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;left&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Text&amp;gt; &lt;/span&gt;&lt;span class="err"&gt;}
&lt;/span&gt;   &lt;span class="cm"&gt;/* Right Child */&lt;/span&gt;
   &lt;span class="nx"&gt;right&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;lt;&lt;/span&gt;&lt;span class="nx"&gt;Text&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;right&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Text&amp;gt; &lt;/span&gt;&lt;span class="err"&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="cm"&gt;/* Child of CustomRow | First Row */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;NameRow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;CustomRow&lt;/span&gt; &lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Developer’s Name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Shivam Gupta&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cm"&gt;/* Second Row for the age */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;AgeRow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;CustomRow&lt;/span&gt; &lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Age&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;22&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/* Action: Connect | Third row */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ConnectActionRow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&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="cm"&gt;/* Notice Generic Row not a CustomRow! */&lt;/span&gt;
 &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;GenericRow&lt;/span&gt; &lt;span class="nx"&gt;left&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;lt;&lt;/span&gt;&lt;span class="nx"&gt;Text&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Connect&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Text&amp;gt; } right = {&amp;lt;Button title="Hit me!" /&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, CustomRow is a specialization of the GenericRow which is going to be used frequently as per the problem statement. Notice that the ConnectActionRow component is contained by the GenericRow and not by the CustomRow, unlike the NameRow and AgeRow.&lt;/p&gt;

&lt;p&gt;Just using concepts of containment, we have the code which is easier to read, debug and maintain.&lt;/p&gt;

&lt;p&gt;Now let’s talk about specialization.&lt;/p&gt;

&lt;h2&gt;
  
  
  Specialization:
&lt;/h2&gt;

&lt;p&gt;Sometimes a component is a special case of the other component. For example, Error Text (traditionally, bold and red) is a special case of Text.&lt;/p&gt;

&lt;p&gt;The following problem will help you understand this better.&lt;/p&gt;

&lt;h3&gt;
  
  
  Problem Statement:
&lt;/h3&gt;

&lt;p&gt;You’re creating a medium-sized non-trivial react-native application that is going to have 20 screens. You require to prompt the danger text (for validation error) on at least 7 to 8 screens.&lt;/p&gt;

&lt;h3&gt;
  
  
  Solution:
&lt;/h3&gt;

&lt;p&gt;You’ll create a separate component for it. Of course! Any sane developer would do that. If that’s the case you already know about Specialization. For beginners, let me just write a code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;fontFamily&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;style&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="cm"&gt;/* User may overwrite the color, or fontWeight using his own style. */&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Text&lt;/span&gt; 
      &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{[&lt;/span&gt;
         &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;red&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;fontWeight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bold&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; 
         &lt;span class="cm"&gt;/* Notice this written after the our style, letting user to overwrite color and fontWeight. */&lt;/span&gt;
         &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;]}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Text&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again, the idea for this implementation is to use the DRY principle and at the same time allow the user of this component to overwrite our default stying whenever the developer wants.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inheritance
&lt;/h2&gt;

&lt;p&gt;React neither prefers nor does provide anything much for inheritance. Most of the time, you’re not going to need it. Whatever you could do using inheritance, you can achieve the same using Containment or Specialization. The following is the statement from the react’s official documentation:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“At Facebook, we use React in thousands of components, and we haven’t found any use cases where we would recommend creating component inheritance hierarchies.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Difference between Containment, Specialization and Inheritance
&lt;/h2&gt;

&lt;p&gt;While Containment, Speicializtion and Inheritance may sound similar but they are very different. The following may help you understand it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The table CONTAINS/HAS rows.
   &lt;em&gt;Neither table is a specialization of rows, nor it’s an inheritance.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Pulsar IS a Bike.
   &lt;em&gt;Neither this is an example of containment nor specialization.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Welcome Dialog is a special case of Dialog.
   &lt;em&gt;Neither this is an example of containment nor inheritance.&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The difference between containment and inheritance is of IS/HAS relationship.&lt;/p&gt;

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

&lt;p&gt;The main objective of the containment and specialization concept is to follow the DRY (Don’t Repeat Yourself) principle. Because redundant code is hard to maintain, harder to debug and using these concepts will make your code maintainable and less error-prone.&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>react</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>ESLint: What, Why, When, How</title>
      <dc:creator>Shivam Gupta</dc:creator>
      <pubDate>Sat, 19 Jun 2021 18:26:41 +0000</pubDate>
      <link>https://dev.to/shivambmgupta/eslint-what-why-when-how-5f1d</link>
      <guid>https://dev.to/shivambmgupta/eslint-what-why-when-how-5f1d</guid>
      <description>&lt;h2&gt;
  
  
  What is ESLint?
&lt;/h2&gt;

&lt;p&gt;ESLint is an open-source Javascript linting utility originally created by Nicholas C. Zakas in June 2013. It is frequently used to find problematic patterns or code that doesn’t adhere to certain style guidelines. ESLint is written using Node.js to provide a fast runtime environment and easy installation via npm.&lt;br&gt;
With ESLint you can impose the coding standard using a certain set of standalone rules. Yes, you can turn those rules on and off. These rules are completely pluggable.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why use ESLint?
&lt;/h2&gt;

&lt;p&gt;JavaScript, being a dynamic and loosely-typed language, is especially prone to developer error. ESLint lets you put guidelines over coding standard and helps you to minimize those errors. The main reason for imposing those guide is because every developer has her style of writing (like naming conventions/tabs/single or double quotes for a string). And, with different styling techniques, your codebase may look weird, more error-prone and vulnerable. Especially when you’re dealing with Javascript this could cause pitfalls you’d never want to deal with.&lt;/p&gt;
&lt;h2&gt;
  
  
  When to use it?
&lt;/h2&gt;

&lt;p&gt;Honestly, I prefer to use it no matter the project size or the team. But you should consider having it for any medium to large-scaled non-trivial Javascript/Typescript project or/and you’ve got quite a team of developers to deal with. In either case, you have to impose common, standard coding practice/guidelines.&lt;br&gt;
Linting tools like ESLint allow developers to discover problems with their JavaScript code without executing it. One of the main the reason for ESLint was created was to allow developers to create their own linting rules. You can use ESLint in any application that runs on Javascript/Typescript:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;React/React Native&lt;/li&gt;
&lt;li&gt;Angular&lt;/li&gt;
&lt;li&gt;Node.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  How to use it?
&lt;/h2&gt;

&lt;p&gt;Enough talk, eh? Here’s how you can install it.&lt;/p&gt;
&lt;h3&gt;
  
  
  Install it
&lt;/h3&gt;

&lt;p&gt;Prerequisites: Node.js &lt;code&gt;(^10.12.0, or &amp;gt;=12.0.0)&lt;/code&gt;&lt;br&gt;
You can install ESLint using &lt;code&gt;npm&lt;/code&gt; or &lt;code&gt;yarn&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install eslint --save-dev
# or
$ yarn add eslint --dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: It is also possible to install ESLint globally rather than locally (using &lt;code&gt;npm install eslint --global&lt;/code&gt;). However, this is NOT recommended, and any plugins or shareable configs that you use must be installed locally in either case.&lt;/p&gt;

&lt;h3&gt;
  
  
  Initialize it
&lt;/h3&gt;

&lt;p&gt;After installing it, initialize it with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npx eslint --init
# or
$ yarn run eslint --init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: &lt;code&gt;— init&lt;/code&gt; assumes you have a package.json file already. If you don’t, make sure to run npm init or yarn init beforehand.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configure it
&lt;/h3&gt;

&lt;p&gt;The moment you’re done with the installation and initialization you’ll have a .eslintrc.{js,yml,json} file in your directory. In it, you’ll see some rules configured like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "rules": {
        "semi": ["error", "always"],
        "quotes": ["error", "double"]
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Use it
&lt;/h3&gt;

&lt;p&gt;If you’re here that means you’ve successfully configured the ESLint. Here’s how you can use it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npx elinst &amp;lt;your file&amp;gt;.js
# or 
$ npx eslint &amp;lt;folder containing js files&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also add lint in yourpackage.json file (if not already added)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
  ...
  "lint": "eslint .",
  ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Congrats!
&lt;/h2&gt;

&lt;p&gt;You’ve successfully made your codebase look a lot cleaner and better than ever in just a few steps.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>reactnative</category>
      <category>node</category>
    </item>
  </channel>
</rss>
