<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Subhash Dhandhukiya on Medium]]></title>
        <description><![CDATA[Stories by Subhash Dhandhukiya on Medium]]></description>
        <link>https://medium.com/@subhash.dhandhukiya?source=rss-dc99b7da7f93------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*fQzVaHZCSmprUq8M</url>
            <title>Stories by Subhash Dhandhukiya on Medium</title>
            <link>https://medium.com/@subhash.dhandhukiya?source=rss-dc99b7da7f93------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 13:12:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@subhash.dhandhukiya/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Introducing The React Profiler]]></title>
            <link>https://medium.com/@subhash.dhandhukiya/introducing-the-react-profiler-d8749ec1983b?source=rss-dc99b7da7f93------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8749ec1983b</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[react-profiler]]></category>
            <dc:creator><![CDATA[Subhash Dhandhukiya]]></dc:creator>
            <pubDate>Mon, 06 Mar 2023 03:33:50 GMT</pubDate>
            <atom:updated>2023-03-06T03:33:50.109Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cC9PQ00bv1_1CePwcttLhg.jpeg" /></figure><p>nowadays, React comes with new particular capabilities, and inspects the higher overall performance of our React Application. So in this blog, we are going to study React Profiler, The tool which helps us to improve our application.</p><p>In cutting-edge days, the arena going too speedy then why do our applications stay back, why do our programs work slowly? There are some elements that make our software slower and the main factor is “Re-Rendering”.</p><p>The React Profiler offers us data where we will discover which element takes how much time and also get statistics on how generally components get re-render.</p><h3><strong>Profiling an application</strong></h3><p>There are methods available to do Profiling for our React software.</p><ol><li>React Developer Tools ( Chrome extension)</li><li>Profiler API</li></ol><p><strong>NOTE: </strong>Make sure that your react-dom version is above 16.5.</p><p>Nowadays, we have the ability to use the React DevTools Profiler to profile our React applications and improve their performance. So first we want to put in React Developer equipment as an extension of Chrome. you may get a concept from the photo underneath.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*5UL1pCknltd92Bgm" /></figure><p>The Profiler Tab is empty first of all. There are several alternatives to be had for show statistics in specific approaches and also with exclusive records. After beginning the React utility, we must open checkout mode in chrome and can get some options with a profiler. you may get a concept from the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*jAUCpRKi9zPC-t6F" /></figure><p>there may be two ways to begin recording, First, click on the blue button to begin recording and the other way is to press the refresh button that’s right after the blue button. as soon as finished recording you need to press the stop button which is in red color. you may get a concept from the underneath picture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*lO3ncKk5IVksaIwZ" /></figure><h3><strong>Reading Performace data</strong></h3><p>The React Profiler collects statistics inside the commit segment and groups the overall performance info with the aid of a commit. The commits are displayed in a bar chart under the photograph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*-TKvqfm-LgXIrhM6" /></figure><p>you can see right here, the Profiler collects all information of every commit and shows like this. there may be a few exceptional meanings for each color. the colors suggest how lots time is taken via the specific factor.</p><ul><li>Yellow — The component took more time to render.</li><li>Blue — The component comparatively took much less time to render.</li><li>Gray — The component did not render at all during the commit.</li></ul><p>using this, we will get the concept of which factor takes lots of time to render, and with the usage of memoization, we can reduce the cost of needless re-rendering and make our utility faster.</p><h3><strong>Filtering Commits:</strong></h3><p>The longer you profile, the more time your utility renders and collects extra commits. The Profiler presents us to filter the devotion via a selected time. you could get the idea from the below photo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/0*d31RoDBL-jnoW0h0" /></figure><h3>Chart:</h3><p>The Profiler provides us with numerous charts of commits and the list of them is under.</p><ul><li>Flame Chart</li><li>Ranked Chart</li><li>Component Chart</li></ul><p>Let’s deep dive into these charts and understand them.</p><h4>Flame Chart:</h4><p>This view represents the state of your application for a single commit. you can see in the picture, every bar has represented a component, and the bar width represents how a lot of time is taken by using the particular element.</p><p>by clicking on the bar, you may get the unique rendering facts for the thing and additionally get the time duration of a particular rendering. you can see into the picture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*0FDiOrOzqQEdggTw" /></figure><h4>Ranked Chart</h4><p>within the profiler, you will get the Ranked Tab at the top. Press on it. It shows us a ranked chart and this chart is primarily based on how much time is taken by the component. you’ll get all charts on the top which took greater time and on the down, you’ll get that factor which took much less time.</p><p>on this chart, additionally get all facts like time taken by using the component for render and how long it takes to render, and so on. you can see the below photograph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*qzwxP-oXx1PU3xuo" /></figure><h4>Component Chart:</h4><p>Double-clicking on a component will help you view the component chart. This view will provide statistics approximately the component lifecycle for the duration of the profiling time. The data is displayed in the form of a bar chart wherein every bar shows at what time the particular element became rendered and the length of the bat suggests for a way lengthy it turned into rending.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*dZ_kHoh48FklOPLz" /></figure><h3>Troubleshooting:</h3><h4>No profiling data has been recorded for the selected root:</h4><p>In case your software has multiple roots then you will get this type of message after profiling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*pKgFPlZTMne5r6LE" /></figure><p>that means after completing profiling, no performance records became recorded or amassed for the selected root. Do once more profiling with distinct roots.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/0*4GQNWPhD7gNNyICD" /></figure><h4>No timing data to display for the selected commit</h4><p>from time to time a dedication can be so speedy that’s why DevTools don’t show any meaningful timing statistics. In this sort of case, you will get this form of massage, see the below picture.</p><h3><strong>Summary</strong></h3><p>The React Profiler is a powerful tool that can help developers improve the performance of their React applications by identifying performance bottlenecks and optimizing components.</p><p>I hope you enjoyed the reading and perhaps even learned something new.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8749ec1983b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Make Custom Hooks In React Native]]></title>
            <link>https://medium.com/@subhash.dhandhukiya/how-to-make-custom-hooks-in-react-native-d5ff7e4b655f?source=rss-dc99b7da7f93------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5ff7e4b655f</guid>
            <category><![CDATA[custom-hook]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Subhash Dhandhukiya]]></dc:creator>
            <pubDate>Sun, 17 Jul 2022 07:07:47 GMT</pubDate>
            <atom:updated>2022-07-17T07:07:47.207Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*byF4YDSMRBwtKi0wWgiqAQ.png" /></figure><h3>What is Hooks?</h3><p>Hooks are a new feature introduced in The React 16.8 version. It is used for writing code without class. The hooks are only used in functional components.</p><h3>Rules of Hooks</h3><ul><li>Hooks can only be called inside React function components.</li><li>Hooks can only be called at the top level of a component.</li><li>Hooks cannot be conditional.</li></ul><p><strong>Note: Hooks will not work in React class components.</strong></p><h3>Build a Hook</h3><p>now we will make new hooks in our React native app.</p><p>In the following code, we will fetch data into our App.js file. and we will fetch JSONPlaceholder API using our custom hook.</p><p>First, We have created one file <em>useFetch.js </em>in our src folder. In this file we have to write the below code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*zUNyhRWC9bcjJzwdWun2aA.png" /></figure><p>here, we made one function whose name is useFetch. we have to use the “use” keyword before the function name because another developer can identify this as a hook. It is not necessary to add the “use” keyword. you can write as you like as a function name.</p><p>So In this function, we passed a URL of our API. and then added two states for storing data of API response and also for loading.</p><p>we add URL as a dependency for useEffect which means when the URL change it will call and update the state.</p><p>and last return that state into an array.</p><h3>Use a Custom hook in our code</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*vZ9I92Z2UEPItxKNtVHBOQ.png" /></figure><p>Just import our custom hook where we like to use it. So you can see into the code.</p><p>We pass the API into the hook and it will give us two data, one is the loading state, and the second is the response of the API which we passed into the useFetch.</p><p>Now we can reuse this custom Hook in any component to fetch data from any URL.</p><h3>Summary</h3><p>This blog is for the custom hook, like how to make it and how to use it anywhere in our project. it basically reduces our code size and is easy to use.</p><p>I hope you enjoyed the reading and perhaps even learned something new.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5ff7e4b655f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to get data from AWS Bucket using Node js]]></title>
            <link>https://medium.com/@subhash.dhandhukiya/how-to-get-data-from-aws-bucket-using-node-js-f86af3012e4d?source=rss-dc99b7da7f93------2</link>
            <guid isPermaLink="false">https://medium.com/p/f86af3012e4d</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Subhash Dhandhukiya]]></dc:creator>
            <pubDate>Tue, 24 May 2022 04:43:54 GMT</pubDate>
            <atom:updated>2022-06-20T04:48:54.827Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*x2g9IGqgJlkpWCK0-Gwh5w.jpeg" /></figure><h3>What is AWS S3?</h3><p>Amazon S3 is Simple storage where we can store all data like video, images, code, etc or any kind of data and when we want any amount of information back from the bucket we are able to latch on easily and anywhere from that bucket. Amazon S3 gives us plenty of space to store data.</p><p>We can store data on an S3 bucket for up to 5TB.</p><h3>AWS S3 Benefits</h3><p>Some of the benefits of AWS S3 are:</p><ul><li>Durability: AWS S3 Bucket provides around 100% durability.</li><li>Low cost: S3 allows you to store data in an exceeding range of “storage classes.” These classes are based on the frequency and immediacy you need in accessing files.</li><li>Security: S3 offers a powerful range of access management tools and encryption features that provide top-notch security.</li><li>Flexibility: S3 is right for a good range of uses like data storage, data backup, software delivery, data archiving, disaster recovery, website hosting, mobile applications, IoT devices, and far more.</li><li>You don’t need an excessive amount of IT knowledge to execute data transfers on S3. This service is extremely simple and straightforward to use.</li></ul><h3>Install npm package</h3><pre>npm i aws-sdk</pre><p>After the entire installation npm package writes the below code to induce an object from the S3 bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*CgwZkZcEO-XQYl-KuOmI2w.png" /></figure><h3>Summary</h3><p>This concludes a function that may give all bucket data which you pass into the function.</p><p>I hope you enjoyed the reading and perhaps even learned something new.</p><p>Please also read <a href="https://medium.com/p/daeb906a3aaf">Send Direct SMS from React Native app using React Native Bridge</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f86af3012e4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Send Direct SMS from React Native App using React Native Bridge]]></title>
            <link>https://medium.com/@subhash.dhandhukiya/send-direct-sms-from-react-native-app-using-react-native-bridge-daeb906a3aaf?source=rss-dc99b7da7f93------2</link>
            <guid isPermaLink="false">https://medium.com/p/daeb906a3aaf</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react-native-bridge]]></category>
            <dc:creator><![CDATA[Subhash Dhandhukiya]]></dc:creator>
            <pubDate>Mon, 25 Apr 2022 04:50:04 GMT</pubDate>
            <atom:updated>2022-04-25T04:50:04.489Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w_gYqkemfeDONaQpWvrSJQ.png" /></figure><h3>What is a bridge in React Native?</h3><p>The Native Side should be Java or Kotlin for Android and Swift or Objective-C for iOS.</p><p>The huge reason for the popularity of React Native is that a bridge can be created between the JavaScript code and Native language. React Native is developed in a manner in which we can produce a bridge between the JavaScript code and the Native Language. The Bridge in React Native permits the JavaScript code and the Native code to interact with each other. Without the bridge in React Native, there is absolutely no means for the native code to transmit any information to the JavaScript code and vise versa.</p><p><strong>Need of Bridge in React Native:</strong> Suppose we need to reutilize a few existing Java libraries without implementing them again in JavaScript. So, we can reutilize it in our React Native application with the use of Native Bridge. Sometimes, to build an application of the production level, we will most likely need to use Native Bridge.</p><h3>What’s a Native Module?</h3><p>A native module is a set of javascript functions that are implemented natively for each platform (in our case iOS and Android). It is used in cases where native capabilities are needed, that react-native doesn’t have a corresponding module yet, or when the native performance is better.</p><h3>Send Direct SMS from React Native App</h3><p>In this example, we will write some native Java code to send the SMS from your Android App and will trigger the same from React Native. An example will have a simple screen with 2 inputs, one for the mobile number and one for the SMS body. Once your click on “Send Message” after inserting the mobile number (Including zero[0]) and SMS body, we will pass the values in the native code and will trigger the native code to send the SMS directly. Hope you will like it.</p><h3>Java Native Code</h3><h4>1. Create MySendSmsModule.java</h4><p>In <strong>android/app/src/main/java/com/yourProject</strong> next to the <strong>MainActivity.java</strong> create a java class that extends the ReactContextBaseJavaModule class and paste the below code. Please remember to change the package name “com.rnpractice” with your package name. You can find the package name on the top of <strong>MainActivity.java</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*i4aqQQIMCN5xnysfSNsfUQ.png" /></figure><h3>2. Create MySendSmsPackage.java</h3><p>The next step in Java is to register the module, if a module is not registered it will not be available from JavaScript. For the registration of created module, create a new class next to the MySendSmsModule.java with the name <strong>MySendSmsPackage.java</strong> and paste the below code. Please remember to change the package name “com.rnpractice” with your package name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*C-CwsAvCTquydf5nt7LfGw.png" /></figure><p>We Override the <strong><em>createNativeModules</em></strong> function and added the <strong><em>MySendSmsModule</em></strong> object to the modules array. It needs to be added here to be available in javascript.</p><h3>3. Register MySendSmsPackage in MainApplication.java</h3><p>Above <strong><em>MySendSmsPackage</em></strong><em> </em>needs to be provided in the <strong><em>getPackages </em></strong>method of the <strong><em>MainApplication.java</em></strong> file. Just import the <strong><em>MySendSmsPackage</em></strong> and add in <strong><em>ReactPackage</em></strong>. Please look at the “// Add This Line” comment in the below sample.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*L2Vgcj2Vdx1rM7Xxcm0W0g.png" /></figure><h3>Android Permission</h3><p>To send a text message from Android you need to add the following permission in <strong>AndroidManifest.xml</strong></p><pre>&lt;<strong>uses-permission</strong> android:name=”android.permission.SEND_SMS”/&gt;</pre><h3>React Native Code</h3><p>If everything went well then you are ready with your native module. To use this native code in React Native just import the <strong>NativeModules</strong> component from react-native</p><p>Let’s see React Native code to trigger our native code.</p><p>Now Open App.js in any code editor and replace the code with the following code</p><h3>App.js</h3><pre>import React,{useState} from &#39;react&#39;<br>import {<br>  SafeAreaView,<br>  StyleSheet,<br>  View,<br>  Text,<br>  TouchableOpacity,<br>  TextInput,<br>  NativeModules,<br>  PermissionsAndroid,<br>} from &#39;react-native&#39;;</pre><pre>let DirectSms = NativeModules.DirectSms;</pre><pre>const DirectSMSTest = () =&gt; {</pre><pre>const [mobileNumber, setMobileNumber] = useState(&#39;&#39;);<br>const [bodySMS, setBodySMS] = useState(&#39;This is Test Message&#39;);</pre><pre>const sendDirectSms = async () =&gt; {<br>   if (mobileNumber) {<br>      try { <br>         const granted = await PermissionsAndroid.request(     <br>              PermissionsAndroid.PERMISSIONS.SEND_SMS,<br>              {<br>                title: &#39;Send SMS App Sms Permission&#39;,<br>                message:&#39;Send SMS App needs access to your inbox so <br>                         you can send messages in background&#39;,<br>                buttonNegative: &#39;Ask Me Later&#39;,<br>                buttonNegative: &#39;Cancel&#39;,<br>                buttonPositive: &#39;OK&#39;,<br>              },<br>           );</pre><pre>           if (granted === PermissionsAndroid.RESULTS.GRANTED) {<br>             DirectSms.sendDirectSms(mobileNumber, bodySMS);<br>           } else {<br>             alert(&#39;SMS permission denied&#39;);<br>           }</pre><pre>      } catch (error) {<br>          console.warn(error);<br>         alert(error);<br>      }<br>    }<br>  };</pre><pre>   return (<br>      &lt;SafeAreaView style={styles.container}&gt;<br>        &lt;View style={styles.container}&gt;<br>          &lt;Text style={styles.titleText}&gt; <br>                React Native Bridge Example for Android to Send  <br>                Direct SMS<br>          &lt;/Text&gt;<br>          &lt;Text style={styles.titleTextsmall}&gt;<br>               Enter Recipients Number<br>          &lt;/Text&gt;</pre><pre>          &lt;TextInput<br>              value={mobileNumber}<br>              onChangeText={mobileNumber =&gt; <br>                          setMobileNumber(mobileNumber)}<br>              placeholder={&#39;Enter Conatct Number to Call&#39;}<br>              keyboardType=&quot;numeric&quot;<br>              style={styles.textInput}<br>          /&gt;</pre><pre>          &lt;Text style={styles.titleTextsmall}&gt;Enter SMS Body&lt;/Text&gt;</pre><pre>          &lt;TextInput<br>              value={bodySMS}<br>              onChangeText={bodySMS =&gt; setBodySMS(bodySMS)}<br>              placeholder={&#39;Enter SMS body&#39;}<br>              style={styles.textInput}<br>           /&gt;</pre><pre>          &lt;TouchableOpacity<br>              activeOpacity={0.7}<br>              style={styles.buttonStyle}<br>              onPress={sendDirectSms}<br>           &gt;<br>              &lt;Text style={styles.buttonTextStyle}&gt;Send  <br>                Message&lt;/Text&gt;<br>         &lt;/TouchableOpacity&gt;<br>       &lt;/View&gt;<br>     &lt;/SafeAreaView&gt;<br>   );</pre><pre>};</pre><pre>export default DirectSMSTest;</pre><pre>const styles = StyleSheet.create({</pre><pre>    container: {<br>       flex: 1,<br>       backgroundColor: &#39;white&#39;,<br>       padding: 10,<br>       textAlign: &#39;center&#39;,<br>    },<br>    titleText: {<br>       fontSize: 22,<br>       textAlign: &#39;center&#39;,<br>       fontWeight: &#39;bold&#39;,<br>       marginBottom: 16,<br>    },<br>    titleTextsmall: {<br>       marginVertical: 8,<br>       fontSize: 16,<br>    },<br>    buttonStyle: {<br>       justifyContent: &#39;center&#39;,<br>       marginTop: 15,<br>       padding: 10,<br>       backgroundColor: &#39;#8ad24e&#39;,<br>    },<br>    buttonTextStyle: {<br>       color: &#39;#fff&#39;,<br>       textAlign: &#39;center&#39;,<br>    },<br>    textInput: {<br>       height: 40,<br>       borderColor: &#39;gray&#39;,<br>       borderWidth: 1,<br>       width: &#39;100%&#39;,<br>       paddingHorizontal: 10,<br>    },<br> });</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=daeb906a3aaf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use Jest testing in React Native]]></title>
            <link>https://medium.com/@subhash.dhandhukiya/how-to-use-jest-testing-in-react-native-48703105a814?source=rss-dc99b7da7f93------2</link>
            <guid isPermaLink="false">https://medium.com/p/48703105a814</guid>
            <category><![CDATA[react-native-development]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[jest]]></category>
            <dc:creator><![CDATA[Subhash Dhandhukiya]]></dc:creator>
            <pubDate>Sun, 20 Mar 2022 11:24:30 GMT</pubDate>
            <atom:updated>2022-03-20T11:24:30.158Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nxSvYeFzLGLIMl6cj-kQsQ.png" /></figure><h3><strong>What is Jest?</strong></h3><p>Jest is a JavaScript testing framework maintained by Meta (formerly Facebook), designed and built by Christoph Nakazawa with a focus on simplicity and support for large web applications. It works with projects using Babel, TypeScript, Node.js, React, Angular, Vue.js, and Svelte. Jest doesn’t require a lot of configuration for first-time users of a testing framework.</p><p>Jest ships as an NPM package, you can install it in any JavaScript project. Jest is <strong>one of the most popular test runners these days</strong> and the default choice for React projects.</p><h3>Setting up the project</h3><p><a href="https://aboutreact.com/getting-started-with-react-native/"><strong>Getting started with React Native</strong></a> will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command-line utility. Open the terminal and go to the workspace and run.</p><pre>npm install -g react-native-cli</pre><p>Run the following commands to create a new React Native project</p><pre>react-native init ProjectName</pre><h3>Integration of Jest</h3><p>To install the dependencies open the terminal and jump into your project using.</p><pre>cd ProjectName</pre><p>For the Jest testing we need to install and setup the jest module</p><pre>npm i jest --save-dev</pre><p>Let’s also configure an NPM script for running our tests from the command line. Open up package.json and configure a script named test for running Jest:</p><pre>&quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;jest&quot;<br>  },</pre><p>and you’re good to go!</p><h3>Project Structure</h3><p>In the project root directory, make a <strong>tests</strong> folder. This folder will store all the test files.</p><p>Note that the js files(which are to be tested) are mapped by their names. <br>For example, <strong>index.js</strong> is mapped to <strong>index.test.js</strong>. This index.test.js file is placed in the ‘tests’ folder. This is the conventional project structure.</p><h3>Start Testing</h3><p>We will use the <strong>‘expect’</strong> method to test our functions. The functions can also be tested using <strong>‘describe’</strong> and <strong>‘it’</strong></p><p><strong>‘it’</strong> and <strong>‘test’ </strong>both are the same.</p><p><strong>A basic test:</strong> adding two positive nums and checking result.</p><pre>//index.js<br>testForAdd: (a, b) =&gt; { return (a + b) },<br><br>//index.test.js<br>describe(&quot;Sum function&quot;, () =&gt; {<br>  test(&#39;test adding two positive nums&#39;, function() {<br>     expect(testFns.testForAdd(4, 5)).toBe(9);<br>  });<br>}</pre><p>After writing the code, we need to run this command.</p><pre>npm test index.test.js</pre><p>When the <em>‘</em>npm test index.test.js<em>’</em> is run, the <strong>index.test.js</strong> file is gone through. Then the testForAdd function is run which is placed in the <em>‘testFns’</em> object. The toBe is used to <em>‘match’</em> the returned response from the test to what is expected. This ‘result matching’ leads to either a <strong>‘fail’</strong> or a <strong>‘pass’</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*sdRm7Ut3LFvZ8OtmG_ns1A.png" /></figure><h3>Testing For React Component</h3><p>Write the below code into the index.js file</p><pre>// index.js</pre><pre>import React from &#39;react&#39;;<br>import {View,Text,TextInput} from &#39;react-native&#39;;</pre><pre>export default class App extends React.Component{<br>   constructor(){<br>     super();<br>     this.state = {<br>       data:&#39;test&#39;;<br>     }<br>   }</pre><pre>render(){<br>    return(<br>      &lt;View style={{flex:1}}&gt;<br>        &lt;TextInput<br>            testID={&#39;username&#39;}<br>            onChangeText={text =&gt; this.change(text)}<br>            style={{backgroundColor: &#39;grey&#39;, marginBottom: 15}}<br>            placeholder=&quot;Enter Username&quot;<br>         /&gt;<br>      &lt;/View&gt;<br>     )}</pre><p>Write the below code into the index.test.js file</p><pre>// index.test.js</pre><pre>import React from &#39;react&#39;;<br>import {View,Text,TextInput} from &#39;react-native&#39;;<br>import App from &#39;index.js&#39;</pre><pre>it(&#39;Render Correctly&#39;,()=&gt;{<br>  const tree = renderer.create(&lt;App/&gt;).toJSON();<br>  expect(tree).toMatchSnapshot();</pre><pre>})</pre><p>After writing the code, we need to run this command.</p><pre>npm test index.test.js</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*_Cw1CzTr6TsNeI9x8T627g.png" /></figure><h3>Conclusions and resources</h3><p><strong>Testing is a big and fascinating topic</strong>. There are many types of tests and many libraries for testing. In this Jest tutorial, <strong>you learned</strong> how to configure Jest for <strong>coverage</strong> reporting, how to organize and write a simple <strong>unit test</strong>, and how to test JavaScript code.</p><p>To learn more about Jest matchers check out the <a href="https://jestjs.io/docs/en/getting-started">documentation</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48703105a814" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Block Taking Screenshots in React Native]]></title>
            <link>https://medium.com/@subhash.dhandhukiya/how-to-block-taking-screenshots-in-react-native-9978f9decf6a?source=rss-dc99b7da7f93------2</link>
            <guid isPermaLink="false">https://medium.com/p/9978f9decf6a</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Subhash Dhandhukiya]]></dc:creator>
            <pubDate>Sun, 23 Jan 2022 15:18:34 GMT</pubDate>
            <atom:updated>2022-01-23T15:18:34.121Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wTW-l3JaJTcpIa9u4YjSYw.png" /></figure><h3>Screenshot Prevention in Mobile App</h3><p>There can be many use-cases where we want to prevent screenshot taking in React Native app, like if we have any temporary QR code generation functionality where we don’t want users to take screenshots. One thing which should be mentioned here is, you should not depend completely upon this functionality to secure your data. Users can also capture the image from another mobile device, so plan things accordingly.</p><p>Let’s see how you can restrict a user to taking screenshots for Android and iOS</p><h3>Screenshot Prevention for Android App</h3><p>Android system provides a built-in mechanism for blocking screenshots which is available from Android Honeycomb (3.0). It literally takes one line of code to put in Activity which you’d like to prevent to be screenshotted. It totally disables this functionality (instead of a screenshot, the user will see the nice error message). Additionally, it blocks all the screen recording options (only the black screen is visible as the output) which is a really great add-on.</p><p>We just need to add the following piece of code to prevent screen capturing.</p><blockquote><strong>getWindow</strong>().setFlags( <strong>WindowManager</strong>.LayoutParams.FLAG_SECURE, <strong>WindowManager</strong>.LayoutParams.FLAG_SECURE );</blockquote><p>Here are the steps to restrict screenshot capturing in React Native App (Android)</p><p>1. Open <strong>your-project -&gt; android -&gt; app -&gt; src -&gt; main -&gt; java -&gt; com -&gt; your-project-name -&gt; MainActivity.java</strong></p><p>2. Add the following imports</p><blockquote><strong>import</strong> <strong>android</strong>.view.WindowManager;</blockquote><blockquote><strong>import</strong> <strong>android</strong>.os.Bundle;</blockquote><p>Add following <strong>onCreate</strong> function</p><blockquote>@<strong>Override</strong> protected void onCreate(Bundle savedInstanceState) { <strong>super</strong>.onCreate(<strong>savedInstanceState</strong>); <strong>getWindow</strong>().setFlags( <strong>WindowManager</strong>.LayoutParams.FLAG_SECURE, <strong>WindowManager</strong>.LayoutParams.FLAG_SECURE ); }</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*lCKLDdg1rhY_lOTljwISLQ.png" /></figure><h3>Screenshot Prevention for iOS App</h3><p>If we talk about iOS then let me clear you one thing, we have tried mostly everything available out there but the result is, we can not restrict a user to taking screenshots in iOS by adding any piece of code or using any hack.</p><p>After looking at some more things we found there is a way to get the detail of the screenshot taken, but it will be triggered only after the user capture the screenshot.</p><pre><strong>class</strong> ViewController: UIViewController {<br>  override func viewDidLoad() {<br>    <strong>super</strong>.viewDidLoad()<br>      NotificationCenter.default.addObserver(<br>        forName: UIApplication.userDidTakeScreenshotNotification, <br>        object: nil, queue: nil) { _ <strong>in</strong><br>          print(&quot;Hey, You have captured a screenshot&quot;)<br>      }<br>  }<br>}</pre><p>With the help of this, we only get the detail of screenshots taken but can’t restrict it. We thought what if we can delete the captured screenshot after this trigger, but iOS does not allow any file to delete from the external app so it wasn’t working.</p><p>After trying so many things we found that there is no way to restrict the screenshot for iOS until and unless you are ready to pay for it :p</p><p>If you want 100% protection against screenshots in iOS then you can use <a href="https://screenshieldkit.com/">ScreenShieldKit</a>, it is a paid SDK that can help you to create the React Native app for iOS which can be screenshot and video-record proof! We are not sharing any further detail about this SDK as you can find the details on their website but it is the best option which you can find out on the internet till now.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9978f9decf6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Apply Search Filter in React Native Application]]></title>
            <link>https://medium.com/@subhash.dhandhukiya/how-to-apply-search-filter-in-react-native-application-72dc78e0adbf?source=rss-dc99b7da7f93------2</link>
            <guid isPermaLink="false">https://medium.com/p/72dc78e0adbf</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[search-filters]]></category>
            <dc:creator><![CDATA[Subhash Dhandhukiya]]></dc:creator>
            <pubDate>Mon, 27 Sep 2021 15:21:51 GMT</pubDate>
            <atom:updated>2021-09-27T15:21:51.464Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*sqTUE9VMJ97fXd6VC38IwQ.png" /></figure><h4>Search Bar Filter for List View</h4><p>This is an example to Make a Search Bar Filter for ListView Data in React Native. Basically, We will make a React Native FlatList with real-time searching ability. If we have a Long list in the app then it is very inconvenient to search the required data by scrolling the whole list.</p><p>Let’s take an example of E-Commerce which has several products and we have to choose our required product. You can imagine how tough it will be to search for a product by scrolling. So at this point, we need a Search Bar Filter on Listview so that we can easily search the required data and can save time.</p><h3>For Real-Time Searching in ListView using Search Bar Filter</h3><p>The logic is simple</p><ul><li>We will load the list from the network call and then show it to the user.</li><li>The user can search the data by entering the text in TextInput.</li><li>After inserting the text SearchFilterFunction will be called</li><li>We will compare the list data with the inserted data and will make a new Data source.</li><li>We will update the data source attached to the ListView.</li><li>It will re-render the list and the user will be able to see the filtered data.</li></ul><pre>const SearchFilter = text =&gt; {<br>      if(text){<br>      <strong>const</strong> newData = masterDataSource.filter(<br>       <strong>function</strong> (item) {<br>          <strong>const</strong> itemData = item.title <br>            ? item.title.toUpperCase()  <br>            : &#39;&#39;.toUpperCase();   <br>      <br>         <strong>const</strong> textData = text.toUpperCase(); <br>         <strong>return</strong> itemData.indexOf(textData) &gt; -1;<br>        }<br>       );</pre><pre>      setFilteredDataSource(newData);<br>       setSearch(text);<br>    } <strong>else</strong> { <br>       setFilteredDataSource(masterDataSource); <br>       setSearch(text);   <br> }<br>};</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72dc78e0adbf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>