<?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: kpiteng</title>
    <description>The latest articles on DEV Community by kpiteng (@kpiteng).</description>
    <link>https://dev.to/kpiteng</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%2F626376%2Fe53cf965-83b1-4503-9b80-e95e5f7f770b.png</url>
      <title>DEV Community: kpiteng</title>
      <link>https://dev.to/kpiteng</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kpiteng"/>
    <language>en</language>
    <item>
      <title>Manage multiple firebase projects in React Native</title>
      <dc:creator>kpiteng</dc:creator>
      <pubDate>Sat, 02 Oct 2021 14:03:36 +0000</pubDate>
      <link>https://dev.to/kpiteng/manage-multiple-firebase-projects-in-react-native-2322</link>
      <guid>https://dev.to/kpiteng/manage-multiple-firebase-projects-in-react-native-2322</guid>
      <description>&lt;p&gt;Hello Developers, We are using &lt;a href="https://www.npmjs.com/package/react-native-config" rel="noopener noreferrer"&gt;react-native-config&lt;/a&gt; to manage multiple environments in Project like Development, Staging and Production. If we have requirements to manage different firebase for Development, Staging and Production then? Today we will see how to manage multiple project environments with multiple firebase GoogleServices-Info.plist and google-service.json files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Highlights of article -&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create React Native Application&lt;/li&gt;
&lt;li&gt;Add Development, Staging, Production Target&lt;/li&gt;
&lt;li&gt;Add Development, Staging, Production Schema&lt;/li&gt;
&lt;li&gt;Link each Schema with each Target&lt;/li&gt;
&lt;li&gt;Add Build, Set Pre-Actions and Select Run Target Executable&lt;/li&gt;
&lt;li&gt;Place Development, Staging and Production GoogleService-Info.plist file&lt;/li&gt;
&lt;li&gt;Link each GoogleService-Info.plist file with each Target&lt;/li&gt;
&lt;li&gt;Update .podfile to share dependency with Development, Staging and Production Target&lt;/li&gt;
&lt;li&gt;SetUp various environment in Android&lt;/li&gt;
&lt;li&gt;SetUp Product Flavor&lt;/li&gt;
&lt;li&gt;Place Development, Staging and Production google-services.json file in Android Application&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://www.kpiteng.com/blogs/securing-react-native-application" rel="noopener noreferrer"&gt;Learn more about - Securing React Native Application&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.kpiteng.com/blogs/top-10-react-tricks-every-developer-should-use" rel="noopener noreferrer"&gt;Learn more about - Top 10 React Tricks Every Developer Should Use&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, first let’s create React Native Application, and setup application icons &amp;amp; all. You can create new application using -&lt;/p&gt;

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

npx react-native init Shopping


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

&lt;/div&gt;

&lt;p&gt;Now, follow the steps, we will setup for iOS &amp;amp; Android.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 1&lt;/strong&gt;&lt;br&gt;
Open iOS Project and Go to Target&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%2Fuploads%2Farticles%2Fhr58e7u081u2rtien2cl.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%2Fuploads%2Farticles%2Fhr58e7u081u2rtien2cl.png" alt="Step - 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 2&lt;/strong&gt;&lt;br&gt;
Right Click on it and press duplicate, It will prompt with three option Duplicate and Transition to iPad, Duplicate Only and Cancel.&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%2Fuploads%2Farticles%2Fgizyf3zf3r7bt3rltq36.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%2Fuploads%2Farticles%2Fgizyf3zf3r7bt3rltq36.png" alt="Step - 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 3&lt;/strong&gt;&lt;br&gt;
Press on Duplicate Only&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%2Fuploads%2Farticles%2F4b50qofprs7aot08tl7t.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%2Fuploads%2Farticles%2F4b50qofprs7aot08tl7t.png" alt="Step - 3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 4&lt;/strong&gt;&lt;br&gt;
Now rename Target name to Shopping-Development&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%2Fuploads%2Farticles%2Ffpb1dn6rfxx3tsxaxpvi.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%2Fuploads%2Farticles%2Ffpb1dn6rfxx3tsxaxpvi.png" alt="Step - 4"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 5&lt;/strong&gt;&lt;br&gt;
Same way create another Target and rename it to Shopping-Staging&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%2Fuploads%2Farticles%2F55558ouz6ng81bvrpjy9.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%2Fuploads%2Farticles%2F55558ouz6ng81bvrpjy9.png" alt="Step - 5"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 6&lt;/strong&gt;&lt;br&gt;
Now, it’s time to create Multiple Project Schema, Shopping, Shopping-Staging, Shopping-Development, Click on Project Schema and Press on Manage Schemas&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%2Fuploads%2Farticles%2Fjs3ifsdsk4b2gl2hee46.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%2Fuploads%2Farticles%2Fjs3ifsdsk4b2gl2hee46.png" alt="Step - 6"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 7&lt;/strong&gt;&lt;br&gt;
Select your Project Schema (Shopping) and click on Settings Icon at bottom, and it will prompt with options, (Duplicate, Import, Export, etc),&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%2Fuploads%2Farticles%2Fgupgsxrtq9rgcmuqfyyt.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%2Fuploads%2Farticles%2Fgupgsxrtq9rgcmuqfyyt.png" alt="Step - 7"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 8&lt;/strong&gt;&lt;br&gt;
Pressed on Duplicate, Now, it will create a new schema for you, Now Rename schema with Shopping-Development, same way duplicate and create schema with Shopping-Staging.&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%2Fuploads%2Farticles%2Fsj19q6us0qqwj8vdqo63.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%2Fuploads%2Farticles%2Fsj19q6us0qqwj8vdqo63.png" alt="Step - 8"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 9&lt;/strong&gt;&lt;br&gt;
So, Finally we have three schema, Shopping, Shopping-Development, Shopping-Staging&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%2Fuploads%2Farticles%2F67f9otq6j6foba1204ci.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%2Fuploads%2Farticles%2F67f9otq6j6foba1204ci.png" alt="Step - 9"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 10&lt;/strong&gt;&lt;br&gt;
So, Now we have three Schema and three Targets&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%2Fuploads%2Farticles%2Fzv95ajhhd6x669g1reoz.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%2Fuploads%2Farticles%2Fzv95ajhhd6x669g1reoz.png" alt="Step - 10"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 11&lt;/strong&gt;&lt;br&gt;
Now, it's time to assign a target to each schema. We have three targets and three schemas, so we will assign one target to each schema. So, first select Shopping Schema, press on Edit Schema option.&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%2Fuploads%2Farticles%2Ftsikkgqh380pb0v5cxti.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%2Fuploads%2Farticles%2Ftsikkgqh380pb0v5cxti.png" alt="Step - 11"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 12&lt;/strong&gt;&lt;br&gt;
Go to the Build Section from left, and make sure you have only one Targets Shopping. Also make sure for that target you have selected all Checkmark mentions on the screenshot. Also you should select only one target according to your requirement. If you can’t find it then click on the plus icon at bottom.&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%2Fuploads%2Farticles%2F8vebbdzy22gb06399ru1.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%2Fuploads%2Farticles%2F8vebbdzy22gb06399ru1.png" alt="Step - 12"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 13&lt;/strong&gt;&lt;br&gt;
Which will prompt like this, select your Target according to your schema. So here, We are selecting Shopping.&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%2Fuploads%2Farticles%2F24so3dij5o15q2cjfxt0.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%2Fuploads%2Farticles%2F24so3dij5o15q2cjfxt0.png" alt="Step - 13"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 14&lt;/strong&gt;&lt;br&gt;
Now, Go To Run Section - and choose Shopping.app as executable.&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%2Fuploads%2Farticles%2Fkobybrneniapoh2693yx.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%2Fuploads%2Farticles%2Fkobybrneniapoh2693yx.png" alt="Step - 14"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 15&lt;/strong&gt;&lt;br&gt;
Now, To set react-native config env for Production environment, click on Pre-actions and add New Run-Script Action.&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%2Fuploads%2Farticles%2Ft97jzsk4oxcnxmk1zh9n.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%2Fuploads%2Farticles%2Ft97jzsk4oxcnxmk1zh9n.png" alt="Step - 15"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 16&lt;/strong&gt;&lt;br&gt;
Copy the script code as shown in Screenshot, for Shopping Schema, we are referring env.production, same way for Shopping-Staging we refer env.staging and for Shopping-Development we refer env.development. So, Do this for Staging Schema, and Development Schema. Using this process we have assigned Target to our schema,&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%2Fuploads%2Farticles%2Fdn6dqwcok7germpueovg.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%2Fuploads%2Farticles%2Fdn6dqwcok7germpueovg.png" alt="Step - 16"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 17&lt;/strong&gt;&lt;br&gt;
Now, it's time to assign GoogleService-Info.plist to our Target. We have three targets and we have three different firebase accounts each for Development, Staging, production. So you required three GoogleService-Info.plist, So, It’s time to add multiple GoogleSevices-Info.plist according to Environment. So, Create GoogleServices folder inside Shopping (Project) folder,&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%2Fuploads%2Farticles%2Fmc7tbumoinqfd3ga4gju.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%2Fuploads%2Farticles%2Fmc7tbumoinqfd3ga4gju.png" alt="Step - 17"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 18&lt;/strong&gt;&lt;br&gt;
Create Development, Staging, Production folder inside GoogleServices folder according to your environment name and add GoogleService-Info.plist file into 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%2Fuploads%2Farticles%2Fugdtm9ifnqt6tc04cu7i.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%2Fuploads%2Farticles%2Fugdtm9ifnqt6tc04cu7i.png" alt="Step - 18"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 19&lt;/strong&gt;&lt;br&gt;
While adding GoogleService-Info.plist for Production make sure you have select (checkmark) that target, in our case we select (checkmark) only Shopping Target. It means that .plist file specific to Shopping Target.&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%2Fuploads%2Farticles%2F4z5axn2y9y1fynrx2pjg.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%2Fuploads%2Farticles%2F4z5axn2y9y1fynrx2pjg.png" alt="Step - 19"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 20&lt;/strong&gt;&lt;br&gt;
Same way while adding GoogleService-Info.plist for Staging, you only select (checkmark) only Shopping-Staging Target only.&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%2Fuploads%2Farticles%2Firkh8e5wmj4tgedxh6z2.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%2Fuploads%2Farticles%2Firkh8e5wmj4tgedxh6z2.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 21&lt;/strong&gt;&lt;br&gt;
If you have used custom Run Script and all, then you have to make sure all the scripts which are in Shopping (Main Target), might not be there for Shopping-Development, Shopping-Staging Target. Here, I have few scripts which are in Shopping Target, you can see [CP] Copy Pods Resources. Reason behind the [CP] scripts not copy because of while you do npx pod-install, at that time it will install / execute only Shopping Target’s [CP] Scripts.&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%2Fuploads%2Farticles%2Fextd7g4z7mlzz77jl67u.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%2Fuploads%2Farticles%2Fextd7g4z7mlzz77jl67u.png" alt="Step - 21"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 22&lt;/strong&gt;&lt;br&gt;
So, the problem is with .podfile, if you see the pod file we have initially installed all dependencies for Shopping target, which we need to share with Shopping-Development, Shopping-Staging Target as well. So let’s modify our .podfile according.&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%2Fuploads%2Farticles%2F5a15dpuzbwedbmkx0vsk.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%2Fuploads%2Farticles%2F5a15dpuzbwedbmkx0vsk.png" alt="Step - 22"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 23&lt;/strong&gt;&lt;br&gt;
For Android go to android/app/build.gradle and add three environment, Development, Staging, Production as shown in Screenshot.&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%2Fuploads%2Farticles%2Fq4r4uwkj5le69m2v7riu.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%2Fuploads%2Farticles%2Fq4r4uwkj5le69m2v7riu.png" alt="Step - 23"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 24&lt;/strong&gt;&lt;br&gt;
In android/app/build.gradle inside android ... defaultConfig add flavorDimensions "default" as shown in Screenshot&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%2Fuploads%2Farticles%2Ffzvu3ceudwwjp1ydunjw.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%2Fuploads%2Farticles%2Ffzvu3ceudwwjp1ydunjw.png" alt="Step - 24"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 25&lt;/strong&gt;&lt;br&gt;
Now, add productFlavors as mention in screenshot, you can specify different applicationId according to your Target/Environment.&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%2Fuploads%2Farticles%2Fedoi71z1wv39yv768cyr.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%2Fuploads%2Farticles%2Fedoi71z1wv39yv768cyr.png" alt="Step - 25"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step - 26&lt;/strong&gt;&lt;br&gt;
Now, it's time to add multiple google-services.json according to Development, Staging and Production environment as shown in Screenshot.&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%2Fuploads%2Farticles%2Ffdwsq4bojm50d6c2uhn6.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%2Fuploads%2Farticles%2Ffdwsq4bojm50d6c2uhn6.png" alt="Step - 26"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it, now you can run your React Native Application with different Schema and it will take environment (URL/Constants), GoogleService-Info.plist and google-services.json according to your target.&lt;/p&gt;

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

&lt;p&gt;KPITENG | DIGITAL TRANSFORMATION&lt;br&gt;
&lt;a href="http://www.kpiteng.com/blogs" rel="noopener noreferrer"&gt;www.kpiteng.com/blogs&lt;/a&gt; | &lt;a href="mailto:hello@kpiteng.com"&gt;hello@kpiteng.com&lt;/a&gt;&lt;br&gt;
Connect | Follow Us On - &lt;a href="https://www.linkedin.com/company/kpiteng/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt; | [Facebook]&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>react</category>
      <category>firebase</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Kubernetes Architecture</title>
      <dc:creator>kpiteng</dc:creator>
      <pubDate>Sun, 05 Sep 2021 12:22:14 +0000</pubDate>
      <link>https://dev.to/kpiteng/kubernetes-architecture-45hp</link>
      <guid>https://dev.to/kpiteng/kubernetes-architecture-45hp</guid>
      <description>&lt;p&gt;All you know about monolithic architecture, but when we migrate to micro-service architecture where everything resides according to modules in various containers. But containers are not scalable, not in-built load balancing and all. Think if your OS crashes where all your containers are, then the whole system stops working and the system shuts down. Also, if your users limit pitched threshold value, then you don’t have the option to create another container and manage users load.&lt;/p&gt;

&lt;p&gt;To overcome this limitation and manage, scale your container Kubernetes comes into picture.&lt;/p&gt;

&lt;p&gt;Let’s look into architecture,&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%2Fuploads%2Farticles%2Fkq7jswnlvrhs2jabalhg.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%2Fuploads%2Farticles%2Fkq7jswnlvrhs2jabalhg.png" alt="Kubernetes Architecture"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Kubernetes is a container-orchestration solution for application deployment, scaling. It was designed by Google and now it is maintained by Cloud Native Computing Foundation.&lt;/p&gt;

&lt;p&gt;Many popular Cloud Services like Google, Amazon, etc offer a Kubernetes based platform as a service or infrastructure as a service on which Kubernetes is deployed as a platform-providing service.&lt;/p&gt;

&lt;p&gt;Kubernetes provides infrastructure that deploy, scale applications based on CPU Usage, User’s traffic and according specified set of rules. Kubernetes follows the master/slave architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  Kubernetes Master -
&lt;/h2&gt;

&lt;p&gt;Kubernetes master is responsible for controlling the cluster, managing workloads and communication across the system. It contains various components like &lt;strong&gt;API Server, Controller Manager, Scheduler, etcd.&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  etcd -
&lt;/h4&gt;

&lt;p&gt;It's a lightweight key-value data store, which stores the configuration details of the cluster. It also represents the overall state of the cluster at any time. Kubernetes API Server uses etcd’s watch API to monitor cluster and upgrade/downgrade configuration changes according to specified rules. Let’s say if the deployer has set five instances of pods that need to be running, this is stored in etcd. If it is found that only 4 instances are running, this difference will be detected by comparison with etcd data and Kubernetes will create an additional instance of the new pod.&lt;/p&gt;

&lt;h4&gt;
  
  
  API Server -
&lt;/h4&gt;

&lt;p&gt;API Server serves the API using JSON over HTTP. API Server processes and validates REST requests and updates the state of the API object in etcd, so it helps clients to configure workloads and containers across Worker nodes.&lt;/p&gt;

&lt;h4&gt;
  
  
  Scheduler -
&lt;/h4&gt;

&lt;p&gt;Scheduler selects the unscheduled pods of node. It tracks the resources. So based on resource requirements it can schedule pod in node.&lt;/p&gt;

&lt;h4&gt;
  
  
  Controller Manager -
&lt;/h4&gt;

&lt;p&gt;Controller Manager drives actual cluster state toward the desired cluster state. It communicates with API Server to create, update and delete the resources it manages. It is also responsible to create/replace nodes if any node fails.&lt;/p&gt;

&lt;h2&gt;
  
  
  Nodes -
&lt;/h2&gt;

&lt;p&gt;Nodes is a system where containers are deployed. Where Docker Image/ Services are running. It contains Kubelet, Kube-Proxy, Container.&lt;/p&gt;

&lt;h4&gt;
  
  
  Kubelet -
&lt;/h4&gt;

&lt;p&gt;Kublet is responsible for running/starting/stopping and maintaining the node and ensuring containers (pods) on the node are healthy. Kubelet also monitors the state of the pod, if any is not in desired state, it re-deploys the same node.&lt;/p&gt;

&lt;p&gt;Node status is checked on certain seconds. If it detects a node failure, the replication controller observes this state change and launches pod on other healthy nodes.&lt;/p&gt;

&lt;h4&gt;
  
  
  Kube-Proxy -
&lt;/h4&gt;

&lt;p&gt;It’s an Implementation of network proxy and a load balancer. It’s responsible for routing traffic to appropriate containers based on IP and port number of the incoming requests.&lt;/p&gt;

&lt;h4&gt;
  
  
  Container Runtime -
&lt;/h4&gt;

&lt;p&gt;Container is the core level of micro-service, which contains applications, libraries and dependencies. It is exposed through an external IP address. Kubernetes supports Docker containers to run inside pod.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pod -
&lt;/h2&gt;

&lt;p&gt;Pod is a scheduling unit in Kubernetes, Kubernetes contains one or more than one container and is located on the same node.&lt;/p&gt;

&lt;p&gt;Each pod in Kubernetes is assigned a unique IP address within the cluster, which allows applications to use ports without the risk of conflict.&lt;/p&gt;

&lt;p&gt;Inside the Pod, containers reference each other on localhost. But a container within one pod has no way to directly connect the container of another pod, for that container has to use Pod IP Address.&lt;/p&gt;

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

&lt;p&gt;KPITENG | DIGITAL TRANSFORMATION&lt;br&gt;
&lt;a href="http://www.kpiteng.com/blogs" rel="noopener noreferrer"&gt;www.kpiteng.com/blogs&lt;/a&gt; | &lt;a href="mailto:hello@kpiteng.com"&gt;hello@kpiteng.com&lt;/a&gt;&lt;br&gt;
Connect | Follow Us On - &lt;a href="https://www.linkedin.com/company/kpiteng/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt; | &lt;a href="https://www.facebook.com/kpiteng" rel="noopener noreferrer"&gt;Facebook&lt;/a&gt; | &lt;a href="https://www.instagram.com/kpiteng" rel="noopener noreferrer"&gt;Instagram&lt;/a&gt;&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>cdci</category>
      <category>devops</category>
    </item>
    <item>
      <title>Redux Rematch - State Management</title>
      <dc:creator>kpiteng</dc:creator>
      <pubDate>Thu, 02 Sep 2021 15:35:46 +0000</pubDate>
      <link>https://dev.to/kpiteng/redux-rematch-state-management-71g</link>
      <guid>https://dev.to/kpiteng/redux-rematch-state-management-71g</guid>
      <description>&lt;p&gt;Rematch is an enhanced version of Redux with added few more features, clean architecture, less boilerplate for React Developers. Rematch uses the same redux concept and also has a persistor to persist store data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/kpiteng/redux-rematch"&gt;Please download full source code from our GitHub.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s look into architecture,&lt;/p&gt;

&lt;h3&gt;
  
  
  Provider -
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Provider store={store}&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Provider contains an argument store. Here, we need to pass our store object in store argument to initialize Rematch Store.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://www.kpiteng.com/blogs/react-nativagation-6.x"&gt;See What's new in React Navigation 6.x.&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Store -
&lt;/h3&gt;

&lt;p&gt;To initialize a store we need to pass models, plugins, redux, etc. Let’s check the syntax,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default init({
    models,
    plugins: [loadingPlugin, persistPlugin],
    redux: {
      middlewares: [logger],
    },
  })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Models&lt;/strong&gt; - Models contain state, reducer and effects in one instead of separate like Redux.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Plugins&lt;/strong&gt; - Plugins contain Loading Plugins, Persist Plugins.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Redux&lt;/strong&gt; - Contains middleware to perform some action in middleware between store &amp;amp; frontend.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://www.kpiteng.com/blogs/improve-react-native-app-performance"&gt;See, How to improve performance of React Application?&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Models -
&lt;/h3&gt;

&lt;p&gt;Models are the core part of Store. Model contains state variables, reducers, effects. Frontend will dispatch action, which executes in effects and once effect computed task it will dispatch to reducer and reducer is responsible for updating state variables. So whenever the state variable is updated our component is also notified.&lt;/p&gt;

&lt;p&gt;As you can see in Image, when UI Dispatch action it executes effects in model, once effect completed its execution it dispatches to reducers and reducer is only responsible to update state. Once the state gets updated it will re-render the UI Component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const TaskList = {
    state: {
      arrTasks: [],
      fetchError: undefined
    },
    reducers: {
      setTasks(state, payload) {
        return {
          ...state,
          arrTasks: payload,
        };
      },
      setError(state, payload) {
        return {
        ...state,
        fetchError: payload
        }
      }
    },
    effects: (dispatch) =&amp;gt; ({
      async fetchTaskList() {
        try {
          const data = [
              { "taskID": 1, "taskName": "Task #1" },
              { "taskID": 2, "taskName": "Task #2" },
              { "taskID": 3, "taskName": "Task #3" }
          ]
          dispatch.TaskList.setTasks(data);
        } catch (error) {
          dispatch.TaskList.setError(error);
        }
      },
    }),
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Plugins -
&lt;/h3&gt;

&lt;p&gt;Rematch allows various plugins, you can set Loading Plugins, Persist Plugins.&lt;/p&gt;

&lt;h4&gt;
  
  
  Loading Plugins -
&lt;/h4&gt;

&lt;p&gt;When we dispatch any action, we have to wait for a fraction of time until we receive results (API Call, Local Operation). Redux in-built having plugins that manage and return us loading = true which effect (action) being in-progress.&lt;/p&gt;

&lt;p&gt;You can create Loading PlugIns using createLoadingPlugin, and pass your model name/actionname in the whitelist. As you can see we have taskList (model), fetchTaskList (action). So after this code, whenever the fetchTaskList operation is in-progress we will get loading as true, once it’s completed we get loading as false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import createLoadingPlugin from '@rematch/loading';

export const loadingPlugin = createLoadingPlugin({
  whitelist: [taskList/fetchTaskList'],
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://www.kpiteng.com/blogs/top-10-react-hooks-library"&gt;Discover Top 10 React Hooks Library&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Persist Plugins -
&lt;/h4&gt;

&lt;p&gt;Persist Plugins contains all required configuration like, whitelist, blacklist, version, storage, transforms, Let’s discuss each in details,&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;whitelist&lt;/strong&gt; - Specify a list of models which you want to store in storage, even though you kill an application, restart application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;blacklist&lt;/strong&gt; - Specify list of models which you don’t want to store in storage, so next time it will load with initial state, instead of saved state.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;version&lt;/strong&gt; - version of store,each to you deploy new application increase the version number, which help to migrate data from older version to newer version.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;storage&lt;/strong&gt; - Specify the storage when your store data is saved, for mobile applications ideally we prefer AsyncStorage, while in web we prefer default Web Storage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;transform&lt;/strong&gt; - Specify Filters, many times you are required to blacklist a model (don’t want to store state value/ persist state value) but you want to store a few key/pairs only. So you can create whitelist filters for a few keys, and pass the model name in blacklist. So Rematch will only store key/pairs which you have sent in the whitelist.&lt;/p&gt;

&lt;h3&gt;
  
  
  Redux -
&lt;/h3&gt;

&lt;p&gt;Redux contains middlewares, you can specify middlewares. You can create your own middleware to perform some action between UI Component and Effect which action dispatch by UI Component.&lt;/p&gt;

&lt;p&gt;For example, let’s specify logger as middleware, so when you dispatch action, it will log in the console to track actions, same way whenever reducer updates the state at the same time logger also logs in console to update users about Rematch actions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import logger from 'redux-logger';
redux: {
  middlewares: [logger],
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now Let’s take an example of a Model and dispatch actions from the Component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Model - TaskList.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const TaskList = {
    state: {
      arrTasks: [],
      fetchError: undefined
    },
    reducers: {
      setTasks(state, payload) {
        return {
          ...state,
          arrTasks: payload,
        };
      },
      setError(state, payload) {
        return {
        ...state,
        fetchError: payload
        }
      }
    },
    effects: (dispatch) =&amp;gt; ({
      async fetchTaskList() {
        try {
          const data = [
              { "taskID": 1, "taskName": "Task #1" },
              { "taskID": 2, "taskName": "Task #2" },
              { "taskID": 3, "taskName": "Task #3" }
          ]
          dispatch.TaskList.setTasks(data);
        } catch (error) {
          dispatch.TaskList.setError(error);
        }
      },
    }),
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Component - Tasks.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, {useEffect} from 'react';
import {
    SafeAreaView, View, FlatList, Text
} from 'react-native';
import { connect } from 'react-redux';

function Tasks(props) {

    useEffect(() =&amp;gt; {
      props.fetchTaskList();
    }, []);

    const TaskListItem = ({task}) =&amp;gt; {
      return (
        &amp;lt;View style={{flex: 1, marginVertical: 10, marginHorizontal: 10}}&amp;gt;
          &amp;lt;Text&amp;gt;{task.taskName}&amp;lt;/Text&amp;gt;
        &amp;lt;/View&amp;gt;
      )
    }

    console.log(JSON.stringify(props.arrTasks));

    return (
      &amp;lt;SafeAreaView style={{flex: 1}}&amp;gt;
         &amp;lt;FlatList
            data={props.arrTasks}
            renderItem={({ item, index }) =&amp;gt; &amp;lt;TaskListItem task={item}/&amp;gt;}
            keyExtractor={(item, index) =&amp;gt; item.taskID}
        /&amp;gt;
      &amp;lt;/SafeAreaView&amp;gt;
    );
  }
  const mapStateToProps = ({ TaskList, loading }) =&amp;gt; ({
    arrTasks: TaskList.arrTasks,
    loading: loading.effects.TaskList.arrTasks,
  });

  const mapDispatchToProps = ({ TaskList: { fetchTaskList } }) =&amp;gt; ({
    fetchTaskList: () =&amp;gt; fetchTaskList(),
  });

  export default connect(mapStateToProps, mapDispatchToProps)(Tasks);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see in Tasks Component, We are dispatching fetchTaskList on load of Component. Will call effect in TaskList.js model. Once fetch operation completed it will dispatch setTasks (action), which calls function in reducers, and reducer will update state variables of arryTasks, which in result re-render our Tasks Component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/kpiteng/redux-rematch"&gt;Please download full source code from our GitHub.&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;KPITENG | DIGITAL TRANSFORMATION&lt;br&gt;
&lt;a href="http://www.kpiteng.com/blogs"&gt;www.kpiteng.com/blogs&lt;/a&gt; | &lt;a href="mailto:hello@kpiteng.com"&gt;hello@kpiteng.com&lt;/a&gt;&lt;br&gt;
Connect | Follow Us On - &lt;a href="https://www.linkedin.com/company/kpiteng/"&gt;Linkedin&lt;/a&gt; | &lt;a href="https://www.facebook.com/kpiteng"&gt;Facebook&lt;/a&gt; | &lt;a href="https://www.instagram.com/kpiteng"&gt;Instagram&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactnative</category>
      <category>redux</category>
      <category>rematch</category>
    </item>
    <item>
      <title>Microfrontends With React</title>
      <dc:creator>kpiteng</dc:creator>
      <pubDate>Wed, 11 Aug 2021 05:04:37 +0000</pubDate>
      <link>https://dev.to/kpiteng/microfrontends-with-react-47jb</link>
      <guid>https://dev.to/kpiteng/microfrontends-with-react-47jb</guid>
      <description>&lt;p&gt;All we know about Microservices, which helps to develop, deploy and maintain applications individually. Like Uber where booking and payment services are individually developed and deployed. Same way we can develop, deploy react applications individually. It means, your application is divided into various individual applications and easy to maintain, that concept known as Micro Frontends.&lt;/p&gt;

&lt;p&gt;Today, we will see a React Website using Micro Frontends where we create three applications, Blogs App, Header App and Container App (Which glue Blog &amp;amp; Header and represent a single web application).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/kpiteng/microfrontends-using-reactjs"&gt;Please download full source code from our GitHub.&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Create React Applications -
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Let’s create three react application,&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Blogs (Website Blogs App)&lt;/li&gt;
&lt;li&gt;Header (Website Header)&lt;/li&gt;
&lt;li&gt;Container (Actual Website, Where we merged Blog &amp;amp; Header)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app container
npx create-react-app blogs
npx create-react-app header
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Blog Application -&lt;/strong&gt;&lt;br&gt;
Let’s create Constant add array of blogs,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const arrBlogs = [
    {
      "blogID": 1,
      "blogName": "React Navigation",
      "blogDetail": "Hello Developers! Let's see what's new in React Navigation 6.x.",
      "blogURL": "https://www.kpiteng.com/blogs/react-nativagation-6.x"
    },
    {
      "blogID": 2,
      "blogName": "Securing React Native Application",
      "blogDetail": "Discover a ways to develop secure react native application.",
      "blogURL": "https://www.kpiteng.com/blogs/securing-react-native-application"
    },
    {
      "blogID": 3,
      "blogName": "Top 10 React Tricks Every Developer Should Use",
      "blogDetail": "Discover a set of React best coding practices, tips and tricks that should be known by all developers.",
      "blogURL": "https://www.kpiteng.com/blogs/top-10-react-tricks-every-developer-should-use"
    }
  ] 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s do code for Blogs Listing, Create a file &lt;strong&gt;Blog.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useEffect } from "react";
import {arrBlogs} from './Constant';
import {
 Link
} from "react-router-dom";
import "./App.css";

function App() {
 return (
   &amp;lt;div className="container mt-5"&amp;gt;
     &amp;lt;div className="row"&amp;gt;
     {
       arrBlogs.map((blog, index) =&amp;gt; {
         return (
           &amp;lt;div className="col-xs-12 col-sm-12 col-md-6 col-lg-4 col-xl-4 mb-5"&amp;gt;
             &amp;lt;div className="card"&amp;gt;
               &amp;lt;Link to={{pathname: `/blogdetail/${blog.blogID}`, id: blog.blogID, item: blog}} &amp;gt;
                 &amp;lt;div class="card-body"&amp;gt;
                   &amp;lt;h5 class="card-title"&amp;gt;{`#${blog.blogID}`}&amp;lt;/h5&amp;gt;
                   &amp;lt;p class="card-text"&amp;gt;{blog.blogName}&amp;lt;/p&amp;gt;
                   &amp;lt;p class="card-text"&amp;gt;{blog.blogDetail}&amp;lt;/p&amp;gt;
                 &amp;lt;/div&amp;gt;
               &amp;lt;/Link&amp;gt;
             &amp;lt;/div&amp;gt;
           &amp;lt;/div&amp;gt;
         )
       })
     }
     &amp;lt;/div&amp;gt;
   &amp;lt;/div&amp;gt;
 );
}

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

&lt;/div&gt;



&lt;p&gt;Blogs are located at url.com/blogs, So we need to set up &lt;strong&gt;react-router-dom and history&lt;/strong&gt;.&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 react-router-dom history
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To see blog detail we need to setup code for BlogDetail, create file &lt;strong&gt;BlogDetail.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useEffect } from "react";
import {arrBlogs} from './Constant';
import "./App.css";

function BlogDetail(props) {

 const [blogDetail, setBlogDetail] = useState({});

 useEffect(() =&amp;gt; {
   const blogID = parseInt(props.match.params.blogid);
   const index = arrBlogs.findIndex((blog) =&amp;gt; blog.blogID === blogID);
   if (index !== -1){
     setBlogDetail(arrBlogs[index])
   }
 }, []);

  return (
   &amp;lt;div className="container mt-5"&amp;gt;
     &amp;lt;div className="row"&amp;gt;
       &amp;lt;div className="card"&amp;gt;
         {
           Object.keys(blogDetail).length &amp;gt; 0 &amp;amp;&amp;amp; &amp;lt;&amp;gt;
           &amp;lt;p&amp;gt;{`#${blogDetail.blogID}`}&amp;lt;/p&amp;gt;
           &amp;lt;p&amp;gt;{blogDetail.blogName}&amp;lt;/p&amp;gt;
           &amp;lt;p&amp;gt;{blogDetail.blogDetail}&amp;lt;/p&amp;gt;
           &amp;lt;p&amp;gt;{blogDetail.blogURL}&amp;lt;/p&amp;gt;
           &amp;lt;/&amp;gt;
         }
         {
           Object.keys(blogDetail).length === 0 &amp;amp;&amp;amp;
           &amp;lt;p&amp;gt;We're sorry, Cound't find Blog&amp;lt;/p&amp;gt;
         }
       &amp;lt;/div&amp;gt;
     &amp;lt;/div&amp;gt;
   &amp;lt;/div&amp;gt;
 );
}

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

&lt;/div&gt;



&lt;p&gt;Finally, We have Constant, Blogs and BlogDetail. Now Let’s do code for Blogs, BlogDetail routing. Replace App.js code with following,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useEffect } from "react";
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
import { createBrowserHistory } from "history";
import Blogs from './Blogs';
import BlogDetail from './BlogDetail';
import "./App.css";

const defaultHistory = createBrowserHistory();

function App({ history = defaultHistory }) {
 return (
   &amp;lt;Router&amp;gt;
     &amp;lt;Switch&amp;gt;
       &amp;lt;Route exact path="/" component={Blogs} /&amp;gt;
       &amp;lt;Route exact path="/blogdetail/:blogid" component={BlogDetail} /&amp;gt;
     &amp;lt;/Switch&amp;gt;
   &amp;lt;/Router&amp;gt;
 );
}

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

&lt;/div&gt;



&lt;p&gt;Now, it’s time to run the application. We can see the list of Blogs and on press of the blog it redirect users to blog detail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Header Application -&lt;/strong&gt;&lt;br&gt;
Here, We simply add header div to demonstrate Header Application. So, let’s add all required dependencies.&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 react-router-dom history
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s modify code for App.js&lt;br&gt;
&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 { createBrowserHistory } from "history";
import "./App.css";

const defaultHistory = createBrowserHistory();

function App({ history = defaultHistory }) {
 return (
   &amp;lt;div&amp;gt;
     &amp;lt;p&amp;gt;KPITENG (Header Application)&amp;lt;/p&amp;gt;
   &amp;lt;/div&amp;gt;
 );
}

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

&lt;/div&gt;



&lt;p&gt;Now, let’s run the application, It will show a Simple Header.&lt;/p&gt;

&lt;p&gt;So, we have two applications ready, Blogs Application - where we do code for Blogs Listing, Header Application - Where we do code for Showing Header In Application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Container Application -&lt;/strong&gt;&lt;br&gt;
Now, it's time to setup our Container Application which actually use/merge both Header and Blogs Application into our Container Application (Our Main Website)&lt;/p&gt;

&lt;p&gt;Let’s add react-router-dom, history to Container Application. After that let’s update code for App.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from "react";
import { BrowserRouter, Switch, Route } from "react-router-dom";
import { createBrowserHistory } from "history";
import MicroFrontend from "./MicroFrontend";

import "./App.css";

const defaultHistory = createBrowserHistory();

const {
 REACT_APP_HEADER_HOST: headerHost,
 REACT_APP_BLOGS_HOST: blogHost,
} = process.env;

function Header({ history }) {
 return &amp;lt;MicroFrontend history={history} host={headerHost} name="Header" /&amp;gt;;
}

function Blogs({ history }) {
 return &amp;lt;MicroFrontend history={history} host={blogHost} name="Blogs" /&amp;gt;;
}

function BlogDetail({history}) {
 return (
   &amp;lt;div&amp;gt;
     &amp;lt;MicroFrontend history={history} host={blogHost} name="Blogs" /&amp;gt;
   &amp;lt;/div&amp;gt;
 );
}


function Home({ history }) {

 return (
   &amp;lt;div className="container"&amp;gt;
      &amp;lt;Header /&amp;gt;
      &amp;lt;Blogs /&amp;gt;
   &amp;lt;/div&amp;gt;
 );
}

function App() {
 return (
   &amp;lt;BrowserRouter&amp;gt;
     &amp;lt;React.Fragment&amp;gt;
       &amp;lt;Switch&amp;gt;
         &amp;lt;Route exact path="/" component={Home} /&amp;gt;
         &amp;lt;Route exact path="/blogdetail/:blogid" component={BlogDetail} /&amp;gt;
       &amp;lt;/Switch&amp;gt;
     &amp;lt;/React.Fragment&amp;gt;
   &amp;lt;/BrowserRouter&amp;gt;
 );
}

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  SetUp Micro Frontends -
&lt;/h3&gt;

&lt;p&gt;Think, how my Container app knows about Header Application and Blogs Application. Let’s set it up one by one.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;SetUp Web Application Port - *&lt;/em&gt;&lt;br&gt;
Container Application - Port 3000&lt;br&gt;
Header Application - Port 3001 &lt;br&gt;
Blogs Application - Port 3002&lt;/p&gt;

&lt;p&gt;To do this, update package.json,&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Container Application,&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
   "start": "PORT=3000 react-app-rewired start",
 },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Header Application,&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
   "start": "PORT=3001 react-app-rewired start",
 },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Blogs Application,&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
   "start": "PORT=3002 react-app-rewired start",
 },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, Create .env file in root directory of Container Application,&lt;/p&gt;

&lt;p&gt;REACT_APP_HEADER_HOST=&lt;a href="http://localhost:3001"&gt;http://localhost:3001&lt;/a&gt;&lt;br&gt;
REACT_APP_BLOGS_HOST=&lt;a href="http://localhost:3002"&gt;http://localhost:3002&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You know, React App bundle entire applications to main.js, Where we have functions to render, mount, unmount components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Render Function Name: render{ApplicationName}
UnMount Function Name: unmount{ApplicationName}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, Your Blogs App looks like,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;renderBlogs
unmountBlogs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same way, Header App looks like,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;renderHeader
unmountHeader
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s create a MicroFrontend.js file in Container App, which has business logic for mount, unmount components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useEffect } from "react";

function MicroFrontend({ name, host, history }) {
 useEffect(() =&amp;gt; {
   const scriptId = `micro-frontend-script-${name}`;

   const renderMicroFrontend = () =&amp;gt; {

     window[`render${name}`](`${name}-container`, history);
   };

   if (document.getElementById(scriptId)) {
     renderMicroFrontend();
     return;
   }

   fetch(`${host}/asset-manifest.json`)
     .then((res) =&amp;gt; res.json())
     .then((manifest) =&amp;gt; {
       const script = document.createElement("script");
       script.id = scriptId;
       script.crossOrigin = "";
       script.src = `${host}${manifest.files["main.js"]}`;
       script.onload = () =&amp;gt; {
         renderMicroFrontend();
       };
       document.head.appendChild(script);
     });

   return () =&amp;gt; {
     window[`unmount${name}`] &amp;amp;&amp;amp; window[`unmount${name}`](`${name}-container`);
   };
 });

 return &amp;lt;main id={`${name}-container`} /&amp;gt;;
}

MicroFrontend.defaultProps = {
 document,
 window,
};

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

&lt;/div&gt;



&lt;p&gt;As you can see MicroFrontend component will take name, host and history as params. See the fetch function which fetch the asset-manifest.json from the host and create a script object using the main.js and it will use the render function to mount components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SetUp Micro Frontends for Blogs Application -&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s install react-app-rewired package which overrides the build config without ejecting the app.&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 react-app-rewired
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create config.overrides.js in the root directory of blogs application and add the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
   webpack: (config, env) =&amp;gt; {
     config.optimization.runtimeChunk = false;
     config.optimization.splitChunks = {
       cacheGroups: {
         default: false,
       },
     };
      config.output.filename = "static/js/[name].js";
      config.plugins[5].options.filename = "static/css/[name].css";
     config.plugins[5].options.moduleFilename = () =&amp;gt; "static/css/main.css";
     return config;
   },
 };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let’s update scripts section of package.json file,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
   "start": "PORT=3002 react-app-rewired start",
   "build": "react-app-rewired build",
   "test": "react-app-rewired test",
   "eject": "react-app-rewired eject"
 },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And final step in Blogs Application to update index.js,&lt;br&gt;
&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 './index.css';
import App from './App';

window.renderBlogs = (containerId, history) =&amp;gt; {
 ReactDOM.render(
   &amp;lt;App history={history} /&amp;gt;,
   document.getElementById(containerId),
 );
};

window.unmountBlogs = containerId =&amp;gt; {
 ReactDOM.unmountComponentAtNode(document.getElementById(containerId));
};

if (!document.getElementById('Blogs-container')) {
 ReactDOM.render(&amp;lt;App /&amp;gt;, document.getElementById('root'));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SetUp Microfrontends for Header Application -&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install react-app-rewired&lt;/li&gt;
&lt;li&gt;Update package.json &lt;/li&gt;
&lt;li&gt;Update index.js file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally, We run the Container App (Our Main Web Application)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/kpiteng/microfrontends-using-reactjs"&gt;Please download full source code from our GitHub.&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;KPITENG | DIGITAL TRANSFORMATION&lt;br&gt;
&lt;a href="http://www.kpiteng.com/blogs"&gt;www.kpiteng.com/blogs&lt;/a&gt; | &lt;a href="mailto:hello@kpiteng.com"&gt;hello@kpiteng.com&lt;/a&gt;&lt;br&gt;
Connect | Follow Us On - &lt;a href="https://www.linkedin.com/company/kpiteng/"&gt;Linkedin&lt;/a&gt; | &lt;a href="https://www.facebook.com/kpiteng"&gt;Facebook&lt;/a&gt; | &lt;a href="https://www.instagram.com/kpiteng"&gt;Instagram&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>microfrontends</category>
      <category>javascript</category>
    </item>
    <item>
      <title>React Navigation 6.x</title>
      <dc:creator>kpiteng</dc:creator>
      <pubDate>Thu, 29 Jul 2021 03:39:21 +0000</pubDate>
      <link>https://dev.to/kpiteng/react-navigation-6-x-29m8</link>
      <guid>https://dev.to/kpiteng/react-navigation-6-x-29m8</guid>
      <description>&lt;p&gt;Hello Developers! Let's see what's new in React Navigation 6.x.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Points -
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Installation&lt;/li&gt;
&lt;li&gt;Params are now overwritten on navigation instead of merging&lt;/li&gt;
&lt;li&gt;By default, modals in iOS uses presentation style and in android it uses slide animation&lt;/li&gt;
&lt;li&gt;Drawer now uses a slide animation by default on iOS&lt;/li&gt;
&lt;li&gt;Headers by default in Drawer &amp;amp; Bottom Tab, No more need to add Stack Navigator&lt;/li&gt;
&lt;li&gt;Material Top Tabs now uses ViewPager based implementation with native experience&lt;/li&gt;
&lt;li&gt;UI Elements Library with rich feature component to be used in React Navigation&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Minimum requirements&lt;/strong&gt;&lt;br&gt;
React Navigation 6 requires at least &lt;code&gt;react-native@0.63.0.&lt;/code&gt; If you’re using Expo, your SDK needs to be at least &lt;code&gt;41&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NPM&lt;/strong&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 @react-navigation/native@next @react-navigation/stack@next
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;YARN&lt;/strong&gt;&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 @react-navigation/native@next @react-navigation/stack@next
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;React Navigation using some core utilities and those are used by navigators to create navigation structures in the app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Following libraries needs to be install -&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;react-native-gesture-handler
react-native-reanimated
react-native-screens 
React-native-safe-area-context
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Install dependency -&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;NPM&lt;/strong&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 react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;YARN&lt;/strong&gt;&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 react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From React Native 0.60 and higher, linking is automatic. So you don't need to run &lt;code&gt;react-native link&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you're on a Mac and developing for iOS, you need to install the pods (via Cocoapods) to complete the linking.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx pod-install ios&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Older versions of some libraries are longer supported,&lt;/strong&gt; React Navigation requires newer versions of the following libraries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;react-native-safe-area-context &amp;gt;= 3.0.0
react-native-screens &amp;gt;= 2.15.0
react-native-tab-view &amp;gt;= 3.0.0
react-native &amp;gt;= 0.63.0
expo - 40+ (if you use Expo)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Recommended - &lt;a href="https://www.kpiteng.com/blogs/securing-react-native-application"&gt;Securing React Native Application&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Params are now overwritten on navigation instead of merging -
&lt;/h3&gt;

&lt;p&gt;When navigating to an existing component/screen, params are merged from the initial version. Example - Let’s say there is existing article screen with the following params:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "articleTitle": "React Navigation",
  "articleBody": "Top React Navigation Library"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you navigate with navigation.navigate &lt;code&gt;("Article", { "articleTitle": "Smart Home"})&lt;/code&gt;, so after param merge it will look like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{ 
  "articleTitle": "Smart Home", 
  "articleBody": "Top React Navigation Library"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, Merging behavior is useful in a few scenarios, but it’s problematic in other cases. In React Navigation 6, no more default merge, instead it will be overwritten. If you want merge params then you can do it by explicitly by merge: true 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;navigation.navigate({
  name: “Article”,
  params: { articleTitle: 'Smart Home' },
  merge: true,
});   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Recommended - &lt;a href="https://www.kpiteng.com/blogs/top-10-react-hooks-library"&gt;Top 10 React Hooks Library&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  By default, modals in iOS uses presentation style and in android it uses slide animation -
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;iOS -&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;mode="modal" is removed in favor of presentation: "modal"&lt;/strong&gt;, New presentation options there, allow developers to customer whether screen is modal or screen(basic).&lt;/p&gt;

&lt;p&gt;iOS having &lt;strong&gt;presentation: "modal"&lt;/strong&gt; - which shows a new presentation style modal introduced in iOS 13. It also manages status bar height in the header automatically, that ideally we did manually before.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Android -&lt;/strong&gt;&lt;br&gt;
Previously we didn’t have modal animation in Android, but now there is a slide from the bottom animation. If you don’t want to use new animation then you can change it using &lt;a href="https://reactnavigation.org/docs/6.x/stack-navigator#animations"&gt;animation related options&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;New &lt;strong&gt;presentation: "transparentModal"&lt;/strong&gt; option to make it easier to bulier transparent modals. &lt;strong&gt;Developers can mix regular screens with modal screens in the same stack.&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Recommended - &lt;a href="https://www.kpiteng.com/blogs/improve-react-native-app-performance"&gt;How to improve the performance of React Native Application?&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  Drawer now uses a slide animation by default on iOS -
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Installation -&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;NPM&lt;/strong&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 @react-navigation/drawer@next
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;YARN&lt;/strong&gt;&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 @react-navigation/drawer@next
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is a new implementation based on the Reanimated Library v2, if it’s not available then it will take the old implementation. To force apply to the old implementation using - &lt;code&gt;useLegacyImplementation={true}&lt;/code&gt; to Drawer.Navigator.&lt;/p&gt;

&lt;p&gt;Slide animation is default in iOS, Still you want to keep previous behavior then you can specify, &lt;code&gt;drawerType: "front"&lt;/code&gt; in screenOptions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Headers by default in Drawer &amp;amp; Bottom Tab, No more need to add Stack Navigator -
&lt;/h3&gt;

&lt;p&gt;TabScreen &amp;amp; Drawer now show a header by default similar to the screen in stack navigator.&lt;/p&gt;

&lt;p&gt;If you want previous behavior not to keep the header then you can use, headerShown: false in screenOptions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Material Top Tabs now uses ViewPager based implementation with native experience -
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Installation&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;NPM&lt;/strong&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 @react-navigation/material-top-tabs@next react-native-pager-view
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;YARN&lt;/strong&gt;&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 @react-navigation/material-top-tabs@next react-native-pager-view
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;react-native-tab-view&lt;/code&gt; dependency is upgraded to the latest version (3.x) which now uses &lt;code&gt;react-native-pager-view&lt;/code&gt; instead of Reanimated and Gesture Handler. Same like bottom tabs, the tabBarOptions prop was removed and the options from there were moved to &lt;strong&gt;screen's options&lt;/strong&gt; instead.&lt;/p&gt;

&lt;p&gt;Previously &lt;code&gt;lazy&lt;/code&gt; props is on stack level now shift to lazy per-screen configuration for material top tabs.&lt;/p&gt;

&lt;h3&gt;
  
  
  UI Elements Library with rich feature component to be used in React Navigation -
&lt;/h3&gt;

&lt;p&gt;React Navigation added a new package which contains multiple UI Elements related to navigation like, Header, Header Title, Header Background Component and many more. So developers can use those components in all navigations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installation&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;NPM&lt;/strong&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 @react-navigation/elements@next react-native-safe-area-context
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;YARN&lt;/strong&gt;&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 @react-navigation/elements@next react-native-safe-area-context
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;import&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useHeaderHeight } from '@react-navigation/elements';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://reactnavigation.org/docs/6.x/elements"&gt;Discover Element Library for more details!&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;KPITENG | DIGITAL TRANSFORMATION&lt;br&gt;
&lt;a href="http://www.kpiteng.com/blogs"&gt;www.kpiteng.com/blogs&lt;/a&gt; | &lt;a href="mailto:hello@kpiteng.com"&gt;hello@kpiteng.com&lt;/a&gt;&lt;br&gt;
Connect | Follow Us On - &lt;a href="https://www.linkedin.com/company/kpiteng/"&gt;Linkedin&lt;/a&gt; | &lt;a href="https://www.facebook.com/kpiteng"&gt;Facebook&lt;/a&gt; | &lt;a href="https://www.instagram.com/kpiteng"&gt;Instagram&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactnative</category>
      <category>reactnavigation</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Lerna Workspaces - Managing Projects With Multiple Packages</title>
      <dc:creator>kpiteng</dc:creator>
      <pubDate>Sat, 24 Jul 2021 14:15:29 +0000</pubDate>
      <link>https://dev.to/kpiteng/lerna-workspaces-managing-projects-with-multiple-packages-4bf1</link>
      <guid>https://dev.to/kpiteng/lerna-workspaces-managing-projects-with-multiple-packages-4bf1</guid>
      <description>&lt;p&gt;Lerna workspace allows to create/manage various packages, like app (react application), web (react.js application), common (common business logic/code) needs to be implemented both in react native and react.js.&lt;/p&gt;

&lt;p&gt;Lerna workspace manages versioning so you can create a package for some of your functionality and want to share with other applications then you can easily integrate in other packages by adding that dependency in package.json like you do for other NPM/YARN packages.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/kpiteng/lerna"&gt;Please download full source code from our GitHub.&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Related Article - &lt;a href="https://www.kpiteng.com/blogs/how-to-share-code-between-react-native-and-react-js"&gt;Share Code Between React Native &amp;amp; React.js&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Learn more about &lt;a href="https://www.kpiteng.com/blogs/yarn-workspaces-monorepo-approach"&gt;Yarn Workspaces - Monorepo Approach&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Step by Step Lerna Integration -
&lt;/h3&gt;

&lt;p&gt;If you are using Lerna for the first time, you need to install Lerna Globally.&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 --global lerna
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's start by creating Lerna Project,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx lerna init // initialize lerna workspace
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After finish initialization you will get following folder/files directory,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lerna-workspace
  /packages
  lerna.json
  package.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;packages&lt;/strong&gt; - You can put your web (Web App), app (Mobile App), common (Common Components) inside this directory&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;lerna.json&lt;/strong&gt; - Contain configuration for packages&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;package.json&lt;/strong&gt; - Contain dependency and lerna workspace settings&lt;/p&gt;

&lt;p&gt;Initially in package.json you will get package name "name": "root", we will change it to "name": "@workspace/root", make sure "private": true to share packages under the workspaceSettings.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;package.json&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  - "name": "root",
  + "name": "@workspace/root",
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Now, Go to lerna.json change it to following,&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "packages": [
    "packages/*"
  ],
  + "version": "independent",
  + "npmClient": "yarn",
  + "useWorkspaces": true
 } 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Let's change workspace settings in package.json, Change it to following&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "@workspace/root",
  "private": true,
  "devDependencies": {
      "lerna": "^4.0.0"
  },
  + "workspaces": {
      + "packages": [
      + "packages/**"
      + ]
  + }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have setup everything in lerna.json and package.json, now lets create React.js application and common component directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd packages
npx create-react-app components --template typescript // common component
npx create-react-app app --template typescript // react.js web application
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Monorepo hoist package to root, so dependency you have installed, actually installed on root node_modules instead of node_modules on each app component package.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you see the folder structure, it will looks like,&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lerna-workspace
 /node_modules
 /packages
   /app
      package.json
      ...
   /components
      package.json
      ...
 lerna.json
 package.json
 yarn.lock
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, think you have two application using same components, instead of design &amp;amp; develop components separately, you can add it to /components packages and use that package wherever your want, let's see,&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;create-react-app-config - CRACO - help us to modify web package configuration, so let's install it,&lt;/strong&gt;&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 --dev craco -W
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, Let's change the package name for the app and components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;/packages/app/package.json&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/packages/app/package.json
{
  - "name": "app",
  + "name": "@workspace/app",
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;/packages/components/package.json&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  - "name": "components",
  - "name": "@workspace/components",
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Let's add components dependency into app/package.json&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "dependencies": {
    + "@workspace/components": "0.1.0",
      ...
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;We are using craco, so we need to change few settings in app/package.json scripts to following,&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "scripts": {
    + "start": "craco start",
    + "build": "craco build",
    + "test": "craco test",
    + "eject": "craco eject"
  }
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Now, let's switch to root package.json and add scripts, Lerna has powerful scripts commands if you type build here in root package.json it will build for all child packages at the same instance.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/package.json
{
  + "scripts": {
    + "start": "lerna exec --scope @workspace/app -- yarn start"
  + }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's execute it, execute - yarn start, it will give errors and you can't find the modules craco.config.js which we don't have yet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For instance let's change scripts in /app/package.json to following,&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "scripts": {
    + "start": "react-scripts start"
  }
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And try to execute yarn start it will load your react app successfully. So our web app runs perfectly using lerna workspace.&lt;/p&gt;

&lt;p&gt;Now, let's add a button in the web app and perform increment operation and save count value into state.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;app/src/App.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function App() {
  const [count, setCount] = useState(0);
  return (
    &amp;lt;button
      onClick={() =&amp;gt; setCount((prev) =&amp;gt; ++prev)}
      &amp;gt;
      Increment
    &amp;lt;/button&amp;gt;
  )
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the web app, counter increment works perfectly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now, let's pull button component in components, go to components directory,&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd components
cd src
mkdir components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Create new file Button.tsx inside packages/components/src/components, add following code,&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

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

interface Props {
 onClick: () =&amp;gt; void;
}

const Button: React.FC&amp;lt;Props&amp;gt; = (props) =&amp;gt; {
 return &amp;lt;button {...props}&amp;gt;Increment&amp;lt;/button&amp;gt;;
};

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Now, go to packages/components/src/index.tsx and change to following,&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

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

Let's add to packages/app/src/App.js
+ import { Button } from "@workspace/components";

function App() {
  const [count, setCount] = useState(0);

  console.log(Button);
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;header className="App-header"&amp;gt;
        &amp;lt;img src={logo} className="App-logo" alt="logo" /&amp;gt;
        + Your count is {count}
        + &amp;lt;Button onClick={() =&amp;gt; setCount((prev) =&amp;gt; ++prev)} /&amp;gt;
     &amp;lt;/header&amp;gt;
   &amp;lt;/div&amp;gt;
 );
}

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

&lt;/div&gt;



&lt;p&gt;If you faced any compile error for App.tsx not found then, go to&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;packages/components/package.json and add&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  + "main": "./src/index.tsx"
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;We need to hoist our packages so execute,&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn lerna bootstrap // this will bootstrap application and make shared components/links components
yarn start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After yarn start you will faced error for loaders, because create-react-app webpack contain loaders, so we need to setup following,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd packages/app/
touch craco.config.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;And add the following code in craco.config.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const path = require("path");
const { getLoader, loaderByName } = require("@craco/craco");

const packages = [];
packages.push(path.join(__dirname, "../components"));

module.exports = {
 webpack: {
   configure: (webpackConfig, arg) =&amp;gt; {
     const { isFound, match } = getLoader(
       webpackConfig,
       loaderByName("babel-loader")
     );
     if (isFound) {
       const include = Array.isArray(match.loader.include)
         ? match.loader.include
         : [match.loader.include];

       match.loader.include = include.concat(packages);
     }
     return webpackConfig;
   },
 },
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we have added craco.config.js so let's change scripts settings in /packages/app/package.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "scripts": {
    + "start": "craco start",
  }
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And finally &lt;strong&gt;yarn starts&lt;/strong&gt;, web app works fine with using Button (reusable code) from components package.&lt;/p&gt;

&lt;h1&gt;
  
  
  Lerna Scripts -
&lt;/h1&gt;

&lt;h2&gt;
  
  
  test scripts
&lt;/h2&gt;

&lt;p&gt;Lerna allows you to run scripts and execute wherever you want to do in scripts. Let’s add some test scripts in root /package.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// package.json
{
  + "scripts": {
    + "test": "lerna run test"
  + }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, add scripts in packages,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// packages/app/package.json
{
  + "scripts": {
    + "test": "echo app packages test scripts"
  + }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// packages/components/package.json
{
  + "scripts": {
    + "test": "echo component packages test scripts"
  + }
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if you run test script, lerna run test it will log run test scripts in two packages (app, components) and you will get log following,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lerna info Executing command in 2 packages: "yarn run test"
lerna info run Ran npm script 'test' in '@workspace/components' in 0.5s:
$ echo component packages test scripts
component packages test scripts
lerna info run Ran npm script 'test' in '@workspace/app' in 0.4s:
$ echo app packages test scripts
app packages test scripts
lerna success run Ran npm script 'test' in 2 packages in 0.9s:
lerna success - @workspace/app
lerna success - @workspace/components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  scope scripts
&lt;/h2&gt;

&lt;p&gt;So, you see, lerna runs test scripts in two packages. If you want to test script of specific packages you can do it by giving scope, Change root package.json,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// package.json
{
  + "scripts": {
    + "test": "lerna run test --scope=@workspace/app"
  + }
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let’s run the script &lt;strong&gt;npx run test&lt;/strong&gt;, It will log following,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lerna notice filter including "@workspace/app"
lerna info filter [ '@workspace/app' ]
lerna info Executing command in 1 package: "yarn run test"
lerna info run Ran npm script 'test' in '@workspace/app' in 0.7s:
$ echo app packages test scripts
app packages test scripts
lerna success run Ran npm script 'test' in 1 package in 0.7s:
lerna success - @workspace/app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You see this time script executed in &lt;strong&gt;@workspace/component&lt;/strong&gt; because we have specified scope.&lt;/p&gt;

&lt;p&gt;You can can apply multiple packages in scope by specifying like,&lt;/p&gt;

&lt;h2&gt;
  
  
  scope with multiple packages
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// package.json
{
  + "scripts": {
    + "test": "lerna run test --scope={@workspace/app,@workspace/components}"
  + }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will log following -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lerna notice filter including ["@workspace/app","@workspace/components"]
lerna info filter [ '@workspace/app', '@workspace/components' ]
lerna info Executing command in 2 packages: "yarn run test"
lerna info run Ran npm script 'test' in '@workspace/components' in 0.6s:
$ echo component packages test scripts
component packages test scripts
lerna info run Ran npm script 'test' in '@workspace/app' in 0.3s:
$ echo app packages test scripts
app packages test scripts
lerna success run Ran npm script 'test' in 2 packages in 0.9s:
lerna success - @workspace/app
lerna success - @workspace/components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Lerna Versioning
&lt;/h2&gt;

&lt;p&gt;Lerna contains packages, everytime you build/commit something, it allows you to increment the package version automatically using the following versioning script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  + "scripts": {
    + "new-version": "lerna version --conventional-commits --yes",
  + }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Learn more about &lt;a href="https://www.conventionalcommits.org/en/v1.0.0-beta.2/"&gt;conventional commit&lt;/a&gt; and &lt;a href="https://commitizen.github.io/cz-cli/"&gt;commitzen&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Conventional commit create Git Tag and ChangeLog and Increment package version for you so you can know what you changed in each release/commit. Let’s run a script, but before that commit your code and run the following.&lt;/p&gt;

&lt;p&gt;Execute &lt;strong&gt;npm run new-version&lt;/strong&gt; you will get following logs,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; lerna@1.0.0 new-version /Users/kpiteng/lerna
&amp;gt; lerna version --conventional-commits --yes

lerna notice cli v4.0.0
lerna info current version 1.0.0
lerna info Looking for changed packages since v1.0.0
lerna info getChangelogConfig Successfully resolved preset "conventional-changelog-angular"

Changes:
 - @workspace/app: 1.0.0 =&amp;gt; 1.0.1
 - @workspace/components: 1.0.0 =&amp;gt; 1.0.1

lerna info auto-confirmed 
lerna info execute Skipping releases
lerna info git Pushing tags...
lerna success version finished
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create CHANGELOG.md file for you in both packages, Let’s look it, Go to &lt;strong&gt;/packages/common/CHANGELOG.md&lt;/strong&gt; you will find following,&lt;/p&gt;

&lt;p&gt;/packages/common/CHANGELOG.md,&lt;/p&gt;

&lt;p&gt;If you see packages/app/package.json you will see version incremented,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// packages/app/package.json
{
  "name": "@workspace/app"
  "version": "1.0.1"
}

// packages/components/package.json
{
  "name": "@workspace/components",
  "version": "1.0.1"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  diff scripts
&lt;/h2&gt;

&lt;p&gt;Lerna diff script allows the user to check a screenshot of what exactly changed since the last commit, it is more like Git, Bitbucket - it’s showing what you have changed before the commit. So to do that, lets add script in root package.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// package.json
  {
    "scripts": {
      + "test": "lerna run test --since"
      + "diff": "lerna diff"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, let’s change something in code, go to /packages/app/src/App.js,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// packages/app/src/App.js
function App() {
  + const [counter, setCounter] = useState(0);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let’s run the script npx run diff you will get log following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; lerna@1.0.0 diff /Users/kpiteng/lerna
&amp;gt; lerna diff

lerna notice cli v4.0.0
diff --git a/packages/app/src/App.js

 module.exports = () =&amp;gt; {
   const [count, setCount] = useState(0);
+  const [counter, setCounter] = useState(0);
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/kpiteng/lerna"&gt;Please download full source code from our GitHub.&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;KPITENG | DIGITAL TRANSFORMATION&lt;br&gt;
&lt;a href="http://www.kpiteng.com/blogs"&gt;www.kpiteng.com/blogs&lt;/a&gt; | &lt;a href="mailto:hello@kpiteng.com"&gt;hello@kpiteng.com&lt;/a&gt;&lt;br&gt;
Connect | Follow Us On - &lt;a href="https://www.linkedin.com/company/kpiteng/"&gt;Linkedin&lt;/a&gt; | &lt;a href="https://www.facebook.com/kpiteng"&gt;Facebook&lt;/a&gt; | &lt;a href="https://www.instagram.com/kpiteng"&gt;Instagram&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactnative</category>
      <category>javascript</category>
      <category>appdevelopment</category>
    </item>
    <item>
      <title>Share Code Between React Native and React.js</title>
      <dc:creator>kpiteng</dc:creator>
      <pubDate>Sat, 17 Jul 2021 11:08:31 +0000</pubDate>
      <link>https://dev.to/kpiteng/share-code-between-react-native-and-react-js-50bj</link>
      <guid>https://dev.to/kpiteng/share-code-between-react-native-and-react-js-50bj</guid>
      <description>&lt;p&gt;Hello Developers! Many times we needs to reuse some code between React Native &amp;amp; React.js like state management code (Redux, &lt;a href="https://www.kpiteng.com/blogs/mobx-state-tree"&gt;Mobx&lt;/a&gt;, &lt;a href="https://www.kpiteng.com/blogs/react-native-apollo-graphql"&gt;Apollo Client&lt;/a&gt;), utility &amp;amp; common functions, global constants, api call &amp;amp; common business logic. Today, we will learn to share code between React Native and React.js using Yarn Workspaces.&lt;/p&gt;

&lt;p&gt;If you haven't checkout &lt;a href="https://www.kpiteng.com/blogs/yarn-workspaces-monorepo-approach"&gt;Yarn Workspaces&lt;/a&gt; I request you to check it first where I have explained SetUp Yarn Workspaces step-by-step.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Please download full source code from &lt;a href="https://github.com/kpiteng/react-share-code"&gt;KPITENG GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Yarn Workspaces
&lt;/h3&gt;

&lt;p&gt;Yarn Workspaces allow developers to create workspaces that share packages under the same workspace. Consider you have multiple packages and all are using common dependencies like graphql, axios, etc. To install dependency separately for each package (node_modules), Yarn Workspaces allow you to install packages at root level and you can access that dependency throughout all packages inside that workspaces. So with lots of installation, memory size will be reduced.&lt;/p&gt;

&lt;h3&gt;
  
  
  WML
&lt;/h3&gt;

&lt;p&gt;Consider you have created a few common packages that you need to use for both React, React Native, Server (BackEnd), So whenever you change on common packages you need to add that updated package into your React, React Native node_modules. WML helps you to link your packages to where it is being used.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; wml add common /app/node_modules/@sharecode/common
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command line will copy common packages inside the app's node_modules.&lt;/p&gt;

&lt;h3&gt;
  
  
  nohoist
&lt;/h3&gt;

&lt;p&gt;As discussed earlier in Yarn Workspaces, whatever dependency (npm, node_modules) you were installing for your packages, it will be installed on your root node_modules instead of individual packages. If you checked then react-native packages refer to node_modules inside /app directory. But actually it will be installed on root (node_modules) so to link react-native dependency we are using nohoist which helps you to link your dependency. To do this you need to add few lines of code in your /app/package.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"workspaces": {
   "nohoist": [
     "react-native",
     "react-native/**",
     "react",
     "react/**"
   ]
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Steps by Step Integration
&lt;/h3&gt;

&lt;p&gt;1) Create WorkSpace directory named - ReactShareCode&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;2) Create package.json file and add following lines of code, which contains a list of packages under WorkSpace&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
   "private": true,
   "name": "react-share-code",
   "version": "1.0.0",
   "workspaces":  [
      "app", "web", "common"
   ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we have set up three packages (app, web, common) inside our Workspaces. We have app (React Native App), web (React.js Website), common (Common Code - Which used in React Native &amp;amp; React.js Website)&lt;/p&gt;

&lt;p&gt;Now, let's create three projects, app (react native), web (react.js), common (common code between react &amp;amp; react native)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; npx react-native init app // this will create react native application
&amp;gt; npx create-react-app web // this will create react.js application

&amp;gt; mkdir common // this is our common directory for code share
&amp;gt; cd common

&amp;gt; yarn init -y // this will create package.json file with following code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/common/package.json
{
   "name": "common",
   "version": "1.0.0",
   "description": "...",
   …
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Now, let's change some hierarchy of folder structure. Right now if you see,&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; ls // it will print following
app web common package.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You see, everything are on root folder, let's move app, web, common inside packages folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; mkdir packages

&amp;gt; mv app/ packages/app/
&amp;gt; mv web/ packages/app/
&amp;gt; mv common/ packages/app/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;You can directory drag your app, web, common folder directory to the packages folder. We have changed folder hierarchy, so we need to update root package.json according&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Update react-share-code/package.json file look 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;{
   "private": true,
   "name": "react-share-code",
   "version": "1.0.0",
   "workspaces":  [
      "packages/*"
   ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Till, all going well, If you see packages name it will be like “name”: “app”, “name”: “web”, “name”: “common”, but as per best coding practices we need to append project name, workspace name. So, lets change packages name&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;react-share-code/packages/app/package.json -&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
   - "name": "app",
   + "name": "@sharecode/app"
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;react-share-code/packages/web/package.json -&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
   - "name": "web",
   + "name": "@sharecode/web"
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;react-share-code/packages/common/package.json -&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
   - "name": "common",
   + "name": "@sharecode/common"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;So, we have finish with&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;WorkSpace Creation&lt;/li&gt;
&lt;li&gt;Project Creation (React Native, React.JS)&lt;/li&gt;
&lt;li&gt;Common Folder Creation&lt;/li&gt;
&lt;li&gt;Structure Folder Hierarchy Into packages directory&lt;/li&gt;
&lt;li&gt;Updated packages name&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, let's put some reusable code into a common directory.&lt;/p&gt;

&lt;p&gt;Create file index.js inside common directory and add following line -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const sharedVariable = “Shared Variable”;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's use this in React Native Project, to use code we need to add it as a dependency, So lets update /packages/app/package.json file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
   "devDependencies": {
    + "@sharecode/common": "1.0.0"
   },
   + "workspaces": {
      + "nohoist": [
         + "react-native",
         + "react-native/**",
         + "react",
         + "react/**"
      + ]
   + }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we have added @sharecode/common as a devDependency and added workspaces - nohoist to get reference of react-native.&lt;/p&gt;

&lt;p&gt;Now, lets go to code /app/app.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+ import {sharedVariable} from “@sharecode/common”;

return (
   + &amp;lt;Text&amp;gt;{sharedVariable}&amp;lt;/Text&amp;gt;
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before start running project, let’s remove node_modules both /app and root /node_modules to reinstall packages&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app &amp;gt; rm -rf node_modules ../../node_modules
app &amp;gt; yarn install // install node_modules 

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

&lt;/div&gt;



&lt;p&gt;Now, let's run the react-native app, you will see Text Value “Shared Variable” which is fetched from common logic.&lt;/p&gt;

&lt;p&gt;Same way, lets integrate it into React.js Application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/web/index.js
+ import {sharedVariable} from “@sharecode/common”;

return (
   + &amp;lt;div&amp;gt;{sharedVariable}&amp;lt;/div&amp;gt;
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the react.js application you will get printed “Shared Variable”&lt;/p&gt;

&lt;p&gt;That’s it, you have used the same code between React Native &amp;amp; React.JS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What kind of code you can add into shared/common -&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Redux/Redux Saga/Redux Rematch/Apollo Client/Mobx&lt;/li&gt;
&lt;li&gt;Common API Imports&lt;/li&gt;
&lt;li&gt;Common Themes/ Fonts Settings&lt;/li&gt;
&lt;li&gt;Common Variables/ Constants&lt;/li&gt;
&lt;li&gt;Common API Calls&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can add as much code as you require as per project needs.&lt;/p&gt;

&lt;p&gt;Now, If you have changed anything in your common folder/ code, then to merge your latest common packages we are using WML.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app &amp;gt; wml ../common ./node_modules/@reactsharecode/common 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above command will copy code files of common into app/web node_modules under @reactsharecode/common packages.&lt;/p&gt;

&lt;p&gt;To start linking you can do&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app &amp;gt; wml start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Execute above WML commands whenever you have updated anything into your common packages, WML will merge code into app/node_modules/@reactsharecode/common and web/node_modules/@reactsharecode/common.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Please download full source code from &lt;a href="https://github.com/kpiteng/react-share-code"&gt;KPITENG GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;p&gt;KPITENG | DIGITAL TRANSFORMATION&lt;br&gt;
&lt;a href="http://www.kpiteng.com/blogs"&gt;www.kpiteng.com/blogs&lt;/a&gt; | &lt;a href="mailto:hello@kpiteng.com"&gt;hello@kpiteng.com&lt;/a&gt;&lt;br&gt;
Connect | Follow Us On - &lt;a href="https://www.linkedin.com/company/kpiteng/"&gt;Linkedin&lt;/a&gt; | &lt;a href="https://www.facebook.com/kpiteng"&gt;Facebook&lt;/a&gt; | &lt;a href="https://www.instagram.com/kpiteng"&gt;Instagram&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactnative</category>
      <category>webdev</category>
      <category>mobile</category>
    </item>
    <item>
      <title>Yarn Workspaces - Monorepo Approach</title>
      <dc:creator>kpiteng</dc:creator>
      <pubDate>Fri, 16 Jul 2021 04:03:29 +0000</pubDate>
      <link>https://dev.to/kpiteng/yarn-workspaces-monorepo-approach-354o</link>
      <guid>https://dev.to/kpiteng/yarn-workspaces-monorepo-approach-354o</guid>
      <description>&lt;p&gt;See how Yarn Workspaces allow developers to develop &lt;a href="https://www.kpiteng.com/services/mobile-app-development"&gt;mobile&lt;/a&gt; &amp;amp; &lt;a href="http://www.kpiteng.com/services/web-development"&gt;web applications&lt;/a&gt; using monorepo approach, helps to split and share code between multiple packages.&lt;/p&gt;

&lt;p&gt;Projects grow over time and some pieces of code can be useful elsewhere in other projects. Also we need to share code between projects like Redux, &lt;a href="https://www.kpiteng.com/blogs/react-native-apollo-graphql"&gt;ApolloClient&lt;/a&gt;, &lt;a href="https://www.kpiteng.com/blogs/mobx-state-tree"&gt;MobX&lt;/a&gt; - State Management Library, Common Utilities, etc same for both React Native, React.js or other technologies.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Download full source code from &lt;a href="https://github.com/kpiteng/yarn-workspaces"&gt;KPITENG - Github&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Monorepos
&lt;/h3&gt;

&lt;p&gt;Many of us tried splitting a code into multiple packages knowing how difficult it is to manage across multiple packages at one time. To make this easier, we adopted a monorepo approach, or multiple packages repositories, which reduce the burden of writing code across packages.&lt;/p&gt;

&lt;p&gt;Many projects used by JavaScript developers are managed as monorepos like, Babel, &lt;a href="https://www.kpiteng.com/services/mobile-app-development/react-native-app-development"&gt;React&lt;/a&gt;, Jest, Vue, Angular.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Yarn Workspaces?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://classic.yarnpkg.com/blog/2017/08/02/introducing-workspaces/"&gt;Yarn Workspaces&lt;/a&gt; is a feature that allows users to install dependencies from multiple package.json files in subfolders of a single root package.json file. Let’s say you have React.js &amp;amp; React Native Application and both using Redux, instead of installing Redux into React Native Project and React.js Project, Yarn installs it to root node_modules to reduce the size of project, making it simpler for developers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step By Step Integration
&lt;/h3&gt;

&lt;h5&gt;
  
  
  Set Up Yarn Workspaces -
&lt;/h5&gt;

&lt;p&gt;Let’s create Project Folder Name - &lt;strong&gt;YarnWorkspaces&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a file named package.json, Specify two things&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
   “private”: true,
   “workspaces”: [“common“, “app”, “web”, “server”]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's create folder directory&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Now, let's jump into common folder&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Same way let’s go to server directory&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Go to common folder, Create file index.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = () =&amp;gt; {
   console.log("Hello from KPITENG");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, I have an export function which prints logs.&lt;/p&gt;

&lt;p&gt;Now, let’s go to Server folder and create file index.js and paste following code,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const commonFunction = require('common');
commonFunction();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let’s run this, but it will break because server doesn’t know common exists, to tell server we need to add dependency in server’s package.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"dependencies": {
   "common": “1.0.0”
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's do yarn install to link directory, Go to server directory and trigger,&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Now, let’s check our dependency are properly mapped, Go to root directory do,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; ls // It will print following folder hierarchy
common node_modules package.json server yarn.lock server

&amp;gt; ls node_modules // you can see common server directly inside it
common server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, our dependency property links with workspaces, not let’s try our server/index.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; node server/index.js // It will print following
Hello from KPITENG
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to change any message in common/index.js then it will automatically reflect using symlink&lt;/p&gt;

&lt;p&gt;Let’s change common/index.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = () =&amp;gt; {
   console.log("Welcome to KPITENG");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And trigger,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; node server/index.js // It will print following
Welcome to KPITENG
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Update Package Name - @sharecode
&lt;/h5&gt;

&lt;p&gt;Till everything seems fine, Not it’s time to give a proper naming convention, Generally we prefer to append ProjectName/PackageName, In our case, lets change package name of common,&lt;/p&gt;

&lt;p&gt;Go To - common/package.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  - "name": "common",
  + "name": "@sharecode/common",
}    

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

&lt;/div&gt;



&lt;p&gt;Go To - common/package.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    - "name": "server",
    + "name": "@sharecode/server"
      "dependencies": {
        - "common": "1.0.0"
        + "@sharecode/common": "1.0.0"
      }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go To - server/index.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- const commonFunction = require(“common”)
+ const commonFunction = require(“@sharecode/common”)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's do yarn install to update package&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; yarn install
&amp;gt; node server/index.js // it will log following
Welcome to KPITENG
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Managing Folder Structure / Hierarchy -
&lt;/h5&gt;

&lt;p&gt;Now, you see our common server packages are inside main directory, Let’s shift it to folder packages, let’s create folder packages inside ReactShareCode,&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;And move common and server packages inside it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mv common/ packages/commom/
mv server/ packages/server/
mv app/ packages/app/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We also need to change our package.json from main folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  - "workspaces": ["common", "server"]
  + "workspaces": ["packages/**"]
}    
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, package will be changed, so let's rm node_modules and install again&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; rm -rf node_modules
&amp;gt; cd packages/server
&amp;gt; rm -rf node_modules
&amp;gt; yarn install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will install dependency again with update packages directory&lt;/p&gt;

&lt;p&gt;Now, you can try,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; node packages/server/index.js // It will log following
Welcome to KPITENG
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, If you want to install any dependency for your server packages&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; cd packages/server
&amp;gt; yarn add graphql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will install dependency in root node_modules and it will be added as dependency in server/package.json, It means node_module installed common / root node_modules. Let’s cross check it, Go to root directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; ls
package.json node_modules
&amp;gt; ls node_modules // It will show graphql dependency
@sharecode graphql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It means there is one graphql package that will work for whole workspaces which is very nice in workspaces concept.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Download full source code from &lt;a href="https://github.com/kpiteng/yarn-workspaces"&gt;KPITENG - Github&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  What Next?
&lt;/h3&gt;

&lt;p&gt;Learn, &lt;a href="https://dev.to/kpiteng/share-code-between-react-native-and-react-js-50bj"&gt;Share code between React Native &amp;amp; React.js using Yarn Workspace.&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;KPITENG | DIGITAL TRANSFORMATION&lt;br&gt;
&lt;a href="http://www.kpiteng.com/blogs"&gt;www.kpiteng.com/blogs&lt;/a&gt; | &lt;a href="mailto:hello@kpiteng.com"&gt;hello@kpiteng.com&lt;/a&gt;&lt;br&gt;
Connect | Follow Us On - &lt;a href="https://www.linkedin.com/company/kpiteng/"&gt;Linkedin&lt;/a&gt; | &lt;a href="https://www.facebook.com/kpiteng"&gt;Facebook&lt;/a&gt; | &lt;a href="https://www.instagram.com/kpiteng"&gt;Instagram&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactnative</category>
      <category>vue</category>
      <category>angular</category>
    </item>
    <item>
      <title>Securing React Native Application</title>
      <dc:creator>kpiteng</dc:creator>
      <pubDate>Mon, 12 Jul 2021 13:57:30 +0000</pubDate>
      <link>https://dev.to/kpiteng/securing-react-native-application-b9c</link>
      <guid>https://dev.to/kpiteng/securing-react-native-application-b9c</guid>
      <description>&lt;p&gt;Discover a ways to develop secure react native application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Points -&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Screenshot Prevention&lt;/li&gt;
&lt;li&gt;Rooted/ Jailbroken Device Detection&lt;/li&gt;
&lt;li&gt;SSL Pinning&lt;/li&gt;
&lt;li&gt;Storage of Sensitive Data - API EndPoint / FB / Google / Firebase Keys&lt;/li&gt;
&lt;li&gt;Local Storage&lt;/li&gt;
&lt;li&gt;Deep Linking&lt;/li&gt;
&lt;li&gt;Android Specific Security&lt;/li&gt;
&lt;li&gt;iOS Specific Security&lt;/li&gt;
&lt;li&gt;Authentication Methods&lt;/li&gt;
&lt;li&gt;Data Encryption&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  1. Screenshot Prevention
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;iOS Integration -&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Screenshot Restriction is not possible on Straight Forward Way, But you can do something like, When application InActive - add Blur Layer/ View on window and when Active - remove BlurLayer/View.&lt;/p&gt;

&lt;p&gt;Add Following Lines of Code in AppDelegate.m&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// AppDelegate.m
- (void)applicationWillResignActive:(UIApplication *)application {
    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
    [blurEffectView setFrame:self.window.bounds];
    blurEffectView.tag = 1234;
    blurEffectView.alpha = 0;
    [self.window addSubview:blurEffectView];
    [self.window bringSubviewToFront:blurEffectView];
    [UIView animateWithDuration:0.5 animations:^{
        blurEffectView.alpha = 1;
    }];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    UIVisualEffectView *blurEffectView = [self.window viewWithTag:1234];
    [UIView animateWithDuration:0.5 animations:^{
      blurEffectView.alpha = 0;
    } completion:^(BOOL finished) {
        [blurEffectView removeFromSuperview];
    }];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Android Integration -&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Android it’s quite simple to restrict user to prevent taking screenshot - Go to MainActivity.java&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// MainActivity.java
// Import Following 
+ import android.view.WindowManager;
+ import android.os.Bundle

Add following lines of Code
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+   super.onCreate(savedInstanceState);
+
+   getWindow().setFlags(
+     WindowManager.LayoutParams.FLAG_SECURE,
+     WindowManager.LayoutParams.FLAG_SECURE
+   );
+ }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another way to prevent for screenshot - Go to MainActivity.java, In onCreate method add lines marked as +.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    + getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Rooted/ Jailbroken Device Detection
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;iOS Integration -&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To detect iOS devices is Jailbroken, use following code. You need to create React Native Native Module and integrated iOS Code in iOS Project.&lt;/p&gt;

&lt;p&gt;We will check following to detect Jailbroken devices -&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check if Cydia is installed&lt;/li&gt;
&lt;li&gt;Check if the app can edit system files&lt;/li&gt;
&lt;li&gt;Check if the system contains suspicious files&lt;/li&gt;
&lt;li&gt;Check if other suspicious apps (FakeCarrier, Icy, etc.) is installed&lt;/li&gt;
&lt;li&gt;Check if Cydia is installed with alternative names (using URIScheme)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Foundation
import UIKit

extension UIDevice {
    var isSimulator: Bool {
        return TARGET_OS_SIMULATOR != 0
    }

    var isJailBroken: Bool {
        get {
            if UIDevice.current.isSimulator { return false }
            if JailBrokenHelper.hasCydiaInstalled() { return true }
            if JailBrokenHelper.isContainsSuspiciousApps() { return true }
            if JailBrokenHelper.isSuspiciousSystemPathsExists() { return true }
            return JailBrokenHelper.canEditSystemFiles()
        }
    }
}

private struct JailBrokenHelper {
    //check if cydia is installed (using URI Scheme)
    static func hasCydiaInstalled() -&amp;gt; Bool {
        return UIApplication.shared.canOpenURL(URL(string: "cydia://")!)
    }

    //Check if suspicious apps (Cydia, FakeCarrier, Icy etc.) is installed
    static func isContainsSuspiciousApps() -&amp;gt; Bool {
        for path in suspiciousAppsPathToCheck {
            if FileManager.default.fileExists(atPath: path) {
                return true
            }
        }
        return false
    }

    //Check if system contains suspicious files
    static func isSuspiciousSystemPathsExists() -&amp;gt; Bool {
        for path in suspiciousSystemPathsToCheck {
            if FileManager.default.fileExists(atPath: path) {
                return true
            }
        }
        return false
    }

    //Check if app can edit system files
    static func canEditSystemFiles() -&amp;gt; Bool {
        let jailBreakText = "Developer Insider"
        do {
            try jailBreakText.write(toFile: jailBreakText, atomically: true, encoding: .utf8)
            return true
        } catch {
            return false
        }
    }

    //suspicious apps path to check
    static var suspiciousAppsPathToCheck: [String] {
        return ["/Applications/Cydia.app",
                "/Applications/blackra1n.app",
                "/Applications/FakeCarrier.app",
                "/Applications/Icy.app",
                "/Applications/IntelliScreen.app",
                "/Applications/MxTube.app",
                "/Applications/RockApp.app",
                "/Applications/SBSettings.app",
                "/Applications/WinterBoard.app"
        ]
    }

    //suspicious system paths to check
    static var suspiciousSystemPathsToCheck: [String] {
        return ["/Library/MobileSubstrate/DynamicLibraries/LiveClock.plist",
                "/Library/MobileSubstrate/DynamicLibraries/Veency.plist",
                "/private/var/lib/apt",
                "/private/var/lib/apt/",
                "/private/var/lib/cydia",
                "/private/var/mobile/Library/SBSettings/Themes",
                "/private/var/stash",
                "/private/var/tmp/cydia.log",
                "/System/Library/LaunchDaemons/com.ikey.bbot.plist",
                "/System/Library/LaunchDaemons/com.saurik.Cydia.Startup.plist",
                "/usr/bin/sshd",
                "/usr/libexec/sftp-server",
                "/usr/sbin/sshd",
                "/etc/apt",
                "/bin/bash",
                "/Library/MobileSubstrate/MobileSubstrate.dylib"
        ]
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, don't forget to add "Cydia" in LSApplicationQueriesSchemes key of info.plist. Otherwise canOpenURL will always return false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;key&amp;gt;LSApplicationQueriesSchemes&amp;lt;/key&amp;gt;
&amp;lt;array&amp;gt;
    &amp;lt;string&amp;gt;cydia&amp;lt;/string&amp;gt;
&amp;lt;/array&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Android Integration -&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://github.com/scottyab/rootbeer"&gt;Rootbear&lt;/a&gt; library helps in detection of rooted devices. Simply follow steps of installation and using React Native Native Module you can access Rootbear functions to detection of rooted devices.&lt;/p&gt;

&lt;p&gt;Library will check following to detection of Rooted Devices&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;checkRootManagementApps&lt;/li&gt;
&lt;li&gt;checkPotentiallyDangerousApps&lt;/li&gt;
&lt;li&gt;checkRootCloakingApps&lt;/li&gt;
&lt;li&gt;checkTestKeys&lt;/li&gt;
&lt;li&gt;checkForDangerousProps&lt;/li&gt;
&lt;li&gt;checkForBusyBoxBinary&lt;/li&gt;
&lt;li&gt;checkForSuBinary&lt;/li&gt;
&lt;li&gt;checkSuExists&lt;/li&gt;
&lt;li&gt;checkForRWSystem&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's simple to integrate in Code -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RootBeer rootBeer = new RootBeer(context);
if (rootBeer.isRooted()) {
    //we found indication of root
} else {
    //we didn't find indication of root
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;SafetyNet&lt;/strong&gt; Android-only API that helps in the detection of rooted devices and bootloader unlocks. It also provides security against security threats, device tampering, malicious apps, and fake users.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://www.npmjs.com/package/react-native-google-safetynet"&gt;react-native-google-safetynet&lt;/a&gt;, which is a wrapper plugin for SafetyNet’s API, can also be used to verify the device of the user. The react-native-device-info plugin can be used to see if the app is being run on an emulator.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. SSL Pinning
&lt;/h3&gt;

&lt;p&gt;SLL Pinning can be done using 3 different ways&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Public Key Pinning&lt;/li&gt;
&lt;li&gt;Certificate Pinning&lt;/li&gt;
&lt;li&gt;Subject Public Key Info (SPKI) Pinning&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;iOS Integration -&lt;/strong&gt; Place your .cer files in your iOS Project. Don't forget to add them in your Build Phases - Copy Bundle Resources, in Xcode&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Android Integration -&lt;/strong&gt; Place your .cer files under src/main/assets/&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Certificate Pinning With react-native-ssl-pinning -&lt;/strong&gt;&lt;br&gt;
iOS - drag .cer to Xcode project, mark your target and "Copy items if needed"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch(url, {
  method: "POST" ,
  timeoutInterval: communication_timeout, // milliseconds
  body: body,
  // your certificates array (needed only in android) ios will pick it automatically
  sslPinning: {
    certs: ["cert1","cert2"] // your certificates name (without extension), for example cert1.cer, cert2.cer
  },
  headers: {
    Accept: "application/json; charset=utf-8", "Access-Control-Allow-Origin": "*", "e_platform": "mobile",
  }
})
.then(response =&amp;gt; {
  console.log("response received:", response);
})
.catch(err =&amp;gt; {
  console.log("error:", err);
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Public Key Pinning With react-native-ssl-pinning -&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;iOS -&lt;/strong&gt; drag .cer to Xcode project, mark your target and "Copy items if needed". No Extra steps needed for public key pinning. AFNetworking will extract public key directly from certificate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Android -&lt;/strong&gt; public key should be extracted by following command, simply replace google with your domain.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;openssl s_client -servername google.com -connect google.com:443 | openssl x509 -pubkey -noout | openssl rsa -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {fetch} from 'react-native-ssl-pinning';

fetch("https://publicobject.com", {
  method: "GET" ,
  timeoutInterval: 10000, // milliseconds
  // your certificates array (needed only in android) ios will pick it automatically
  pkPinning: true,
  sslPinning: {
    certs: [
      "sha256//r8udi/Mxd6pLOS73Djkex2EP4nFnIWXCqeHsTDRqy8=",
    ]
  },
  headers: {
    Accept: "application/json; charset=utf-8", "Access-Control-Allow-Origin": "*", "e_platform": "mobile",
  }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Certificate Pinning With react-native-pinch -&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

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

pinch.fetch('https://my-api.com/v1/endpoint', {
  method: 'post',
  headers: { customHeader: 'customValue' },
  body: '{"firstName": "Jake", "lastName": "Moxey"}',
  timeoutInterval: 10000 // timeout after 10 seconds
  sslPinning: {
    cert: 'cert-file-name', // cert file name without the .cer
    certs: ['cert-file-name-1', 'cert-file-name-2'], // optionally specify multiple certificates
  }
})
  .then(res =&amp;gt; console.log("response -", res);)
  .catch(err =&amp;gt; console.log("error -",err);)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Storage of Sensitive Data - API EndPoint / FB / Google / Firebase Keys
&lt;/h3&gt;

&lt;p&gt;Never store your API EndPoint, AccessKey, Firebase, Google/FB Social Key directly into Code. Your bundle can be decoded into plaintext and all information can be extracted.&lt;/p&gt;

&lt;p&gt;It’s recommended to use &lt;a href="https://github.com/luggit/react-native-config/"&gt;react-native-config&lt;/a&gt; and &lt;a href="https://github.com/goatandsheep/react-native-dotenv"&gt;react-native-dot-env&lt;/a&gt; to place your secure key, endpoint.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; react-native-config module doesn’t encrypt secrets for packaging, so do not store sensitive keys in .env file.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Local Storage
&lt;/h3&gt;

&lt;p&gt;Developer often needs to store data locally, sometime developer prefer asyncstorage to store accesskey/ access-token/ user token. But AsyncStorage is un-encrypted storage, so information can be extract from AsyncStorage.&lt;/p&gt;

&lt;p&gt;React Native does not provide solution for secure data storage. There are pre-existing solution in iOS &amp;amp; Android we all know about iOS Keychain and Android Keystore.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.apple.com/documentation/security/keychain_services"&gt;iOS Keychain -&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In iOS we use Keychain Services which allows developers to securely store sensitive information like certificates, tokens, securekeys, passwords, and any other sensitive information like secrets of open platform services which we are using in our application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.android.com/training/articles/keystore"&gt;Android Keystore -&lt;/a&gt;&lt;br&gt;
The Android Keystore allows developers to store cryptographic keys in a container to make it more difficult to extract from the device. Once keys are in the keystore, they can be used for cryptographic operations with the key material remaining non-exportable.&lt;/p&gt;

&lt;p&gt;To use iOS Keychain &amp;amp; Android Secure Shared Preferences from React Native, you can use following NPM.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;react-native-encrypted-storage&lt;/li&gt;
&lt;li&gt;react-native-keychain&lt;/li&gt;
&lt;li&gt;redux-persist-sensitive-storage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; redux-persist-sensitive-storage uses react-native-sensitive-info with redux-persist. react-native-sensitive-info manages all data stored in Android Shared Preferences and iOS Keychain. Android Shared Preferences are not secure, but there is a branch of react-native-sensitive-info that uses the Android key-store instead of shared preferences. You can use that branch with redux-persist-sensitive-storage if you prefer.&lt;/p&gt;
&lt;h3&gt;
  
  
  6. Deep Linking
&lt;/h3&gt;

&lt;p&gt;Deep linking is a way to open application from other sources. Deep Link contains textual data along with Link. Like &lt;strong&gt;yourappname://&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's say you have E-Commerce application and your deep link is yourappname://products/1 means it will open your app with detail of product 1.&lt;/p&gt;

&lt;p&gt;Deep links are not secure and you should not append any sensitive information in deep link.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security issues while dealing with deep linking -&lt;/strong&gt;&lt;br&gt;
There is no centralised method of registering URL schemes. As developer, you can use any URL scheme you choose by configuring it in Xcode for iOS or adding an intent on Android.&lt;/p&gt;

&lt;p&gt;Malicious app can hijack your data by also &lt;strong&gt;using the same scheme&lt;/strong&gt; and then obtaining access to the data your link contains. Sending something like &lt;strong&gt;yourappname://products/1&lt;/strong&gt; is not harmful, but sending tokens is a security concern.&lt;/p&gt;

&lt;p&gt;iOS allows one single URL Scheme to be claimed by multiple apps. For instance, sample:// can be used by two completely separate apps in their implementation of URL Schemes. This is how some malicious apps can take advantage of the URL Scheme and compromise users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security solutions to overcome deep linking security issue -&lt;/strong&gt;&lt;br&gt;
Apple introduced Universal Links in iOS 9 as a solution to the lack of graceful fallback functionality in custom URI scheme deep links. Universal Links are standard web links that point to both a web page and a piece of content inside an app.&lt;/p&gt;

&lt;p&gt;When a Universal Link is opened, iOS checks to see if any installed app is registered for that domain. If so, the app is launched immediately without ever loading the web page. If not, the web URL (which can be a simple redirect to the App Store) is loaded in Safari.&lt;/p&gt;

&lt;p&gt;Setting up a universal link (HTTP or HTTPS) login interface, and musing a random identifier to authenticate the received login token locally, prevents hijacking and malicious login token replaying.&lt;/p&gt;
&lt;h3&gt;
  
  
  7. Android Specific Security
&lt;/h3&gt;

&lt;p&gt;Let’s see how to protect our APK or app bundle from reverse engineering attacks.&lt;/p&gt;

&lt;p&gt;Hackers can easily access our Codebase by doing reverse engineering with APK or app bundle file. To avoid it we can add Pro Guard rules. Pro Guard obfuscates your code. So if someone reverse engineer it, it’s not readable and saves you from engineering attacks. Pro Guard also used to reduces APK size by removing unused code and resources. If your project contain any third party library then you can add the Pro Guard rules of that library in your rules file.&lt;/p&gt;

&lt;p&gt;To enable Pro Guard rule we have to enable the minifyEnabled property in app/build.gradle file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;buildTypes {
    release: {
       minifyEnabled true
    }
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  8. iOS Specific Security
&lt;/h3&gt;

&lt;p&gt;Let’s see how we can restrict the insecure domains usage in iOS. It will save us from transport layer attacks. You can restrict insecure domains by configuring some properties within your Info.plist file.&lt;/p&gt;

&lt;p&gt;Now, let’s see what you should add in your Info.plist file for that.&lt;/p&gt;

&lt;p&gt;From iOS 9.0 Apple has introduced NSAppTransportSecurity which you can find inside info.plist file. Inside &lt;strong&gt;NSAppTransportSecurity&lt;/strong&gt; there is one key NSAllowArbitraryLoads which is set to NO by default that means you are agreed with security benefits. In some cases while you are working with localhost or with HTTP domain if required then you have to make it YES otherwise you can’t make network request with those insecure domains.&lt;/p&gt;

&lt;p&gt;There are chances that your app might get rejected while uploading it to apple store because you set NSAllowArbitraryLoads value as YES. To overcome that you can use NSExceptionDomains by providing a list of domains inside that. Application will consider like you have agreed to all over security benefits excepts the domain those domains which you have mentioned in NSExceptionDomains (although you have set NSAllowArbitraryLoads value as YES).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;key&amp;gt;NSAppTransportSecurity&amp;lt;/key&amp;gt;
&amp;lt;dict&amp;gt;
  &amp;lt;key&amp;gt;NSAllowsArbitraryLoads&amp;lt;/key&amp;gt;
  &amp;lt;true/&amp;gt;
  &amp;lt;key&amp;gt;NSExceptionDomains&amp;lt;/key&amp;gt;
  &amp;lt;dict&amp;gt;
    &amp;lt;key&amp;gt;localhost&amp;lt;/key&amp;gt;
    &amp;lt;dict&amp;gt;
      &amp;lt;key&amp;gt;NSExceptionAllowsInsecureHTTPLoads&amp;lt;/key&amp;gt;
      &amp;lt;true/&amp;gt;
    &amp;lt;/dict&amp;gt;
  &amp;lt;/dict&amp;gt;
&amp;lt;/dict&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  9. Authentication Methods
&lt;/h3&gt;

&lt;p&gt;Nowadays OAuth has become more popular for Authentication between one application interacting with another application. Consider a case where your application communicates with an API to send/retrieve data from the server. How do servers know the coming request is authenticated? OAuth 2.0 makes the authentication process simple for you. Instead of sharing passwords OAuth allows authentication using Token. It's an approach to use &lt;a href="https://jwt.io/"&gt;JWT Token&lt;/a&gt; for API Authentication.&lt;/p&gt;

&lt;h3&gt;
  
  
  10. Data Encryption
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/crypto-js"&gt;Crypto JS&lt;/a&gt; is popular Javascript library for crypto standards. To store, send data to server it's approched to Encrypt data using CrytpJS. So, it's is not redable by enable directly.&lt;/p&gt;

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

&lt;p&gt;KPITENG | DIGITAL TRANSFORMATION&lt;br&gt;
&lt;a href="http://www.kpiteng.com/blogs"&gt;www.kpiteng.com/blogs&lt;/a&gt; | &lt;a href="mailto:hello@kpiteng.com"&gt;hello@kpiteng.com&lt;/a&gt;&lt;br&gt;
Connect | Follow Us On - &lt;a href="https://www.linkedin.com/company/kpiteng/"&gt;Linkedin&lt;/a&gt; | &lt;a href="https://www.facebook.com/kpiteng"&gt;Facebook&lt;/a&gt; | &lt;a href="https://www.instagram.com/kpiteng"&gt;Instagram&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactnative</category>
      <category>security</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Top 10 React Tricks Every Developer Should Use</title>
      <dc:creator>kpiteng</dc:creator>
      <pubDate>Sun, 04 Jul 2021 08:04:29 +0000</pubDate>
      <link>https://dev.to/kpiteng/top-10-react-tricks-every-developer-should-use-8nj</link>
      <guid>https://dev.to/kpiteng/top-10-react-tricks-every-developer-should-use-8nj</guid>
      <description>&lt;p&gt;Discover a set of React best coding practices, tips and tricks that should be known by all &lt;a href="https://www.kpiteng.com/services/mobile-app-development/react-native-app-development"&gt;developers&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Points -&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use State Management Library (Redux, MobX, Apollo)&lt;/li&gt;
&lt;li&gt;Use Event Listener instead of Static Method&lt;/li&gt;
&lt;li&gt;Remove All Listener In UnMount&lt;/li&gt;
&lt;li&gt;Config for Environment Setup || Test || Live || Staging&lt;/li&gt;
&lt;li&gt;Use Context for Themes management Dark || Live Theme&lt;/li&gt;
&lt;li&gt;Use Storybook - Isolated | | Reusable Component Development&lt;/li&gt;
&lt;li&gt;Minimize use of third-party library || Instead create own Code Logic&lt;/li&gt;
&lt;li&gt;Scale and Resize Images || Cache Images&lt;/li&gt;
&lt;li&gt;Firebase Performance Monitoring&lt;/li&gt;
&lt;li&gt;Avoid re-rendering using useMemo, useCallBack&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  1. Use State Management Library (Redux, MobX, Apollo)
&lt;/h4&gt;

&lt;p&gt;Many times we are using local variables, array, objects declarations that are specific to components but what happens the same would be used in other components then, Use State Management Library so you can access your variables, array, objects though the app, you can update and listen for change in any component.&lt;/p&gt;

&lt;p&gt;Redux, Redux Saga, Redux Rematch, &lt;a href="https://www.kpiteng.com/blogs/mobx-state-tree"&gt;MobX State Tree&lt;/a&gt;, &lt;a href="https://www.kpiteng.com/blogs/react-native-apollo-graphql"&gt;Apollo&lt;/a&gt; are popular state management libraries which allow developers to access State Variables through the app and it will persist your data so next time the user comes back to application data fetched from storage and assigned to state variables.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Use Event Listener instead of Static Method
&lt;/h4&gt;

&lt;p&gt;We are on one component and we want to call one function of the previous component or any other component at that time we are using static methods in the class component. Instead of using Static Method I approach using React Native Event Listeners. You can add a listener in a component where you want to listen and emit an event from where you want to call a function. It’s very simple to integrate.&lt;/p&gt;

&lt;p&gt;Check out &lt;a href="https://www.npmjs.com/package/react-native-event-listeners"&gt;react-native-event-listeners&lt;/a&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 --save react-native-event-listeners
or
yarn add react-native-event-listeners
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { EventRegister } from 'react-native-event-listeners'

/*
 * RECEIVER COMPONENT
 */
class Receiver extends PureComponent {
    constructor(props) {
        super(props)

        this.state = {
            data: '',
        }
    }

    componentWillMount() {
        this.listener = EventRegister.addEventListener('yourEventName', (data) =&amp;gt; {
            this.setState({
                data,
            })
        })
    }

    componentWillUnmount() {
        EventRegister.removeEventListener(this.listener)
    }

    render() {
        return &amp;lt;Text&amp;gt;{this.state.data}&amp;lt;/Text&amp;gt;
    }
}

/*
 * SENDER COMPONENT
 */
const Sender = (props) =&amp;gt; (
    &amp;lt;TouchableHighlight
        onPress={() =&amp;gt; {
            EventRegister.emit(‘yourEventName’, ‘Task Completed!’)
        })
    &amp;gt;&amp;lt;Text&amp;gt;Send Event&amp;lt;/Text&amp;gt;&amp;lt;/TouchableHighlight&amp;gt;
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Remove All Listener In UnMount
&lt;/h4&gt;

&lt;p&gt;We are adding listeners to listen events like KeyboardListeners, EventListeners, NavigationEventListeners, TabEventListeners etc. When you add listeners on componentWillMount it will create listeners for you, but if you forget to remove it on componentWillUnMount then next-time when you back to component again it will create another listener object which conflicts with memory leaks and unexpected listeners behaviour. So best is to remove listeners in componentWillUnMount to it will free out memory and provide you un-interrupted behaviour.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Related Article - See how &lt;a href="https://www.kpiteng.com/blogs/react-clean-architecture"&gt;React Clean Architecture&lt;/a&gt; helps to write Clean, Structured, Modularized and Best Coding Practices for Rect Developers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  4. Config for Environment Setup || Test || Live || Staging
&lt;/h4&gt;

&lt;p&gt;We are all using different environments like Test, Staging, Production/Live environment. There are different API URLs, Constant Variables, Keys, etc depending on Environment. So It’s recommended to use react-native-config to setup your configuration for Test, Stage and Live environment. Please follow steps provided in &lt;a href="https://www.npmjs.com/package/react-native-config"&gt;react-native-config&lt;/a&gt; and manage your environment.&lt;/p&gt;

&lt;h4&gt;
  
  
  5. Use Context for Themes management Dark || Live Theme
&lt;/h4&gt;

&lt;p&gt;Nowadays we are used to Light &amp;amp; Dark themes, developers also developing applications that support both Light &amp;amp; Dark Themes. But being developers how we manage Styles, how to add/manage listeners. It’s recommended to manage themes using React Context API, you can set up Context in App.js and add Themes Listener in App.js so whenever a user changes theme App.js get notified and themes will be changed and all the components will be notified. So you can provide instant themes that change the effect to your users.&lt;/p&gt;

&lt;h4&gt;
  
  
  6. Use Storybook - Isolated || Reusable Component Development
&lt;/h4&gt;

&lt;p&gt;Almost every application has components like TextInput, Button, etc that are used at various components. Instead of doing separate code for each component it’s recommended to create a common component and use it in Components, advantage of doing this you can manage it from one place and it will reflect your changes in the whole application.&lt;/p&gt;

&lt;p&gt;What happens if I say show me the component you developed and change it’s property dynamically like color, etc, you need to import/implement it in one component and run the application, correct? Is there any way I can see all Reusable Components in one place, I can play with it, change various props and validate it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.kpiteng.com/blogs/storybook-design-share-component"&gt;Storybook&lt;/a&gt; will provide an interface where you see all your developed ReUsable components at one place. For that you simply create Story and improve your component into your Story. So the Storybook will render all the stories. It’s very simple to integrate. Please check out the Storybook article for more detail.&lt;/p&gt;

&lt;h4&gt;
  
  
  7. Minimize use of third-party library || Instead create own Code Logic
&lt;/h4&gt;

&lt;p&gt;We are using too many third-party library, NPMs in our application for Small - Small tasks. Problem is whenever iOS, Android, React Native version upgrade we forget to upgrade our library, NPMs which break our application, Even we are not sure, Creator of Library, NPMs have updated with latest standard &amp;amp; security which cause break in our application.&lt;/p&gt;

&lt;p&gt;Instead of using Third-Party Library, NPMs for Small-Small cases, it’s recommended to create your own code solution and so you can manage it, update it easily.&lt;/p&gt;

&lt;h4&gt;
  
  
  8. Scale and Resize Images || Cache Images
&lt;/h4&gt;

&lt;p&gt;Image optimization is very important in React Native App Performance. If you have an E-Commerce kind application or Application where there is maximum Image Rendering and images are not optimized then it will consume more user’s memory which causes application crashes.&lt;br&gt;
It’s recommend to do following -&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use PNG image instead of JPG&lt;/li&gt;
&lt;li&gt;Use small resolution images&lt;/li&gt;
&lt;li&gt;Use the latest WEBP format for Image - which helps to reduce binary size of iOS and Android.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cache Images - &lt;br&gt;
While having an ECommerce Or Heavy Image Showcase kind application it’s recommended to use Image Caching to show images faster without flickering. Prefer to use &lt;a href="https://github.com/DylanVann/react-native-fast-image"&gt;React Native Fast Image&lt;/a&gt; which works perfectly for both iOS &amp;amp; Android.&lt;/p&gt;

&lt;h4&gt;
  
  
  9. Firebase Performance Monitoring
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://rnfirebase.io/perf/usage"&gt;Firebase Performance Monitoring&lt;/a&gt; helps developers to identify where and when performance can be improved, so that you can fix those performance issues and give consistent experience to users. It allows you to track HTTP Request Performance Traces, also you can do custom tracing according to your business needs.&lt;/p&gt;

&lt;p&gt;It’s simple in integration and you will get a dashboard with reports. That's simple.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Related Article - &lt;a href="https://www.kpiteng.com/blogs/improve-react-native-app-performance"&gt;How to improve the performance of a React Native App?&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  10. Avoid re-rendering using useMemo, useCallBack
&lt;/h4&gt;

&lt;p&gt;Almost all applications have FlatList along with other components like Button, TextInput. FlatList reload FlatListItem on first time render, also whenever any of the state variables changes FlatList will reload again with It’s FlatListItem. These are unwanted re-rendering, actually nothing changed on FlatList Item. To avoid these re-rendering use useMemo hooks that will first check any of the props changed then only it will reload FlatListItem.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Related Article - Step By Step Integration Of &lt;a href="https://www.kpiteng.com/blogs/react-hooks"&gt;React Hooks&lt;/a&gt;  - useState, useEffect, useRef, useMemo, useCallback.&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;p&gt;KPITENG | DIGITAL TRANSFORMATION&lt;br&gt;
&lt;a href="http://www.kpiteng.com/blogs"&gt;www.kpiteng.com/blogs&lt;/a&gt; | &lt;a href="mailto:hello@kpiteng.com"&gt;hello@kpiteng.com&lt;/a&gt;&lt;br&gt;
Connect | Follow Us On - &lt;a href="https://www.linkedin.com/company/kpiteng/"&gt;Linkedin&lt;/a&gt; | &lt;a href="https://www.facebook.com/kpiteng"&gt;Facebook&lt;/a&gt; | &lt;a href="https://www.instagram.com/kpiteng"&gt;Instagram&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactnative</category>
      <category>security</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to improve the performance of a React Native App?</title>
      <dc:creator>kpiteng</dc:creator>
      <pubDate>Mon, 28 Jun 2021 03:13:21 +0000</pubDate>
      <link>https://dev.to/kpiteng/how-to-improve-the-performance-of-a-react-native-app-188p</link>
      <guid>https://dev.to/kpiteng/how-to-improve-the-performance-of-a-react-native-app-188p</guid>
      <description>&lt;p&gt;See how you will boost your &lt;a href="https://www.kpiteng.com/services/mobile-app-development/react-native-app-development/"&gt;react native app&lt;/a&gt; performance, improve start-up time, decrease bundle size &amp;amp; memory usage.&lt;/p&gt;

&lt;h5&gt;
  
  
  Key Points -
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Hermes&lt;/li&gt;
&lt;li&gt;Avoid re-rendering using useMemo&lt;/li&gt;
&lt;li&gt;Cache Images&lt;/li&gt;
&lt;li&gt;Use nativeDriver with Animated Library&lt;/li&gt;
&lt;li&gt;State Management With Redux/MobX/Apollo&lt;/li&gt;
&lt;li&gt;Remove Console Log&lt;/li&gt;
&lt;li&gt;Optimize Android App Size&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  1. Hermes
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://reactnative.dev/docs/hermes"&gt;Hermes&lt;/a&gt; is an open-source JavaScript engine optimized for React Native. Hermes integration helps to improve start-up time, decreased memory usage, and smaller app size.&lt;/p&gt;

&lt;p&gt;With Hermes your app will start at 2x speed, memory usage will decrease to 30%, android app bundle size decreased 30%, iOS Application performance will boost.&lt;/p&gt;

&lt;p&gt;Let’s see how to integrate &lt;a href="https://hermesengine.dev/"&gt;Hermes&lt;/a&gt;. Hermes supports iOS support after the 0.64 version. So make sure you upgrade your app using &lt;a href="https://react-native-community.github.io/upgrade-helper/?from=0.59.0"&gt;React Native Upgrade Helper&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Enabling Hermes -
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Android -&lt;/strong&gt;&lt;br&gt;
Add following code line In android/app/build.gradle&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;project.ext.react = [
  entryFile: "index.js",
-     enableHermes: false  // clean and rebuild if changing
+     enableHermes: true  // clean and rebuild if changing
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you're using ProGuard, add following rules in proguard-rules.pro :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-keep class com.facebook.hermes.unicode.** { *; }
-keep class com.facebook.jni.** { *; }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Clean the build&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd android &amp;amp;&amp;amp; ./gradlew clean
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;iOS -&lt;/strong&gt;&lt;br&gt;
Edit ios/Podfile file with below code lines -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use_react_native!(
  :path =&amp;gt; config[:reactNativePath],
  # to enable hermes on iOS, change false to true and then install pods
-    :hermes_enabled =&amp;gt; false
+    :hermes_enabled =&amp;gt; true
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install the Hermes pod&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ios &amp;amp;&amp;amp; pod install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s it, Now create your iOS &amp;amp; Android build and see application start-up speed, memory usage, and specially bundle size.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Avoid re-rendering using useMemo
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.kpiteng.com/blogs/react-hooks"&gt;useMemo hooks&lt;/a&gt; helps developers to avoid re-rendering of child components to improve the performance of react application. useMemo is used to handle memoization, meaning if any component receives the same props more than once, it will use previously cached props and render the JSX view and return component.&lt;/p&gt;

&lt;p&gt;In the sample below I have taken FlatList and Button. First time Flatlist renders perfectly. Now when user pressed button new setCount will update state variable and whole component getting reloaded with FlatList even no values updated in Array. To avoid this I have wrapped FlatListItem (UseMemoListItem) with useMemo, so useMemo checks if any change in props then only it will render the JSX else it will return render &amp;amp; return the view previous props.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const technology = [
  { name: 'React Native' },
  { name: 'React.js' },
  { name: 'Next.js' },
 ];
 const [arrTechnology, setArrTechnology] = useState(technology);
 const [count, setCount] = useState(0);

 function UseMemoListItem({item, onChange, arrTechnology}) {
  return useMemo(() =&amp;gt; {
    return (
      &amp;lt;View style={Styles.container}&amp;gt;
        &amp;lt;Text&amp;gt;{item.name}&amp;lt;/Text&amp;gt;
      &amp;lt;/View&amp;gt;
    );
  }, [item.status]);
 }

  return (
    &amp;lt;View style={Styles.container}&amp;gt;
      &amp;lt;Button title='Increment' onPress={() =&amp;gt; setCount(count + 1)} /&amp;gt;
      &amp;lt;FlatList
        data={arrTechnology}
        keyExtractor={(item) =&amp;gt; String(item.name)}
        renderItem={({item, index}) =&amp;gt; (
          &amp;lt;UseMemoListItem
            item={item}
          /&amp;gt;
        )}
        ItemSeparatorComponent={() =&amp;gt; &amp;lt;UseMemoListItemSeprator /&amp;gt;}
        showsVerticalScrollIndicator={false}
      /&amp;gt;
    &amp;lt;/View&amp;gt;
  );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Cache Images
&lt;/h3&gt;

&lt;p&gt;React Native Image component allow developers to display Images in application, still there is few issues like -&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rendering number of Image (Product List - ECommerce Application)&lt;/li&gt;
&lt;li&gt;Low performance in Caching Image Loading&lt;/li&gt;
&lt;li&gt;Image flickering&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To solve this issue React Native support in-build caching for &lt;a href="https://reactnative.dev/docs/images#cache-control-ios-only"&gt;iOS&lt;/a&gt; by enabling following lines of code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Image
  source={{
    uri: 'https://example.com/image.png',
    cache: 'only-if-cached'
  }}
  style={{ width: 400, height: 400 }}
/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But, what to do for Android, there is a popular third-party library named - &lt;a href="https://github.com/DylanVann/react-native-fast-image"&gt;react-native-fast-image&lt;/a&gt; which will work perfect for iOS &amp;amp; Android. Using Fast Image you can give quick image rendering, caching mechanism and many more to application users.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import FastImage from 'react-native-fast-image'

const YourImage = () =&amp;gt; (
    &amp;lt;FastImage
        style={{ width: 200, height: 200 }}
        source={{
            uri: 'https://yourimageurl.com/image.png',
            headers: { Authorization: 'token' },
            priority: FastImage.priority.normal,
        }}
        resizeMode={FastImage.resizeMode.contain}
    /&amp;gt;
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Use nativeDriver with Animated Library
&lt;/h3&gt;

&lt;p&gt;We are using animations in our Application, but sometimes it will not run smoothly as expected which impacts application render performance. To avoid flicker and run smooth animation, &lt;a href="https://reactnative.dev/docs/animated"&gt;useNativeDriver&lt;/a&gt; which send animation to native bridge before animation start on component. This helps animations to be executed on separate javascript instance, which resulting in smoother animation.&lt;/p&gt;

&lt;p&gt;It’s very simple to integration - &lt;strong&gt;useNativeDriver: true&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Animated.timing(this.state.animatedValue, {
  toValue: 1,
  duration: 500,
  useNativeDriver: true, // &amp;lt;-- Add this
}).start();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. State Management With Redux/MobX/Apollo
&lt;/h3&gt;

&lt;p&gt;Many times it is required to manage data locally means caching data which shows immediately to the user without interruption whenever the user comes back to the application. We are using AsyncStorage, Local Database Storage to store data and when the user comes back next time/ open application next time we are fetching data and keeping it in Global variables to access anywhere in the application.&lt;/p&gt;

&lt;p&gt;To manage this in various screens and storing data into various arrays, object Prefer popular State Management Library like Redux, Redux Rematch, &lt;a href="https://www.kpiteng.com/blogs/mobx-state-tree"&gt;MobX&lt;/a&gt; and &lt;a href="https://www.kpiteng.com/blogs/react-native-apollo-graphql"&gt;Apollo&lt;/a&gt;. These library will storage | mange | retrieve data for you and you can easily access throughout the app without any interruption.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Remove Console Log
&lt;/h3&gt;

&lt;p&gt;All we are using &lt;strong&gt;console.log('Hello KPITENG!')&lt;/strong&gt; to debug applications. While deploying an application if we keep console.log() then it will create performance issues due to javascript thread.&lt;/p&gt;

&lt;p&gt;To remove console.log in Production, following simple installation and setup.&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 babel-plugin-transform-remove-console
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, modify the .babelrc file to remove the console statements, as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "env": {
    "production": {
      "plugins": ["transform-remove-console"]
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  7. Optimize Android App Size
&lt;/h3&gt;

&lt;p&gt;React Native Android apps contain -&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Resources such as images, fonts, etc.&lt;/li&gt;
&lt;li&gt;Four different binaries compiled for different CPU architectures&lt;/li&gt;
&lt;li&gt;Javascript bundle with business logic&lt;/li&gt;
&lt;li&gt;Other in-built files&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While you are building an app this will combine all these and create a binary for you. To &lt;a href="https://reactnative.dev/docs/signed-apk-android#enabling-proguard-to-reduce-the-size-of-the-apk-optional"&gt;optimize binary size Android build&lt;/a&gt; in React Native by adding below line&lt;/p&gt;

&lt;p&gt;Update following line in android/app/build.gradle&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def enableProguardInReleaseBuilds = true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to extract four different binary according your CPU architecture then,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def enableSeparateBuildPerCPUArchitecture = true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;KPITENG | DIGITAL TRANSFORMATION&lt;br&gt;
&lt;a href="http://www.kpiteng.com/blogs"&gt;www.kpiteng.com/blogs&lt;/a&gt; | &lt;a href="mailto:hello@kpiteng.com"&gt;hello@kpiteng.com&lt;/a&gt;&lt;br&gt;
Connect | Follow Us On - &lt;a href="https://www.linkedin.com/company/kpiteng/"&gt;Linkedin&lt;/a&gt; | &lt;a href="https://www.facebook.com/kpiteng"&gt;Facebook&lt;/a&gt; | &lt;a href="https://www.instagram.com/kpiteng"&gt;Instagram&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactnative</category>
      <category>performance</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Axios vs Fetch</title>
      <dc:creator>kpiteng</dc:creator>
      <pubDate>Tue, 22 Jun 2021 16:48:43 +0000</pubDate>
      <link>https://dev.to/kpiteng/axios-vs-fetch-1eh5</link>
      <guid>https://dev.to/kpiteng/axios-vs-fetch-1eh5</guid>
      <description>&lt;p&gt;Hello &lt;a href="https://www.kpiteng.com/services/mobile-app-development/react-native-app-development"&gt;Developers&lt;/a&gt;! All we are using either Axios OR fetch to communicate/exchange data with server. Both works perfect as per your requirement. Today we will go in detail and see how they are differ in terms of features they provide.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Request URL
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Axios&lt;/strong&gt; — has url in request object&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;axios
  .get(url, {
    headers: {
      'Content-Type': 'application/json',
    },
    timeout: 1000 * 60,
  })
  .then(res =&amp;gt; {

  })
  .catch(err =&amp;gt; {

  })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Fetch&lt;/strong&gt; — has no url in request object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; fetch(url)
  .then((response) =&amp;gt; response.json())
  .then((json) =&amp;gt; {  

  })
  .catch(() =&amp;gt; {

  })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Package
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Axios&lt;/strong&gt; — third-party package that you need to install manually. 85.3k Star in Github — Well managed &amp;amp; rich features library.&lt;br&gt;
&lt;code&gt;npm i axios&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Fetch&lt;/strong&gt; — is in-build into most of the browser, no more need of installation.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. CSRF Protection
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Axios&lt;/strong&gt; — having in-build support of CSRF (Cross site request forgery) to prevent cross-site request.&lt;br&gt;
&lt;strong&gt;Fetch&lt;/strong&gt; — doesn’t support CSRF&lt;/p&gt;
&lt;h3&gt;
  
  
  4. Request Data
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Axios&lt;/strong&gt; — request data contain object, you can directly sent JSON Object in request data&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;axios
  .post(url, jsonObject, {
    headers: {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
    },
    timeout: 1000 * 60, // 1 min
  })
  .then((res) =&amp;gt; {
    if (res) {
      return res.data;
    }
  })
  .catch((err) =&amp;gt; {
    return err;
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Fetch&lt;/strong&gt; — request data should stringify&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch(url, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify(jsonObject),
})
.then((response) =&amp;gt; response.json())

.then((json) =&amp;gt; {

})
.catch(() =&amp;gt; {

});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;If you want to start New React Project — Check out &lt;a href="https://www.kpiteng.com/blogs/react-clean-architecture"&gt;React Clean Architecture&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  5. Response Parsing
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Axios&lt;/strong&gt; — in-built transform response to JSON for &lt;br&gt;
developers&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;axios
  .post(url, jsonObject, {
    headers: {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
    },
    timeout: 1000 * 60, // 1 min
  })
  .then(res =&amp;gt; {
    if (res) {
      return res.data; // Directly get JSON in Step - 1 Only - Managed by Axios
    }
  })
  .catch(err =&amp;gt; {
    return err;
  })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;fetch&lt;/strong&gt; — has two step process, first response convert to json and then in second process developer will get json response&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch(url, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(jsonObject)
}).then((response) =&amp;gt; response.json()) // Response Convert To JSON in this Step - 1
  .then((json) =&amp;gt; {
    // Get JSON Object Here in Step - 2
  })
  .catch(() =&amp;gt; {


  })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  6. Cancel Request
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Axios&lt;/strong&gt; — In case user left the screen/component, axios allow developers to Cancel request&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const cancelTokenSource = axios.CancelToken.source();

 axios.get('/listing/1', {
  cancelToken: cancelTokenSource.token
 });

 // Cancel request
 cancelTokenSource.cancel();
 Fetch - doesn’t support Cancel API request
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Fetch&lt;/strong&gt; — doesn’t support Cancel API request&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Request Interceptor
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Axios&lt;/strong&gt; — having in-build feature of intercept HTTP Request&lt;br&gt;
&lt;strong&gt;Fetch&lt;/strong&gt; — Doesn’t provide a way to intercept http requests.&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Upload/Download Request Progress
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Axios&lt;/strong&gt; — Support developers to provide data transmission progress so developers can show loading indicator while user communicating with server&lt;br&gt;
&lt;strong&gt;Fetch&lt;/strong&gt; — Doesn’t support Upload/Download progress&lt;/p&gt;

&lt;h3&gt;
  
  
  9. Browser Support
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Axios&lt;/strong&gt; — have side browser capability support&lt;br&gt;
&lt;strong&gt;Fetch&lt;/strong&gt; — only support limited browsers &amp;amp; version , like Chrome 42+, Firefox 39+, Edge 14+, Safari 10.1.&lt;/p&gt;

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

&lt;p&gt;KPITENG | DIGITAL TRANSFORMATION&lt;br&gt;
&lt;a href="http://www.kpiteng.com/blogs"&gt;www.kpiteng.com/blogs&lt;/a&gt; | &lt;a href="mailto:hello@kpiteng.com"&gt;hello@kpiteng.com&lt;/a&gt;&lt;br&gt;
Connect | Follow Us On - &lt;a href="https://www.linkedin.com/company/kpiteng/"&gt;Linkedin&lt;/a&gt; | &lt;a href="https://www.facebook.com/kpiteng"&gt;Facebook&lt;/a&gt; | &lt;a href="https://www.instagram.com/kpiteng"&gt;Instagram&lt;/a&gt;&lt;/p&gt;

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