<?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>Forem: Sonia I. Siganporia</title>
    <description>The latest articles on Forem by Sonia I. Siganporia (@soniaisiganporia).</description>
    <link>https://forem.com/soniaisiganporia</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%2F745019%2F9ca8e489-229d-40cd-80b9-f8dfa157e0ab.png</url>
      <title>Forem: Sonia I. Siganporia</title>
      <link>https://forem.com/soniaisiganporia</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/soniaisiganporia"/>
    <language>en</language>
    <item>
      <title>How to Implement Your First React Native Mobile Application using Node.js, Expo, and DataStax Astra DB</title>
      <dc:creator>Sonia I. Siganporia</dc:creator>
      <pubDate>Thu, 19 May 2022 19:40:49 +0000</pubDate>
      <link>https://forem.com/datastax/how-to-implement-your-first-react-native-mobile-application-using-nodejs-expo-and-datastax-astra-db-3o8p</link>
      <guid>https://forem.com/datastax/how-to-implement-your-first-react-native-mobile-application-using-nodejs-expo-and-datastax-astra-db-3o8p</guid>
      <description>&lt;p&gt;If you followed the &lt;a href="https://www.youtube.com/playlist?list=PL2g2h-wyI4Sr09jyk19cSwv2Iwcl1V1Fl" rel="noopener noreferrer"&gt;DataStax app development workshop series&lt;/a&gt;, you have already learned how to &lt;a href="https://www.youtube.com/watch?v=NzT_w3YHpuI" rel="noopener noreferrer"&gt;build a To-Do web application&lt;/a&gt; using JS, Node.js, and &lt;a href="https://astra.dev/3z4bRp9" rel="noopener noreferrer"&gt;DataStax Astra DB&lt;/a&gt;, a serverless, pay-as-you-go database based on Apache Cassandra®.&lt;/p&gt;

&lt;p&gt;To take your To-Do app a step further, &lt;a href="https://github.com/datastaxdevs/workshop-todo-native-mobile" rel="noopener noreferrer"&gt;this workshop&lt;/a&gt; shows you how to convert your app into a React Native mobile and web application. We’ll use the same database setup as the previous workshop, and introduce you to &lt;a href="https://expo.dev/" rel="noopener noreferrer"&gt;Expo&lt;/a&gt; as the fastest way to build a React Native app.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/V3xhrUszvdA"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;To start, here’s a reminder of what the previous version of the To-Do web application looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fs70jh8l1pif4929m6zud.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fs70jh8l1pif4929m6zud.png" alt="Image description" width="560" height="306"&gt;&lt;/a&gt;&lt;br&gt;
Figure 1: The interface of the To-Do app.&lt;/p&gt;

&lt;p&gt;By the end of this workshop, you’ll have a mobile-native To-Do application that can run on Android, iOS, and Web. Look at Figures 2 and 3 below for a glimpse of what you’ll end up with on mobile and desktop.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fpgyqdlwis7r41c6ldvvk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fpgyqdlwis7r41c6ldvvk.png" alt="Image description" width="560" height="560"&gt;&lt;/a&gt;&lt;br&gt;
Figure 2: To-Do app on iOS (left) and Android (right).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fwzcehla0l6ebyumam679.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fwzcehla0l6ebyumam679.png" alt="Image description" width="560" height="312"&gt;&lt;/a&gt;&lt;br&gt;
Figure 3: To-Do web application in Chrome.&lt;/p&gt;

&lt;p&gt;Here are the technologies you’ll be using in this workshop:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;React &amp;amp; React Native&lt;/strong&gt; to develop the user interface&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Expo&lt;/strong&gt; to help us build web and mobile apps from the same JS codebase&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Node.js&lt;/strong&gt; as our runtime environment&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Astra DB&lt;/strong&gt; as our free, serverless database&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;astrajs/collections&lt;/strong&gt;, which is a library called to interact with a document-oriented database&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Netlify&lt;/strong&gt; to deploy the app across a global content delivery network (CDN)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To start, let’s take a quick dip into the popular open-source platform: &lt;a href="https://reactnative.dev/" rel="noopener noreferrer"&gt;React Native&lt;/a&gt;.&lt;/p&gt;
&lt;h1&gt;
  
  
  Why use the React Native Framework?
&lt;/h1&gt;

&lt;p&gt;Before the advent of frameworks like React Native and Flutter, if you wanted to build a responsive, native application for mobile and web, you needed to build the same application, in three different languages, on three different platforms. For example, you’d use Swift for iOS in Xcode, and Java or Kotlin for Android in Android Studio. This meant you had to be fluent in multiple platforms and languages, and build the same application from scratch several times.&lt;/p&gt;

&lt;p&gt;Since you already built the To-Do app as a React-based web application using JavaScript, we’ll use React Native and Expo to convert the application to native. (If we used Flutter, we would have to convert the entire infrastructure to Dart.)&lt;/p&gt;

&lt;p&gt;In this workshop, we’ll use &lt;a href="https://docs.expo.io/guides/how-expo-works/" rel="noopener noreferrer"&gt;Expo&lt;/a&gt; to build the To-Do React Native App. In short, Expo is a set of open-source tools and services built around React Native that help you develop, build, deploy, and quickly iterate on iOS, Android, and web apps.&lt;/p&gt;

&lt;p&gt;By using Expo, you can create web apps and native Android and iOS applications from a single codebase, all using React and React Native components. You could always develop using a &lt;a href="https://docs.expo.dev/bare/exploring-bare-workflow/" rel="noopener noreferrer"&gt;bare workflow in Expo&lt;/a&gt; or &lt;a href="https://reactnative.dev/docs/environment-setup" rel="noopener noreferrer"&gt;React Native&lt;/a&gt;, but the convenience of developing using your phone as the emulator shifts the tide in favor of Expo. This is because you can actually view your new To-Do mobile app without needing to download heavy applications (like Xcode and Android Studio) or set up emulators.&lt;/p&gt;

&lt;p&gt;In addition, Expo has &lt;a href="https://docs.expo.dev/workflow/snack/" rel="noopener noreferrer"&gt;Snack&lt;/a&gt;: a playground in your browser, on which you can view code snippets in a browser-based emulator and even run complete Expo projects within a browser. No download is required.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fpevs61e5nn9jnu717q3a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fpevs61e5nn9jnu717q3a.png" alt="Image description" width="560" height="384"&gt;&lt;/a&gt;&lt;br&gt;
Figure 4: Example of an in-browser Expo project.&lt;/p&gt;
&lt;h1&gt;
  
  
  Getting started with Expo
&lt;/h1&gt;
&lt;h2&gt;
  
  
  Developing Locally
&lt;/h2&gt;

&lt;p&gt;If you’re developing a native application from scratch, you should be developing locally, using a physical Android or iPhone, Xcode for the iPhone simulator, Android Studio for the Android emulator, and a Web Browser so you can view your project on all platforms as you are developing.&lt;/p&gt;

&lt;p&gt;Alternatively, for speed and simplicity, you can simply use the Expo mobile app on your phone. All three platforms support hot refresh so you can see the changes live as you make updates in your IDE.&lt;/p&gt;

&lt;p&gt;To develop locally, you need the Expo CLI, Watchman, Git, Node.js, an IDE of your choice (i.e. VisualStudio), and ideally, Xcode and Android Studio. You can walk through the &lt;a href="https://docs.expo.dev/get-started/installation/" rel="noopener noreferrer"&gt;Expo installation process&lt;/a&gt; and create an empty Expo project.&lt;/p&gt;

&lt;p&gt;When you’re ready to test your project, start your project in debugging mode with the command: &lt;code&gt;expo start&lt;/code&gt;. This will bring up a QR code you can scan with your phone camera to bring up the app. It’ll also give you shortcut commands to run the Android, iOS, and web applications.&lt;/p&gt;

&lt;p&gt;The simulators can be a little tricky, so they work best when you have the Android emulator running &lt;em&gt;before&lt;/em&gt; doing &lt;code&gt;expo start --android&lt;/code&gt;, whereas the iOS simulator works best when the emulator quits before doing &lt;code&gt;expo start --ios&lt;/code&gt;. Similarly, you can just pay attention to the browser tab with your IP and the port, like &lt;em&gt;&lt;a href="https://192.198.68.35/8888," rel="noopener noreferrer"&gt;https://192.198.68.35/8888,&lt;/a&gt;&lt;/em&gt; and ignore the others that are launched by Netlify and Expo.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;expo start
expo start --ios
expo start --android
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To get all three platforms to connect to the Expo and Netlify servers simultaneously, you’ll need to hard code in your Port (8888) and IP address. This configuration is detailed in the &lt;code&gt;netlify.toml&lt;/code&gt; file and the .env file you’ll create during this workshop. Here’s what the end set up for the &lt;code&gt;.env&lt;/code&gt; file looks like when run locally (You will need to replace your Tokens, region, and IP with your own.):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ASTRA_DB_ADMIN_TOKEN="AstraCS:ZWpKiCKCtGkwuLadZSlclznj:a14a51e87a51b58ac7ec8fef92d5ef68abef09aa24349ec8a5d86e6c2ef479310"
ASTRA_DB_APPLICATION_TOKEN="AstraCS:ZWpKiCKCtGkwuLadZSlclznj:a14a51e87a51b58ac7ec8fef92d5ef68abef09aa24349ec8a5d86e6c2ef479310"
ASTRA_DB_ID="1795de90-1d19-43e9-bcfe-8f33aec8d9cf"
ASTRA_DB_REGION="us-west1"
ASTRA_DB_KEYSPACE="todos"
HOST="192.168.86.60"
PORT="8888"
IS_PROD="false"
GITPOD="false"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setting Up
&lt;/h2&gt;

&lt;p&gt;In this workshop, you’ll run the app on the cloud-based IDE called &lt;a href="https://www.gitpod.io/" rel="noopener noreferrer"&gt;GitPod&lt;/a&gt;, which means that you need the &lt;a href="https://expo.dev/client" rel="noopener noreferrer"&gt;Expo Go client app&lt;/a&gt; installed on your mobile device to view the app. You’ll also need to have a specific setup in your .env file, which you’ll generate during the workshop. The end product will look similar to below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ASTRA_DB_ADMIN_TOKEN="AstraCS:ZWpKiCKCtGkwuLadZSlclznj:a14a51e87a51b58ac7ec8fef92d5ef68abef09aa24349ec8a5d86e6c2ef47910"
ASTRA_DB_APPLICATION_TOKEN="AstraCS:ZWpKiCKCtGkwuLadZSlclznj:a14a51e87a51b58ac7ec8fef92d5ef68abef09aa24349ec8a5d86e6c2ef47910"
ASTRA_DB_ID="1795de90-1d19-43e9-bcfe-8f33aec8d9cf"
ASTRA_DB_REGION="us-west1"
ASTRA_DB_KEYSPACE="todos"
HOST="https://amaranth-jay-0efw1dab.ws-us15.gitpod.io/"
PORT="8888"
IS_PROD="false"
GITPOD="true"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additionally, you’ll need to start the app using &lt;code&gt;expo start --tunnel&lt;/code&gt;, in which Expo CLI &lt;a href="https://docs.expo.dev/guides/how-expo-works/" rel="noopener noreferrer"&gt;starts a tunnel using ngrok&lt;/a&gt;. This allows devices outside of your LAN to access the above servers without you needing to change your firewall settings. To run your app, enter the following commands, where each line is in a separate terminal window:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;netlify dev
expo start --tunnel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Networking with Expo, Netlify, and GitPod
&lt;/h1&gt;

&lt;p&gt;One of the biggest challenges when developing locally is configuring the emulators to all run at the same time. We found that if iOS and Web are running, the Android emulator doesn’t connect, and vice versa. As you can imagine, this made simultaneous development challenging.&lt;/p&gt;

&lt;p&gt;It all came down to configuring networking. The iOS (using localhost) and &lt;a href="https://developer.android.com/studio/run/emulator-networking" rel="noopener noreferrer"&gt;Android emulators&lt;/a&gt; (using its own loopback interface) had different IP addresses, and both Expo and Netlify were serving different ports. Expo looks for the lowest unused port starting at 19000, while Netlify defaults to port 8888. To handle this (in the &lt;code&gt;netlify.toml&lt;/code&gt;), we specified the port to which Netlify will listen (port 8888), and added a &lt;code&gt;PORT&lt;/code&gt; environment variable in our &lt;code&gt;.env&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F6hnveitsjozkjfc92940.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F6hnveitsjozkjfc92940.png" alt="Image description" width="560" height="275"&gt;&lt;/a&gt;&lt;br&gt;
Figure 4: Diagram showing how the Expo app works.&lt;/p&gt;

&lt;p&gt;When you start an app with Expo CLI using &lt;code&gt;expo start&lt;/code&gt;, you’re running the Expo Development Server and Metro bundler. The Dev Server is the endpoint that you hit first when you type the URL into the Expo app. Its purpose is to serve the Expo Manifest and provide a communication layer between Expo CLI and the Expo app on your phone or emulator.&lt;/p&gt;

&lt;p&gt;The Metro Bundler is the first to serve your app JavaScript compiled into a single file, and to translate any JavaScript code that you wrote that isn’t compatible with your phone’s JavaScript engine, as well as serve the assets.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fszomwej75lxd6zpz15c7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fszomwej75lxd6zpz15c7.png" alt="Image description" width="560" height="383"&gt;&lt;/a&gt;&lt;br&gt;
Figure 5: Diagram showing how Netlify works.&lt;/p&gt;

&lt;p&gt;The command we use to run Netlify, &lt;code&gt;&lt;a href="https://cli.netlify.com/netlify-dev/" rel="noopener noreferrer"&gt;netlify dev&lt;/a&gt;&lt;/code&gt; runs Netlify’s production routing engine in a local dev server to make all redirects, proxy rules, function routes, or add-on routes available locally. It then injects the correct environment variables from your site environment and installs add-ons or your &lt;code&gt;netlify.toml&lt;/code&gt; file into your build and function environment.&lt;/p&gt;

&lt;p&gt;To get all platform simulators firing simultaneously, you can set the path to your local private IP (or GitPod URL for cloud development) and specify the port as well, so all three platforms work at the same time.&lt;/p&gt;
&lt;h1&gt;
  
  
  Differences between React and React Native
&lt;/h1&gt;

&lt;p&gt;Now let’s take a closer look at React Native and how it differs from React. Both frameworks are open-sourced by Facebook, and used in applications like Instagram, Discord, AirBnB, Pinterest, UberEats, Skype, and SalesForce.&lt;/p&gt;

&lt;p&gt;In short:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;React&lt;/strong&gt; is a framework for building applications using JavaScript&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;React Native&lt;/strong&gt; is a platform that allows you to build native, cross-platform mobile apps&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;React.js&lt;/strong&gt; is a JavaScript library you use for constructing a high performing UI layer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;React.js is central to React Native, and is built upon React’s principles and syntax, so converting from one to the other is relatively intuitive. The browser code in React is rendered through Virtual DOM, while React Native uses Native APIs to render components on mobile. React uses HTML and CSS, whereas React Native uses its own components and libraries. You can also use hot reload in React Native so you can see your application’s current state while building.&lt;/p&gt;

&lt;p&gt;Here are some examples of code differences between the two frameworks with examples.&lt;/p&gt;
&lt;h2&gt;
  
  
  HTML Tags vs. React Native Components
&lt;/h2&gt;

&lt;p&gt;React Native uses native UI components instead of HTML. Here are some examples of translations.&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;div&amp;gt; vs &amp;lt;View&amp;gt;
&amp;lt;input&amp;gt; vs &amp;lt;TextInput&amp;gt;
&amp;lt;li&amp;gt; vs &amp;lt;FlatList&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Many of these React Native components have more event handlers that require specific calling syntax, which you can read about in &lt;a href="https://reactnative.dev/docs/components-and-apis" rel="noopener noreferrer"&gt;React Native’s Core Component and API documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS vs. StyleSheets
&lt;/h2&gt;

&lt;p&gt;Certain attributes have the same title, except React Native uses camel case instead of hyphens. Some CSS attributes don’t have a corresponding equivalent in React Native, so it’s best to go through the &lt;a href="https://reactnative.dev/docs/components-and-apis" rel="noopener noreferrer"&gt;React Native documentation&lt;/a&gt; in detail.&lt;/p&gt;

&lt;p&gt;In React, you can create one file that has all the styling for each class, but in React Native, you include it in a StyleSheet component at the end of the file (if you’re not creating a styling theme for the entire app).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CSS in React&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;lt;div className="complete"&amp;gt; &amp;lt;/div&amp;gt;

    complete: {
         text-decoration: line-through;
         font-size: 18;
         font-family: Inter_300Light;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;StyleSheet in ReactNative&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;lt;View style={styles.complete}&amp;gt; &amp;lt;/View&amp;gt;

const styles = StyleSheet.create({
    complete: {
         textDecorationLine: 'line-through',
         fontSize: 18,
         fontFamily: 'Inter_300Light',
         flexWrap: 'wrap'
    }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Import Statements
&lt;/h2&gt;

&lt;p&gt;You will now have to specify the import of each component from 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;import { SafeAreaView, StyleSheet, View, TextInput, Button } from 'react-native';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Layouts, Navigation, Animation, and more
&lt;/h2&gt;

&lt;p&gt;All are done differently in React Native. The &lt;a href="https://reactnative.dev/docs/flexbox" rel="noopener noreferrer"&gt;FlexBox algorithm&lt;/a&gt; is a responsive way to arrange components, while &lt;a href="https://reactnative.dev/docs/navigation#react-navigation" rel="noopener noreferrer"&gt;Navigation&lt;/a&gt; requires the react-native-navigation library. You can read more about the Animated API and many other available APIs &lt;a href="https://reactnative.dev/docs/animated" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  How to convert your React To-Do app into a React Native app
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Port over the following folders and files
&lt;/h2&gt;

&lt;p&gt;src (Main code changes occur here), functions (keep the same), &lt;code&gt;netlify.toml&lt;/code&gt; (Configure for Expo), &lt;code&gt;package.json&lt;/code&gt; (run npm install after copying this over), &lt;code&gt;.env&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Move the App.js file from within the src directory to the root directory
&lt;/h2&gt;

&lt;p&gt;It’s the root component for your app so Expo wants it in the root directory.&lt;/p&gt;

&lt;h2&gt;
  
  
  src/utils/api.js
&lt;/h2&gt;

&lt;p&gt;Configure fetch path to accommodate environment variables&lt;/p&gt;

&lt;p&gt;Before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const response = await fetch(`/.netlify/functions/getRestTodos`);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// GENERATE
    const generateEndpoint = () =&amp;gt; {
    const ipAddress = process.env.HOST;
    const port = process.env.PORT;

// Netlify deploy
    if (process.env.IS_PROD === "true") {
         return ``;
    }
// Running on GitPod
    else if (process.env.GITPOD === "true") {
         return ipAddress;
    }
// Local configuration
    else {
         return `http://${ipAddress}:${port}`;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  netlify.toml: Update the build command and the publish folder to work with Expo.
&lt;/h2&gt;

&lt;p&gt;Before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[build]
command = "npm run build"
functions = "functions"
publish = "build"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[build]
command = "expo build:web"
functions = "functions"
publish = "web-build"
targetPort = 8888
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  .env: Add these lines to the original .env you had
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HOST="192.168.86.95" // Add your local IP here or GitPod url
PORT="8888"
IS_PROD="false"
GITPOD="false" // Change to true if on GitPod
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  State Changes for Delete and Complete in Todo.js
&lt;/h2&gt;

&lt;p&gt;Props are used to pass data, whereas the state is for managing data. Here we’re updating the state of the Checkbox and the state of the To-Do item and then conducting the API call to update it in Astra DB. This makes the interaction snappier and more native.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [isChecked, setIsChecked] = React.useState(todo.completed);

const [isVisible, setIsVisible] = React.useState(true);

const handleCheck = () =&amp;gt; {
    setIsChecked(!isChecked);
    completeRestTodo(todo.id, todo.text, todo.completed);
}

const handleVisible = () =&amp;gt; {
    setIsVisible(!isVisible);
    deleteRestTodo(todo.id);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Additional Steps
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Swap HTML tags for React Native UI components and find the appropriate properties for those components to enable functionality.&lt;/li&gt;
&lt;li&gt;Translate CSS into StyleSheets for each component.&lt;/li&gt;
&lt;li&gt;Install additional libraries to support Expo and React Native (Take a look at &lt;code&gt;package.json&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Packages and Libraries
&lt;/h1&gt;

&lt;p&gt;Look at &lt;code&gt;.gitpod.yml&lt;/code&gt;, which sets up the cloud workspace before you start the app, and &lt;code&gt;package.json&lt;/code&gt; to see all the required packages and libraries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gitpod.yml
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tasks:
- name: todonativemobileapp
before: |
cd /workspace/todonativemobileapp
nvm install node
npm install
npm install -g expo-cli (Command line interface for Expo)
npm install -g netlify-cli (Command line interface for Netlify)
npm install astra-setup (To create the .env file during the workshop)
npm install whatwg-fetch
npm install -g @expo/ngrok (For tunnels on GitPod)
npm install @expo/ngrok@4.1.0
npm install react-native-gesture-handler (For swipe to delete/complete gesture)
npm install @react-native-segmented-control/segmented-control (For filter based on completeness)
npm install @expo-google-fonts/inter — legacy-peer-deps (For custom fonts)
npm install babel-plugin-inline-dotenv — legacy-peer-deps (For using inline environment variables)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Adding new Native features
&lt;/h1&gt;

&lt;p&gt;You can also add native features that aren’t in the original web application. These include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/react-native-segmented-control/segmented-control" rel="noopener noreferrer"&gt;Segmented Control&lt;/a&gt;: Instead of a filter at the bottom of the list, you’ll learn how to create a segmented control component that allows you to filter tasks based on their status of All, Active, and Completed.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.swmansion.com/react-native-gesture-handler/docs/api/components/swipeable/" rel="noopener noreferrer"&gt;Swipe to delete and complete&lt;/a&gt;: Aside from clicking the trash icon for delete and the check box for complete/incomplete, you can also swipe from the right to expose a drawer and swipe to the left to delete. From the left side, you can reveal a drawer that swaps based on the state of the task (Complete or Incomplete). Swiping across will change its state and the item will close itself.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Enhancing the user interface
&lt;/h1&gt;

&lt;p&gt;Expo recommends certain &lt;a href="https://docs.expo.dev/guides/userinterface/" rel="noopener noreferrer"&gt;UI libraries&lt;/a&gt; for sleek, native-looking enhancements for your application, depending on the components and functionality you need. Each library has a different set of functionality and appearance, so choose accordingly.&lt;/p&gt;

&lt;p&gt;Other additions to the native app include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://reactnative.dev/docs/flexbox#flex-wrap" rel="noopener noreferrer"&gt;flexWrap&lt;/a&gt;: Property needed to prevent horizontal and vertical overflow from a long To-Do item: &lt;code&gt;flexWrap&lt;strong&gt;: &lt;/strong&gt;'wrap'&lt;strong&gt;.&lt;/strong&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/callstack/react-native-paper/issues/1416" rel="noopener noreferrer"&gt;Removing border when TextInput is selected on the web&lt;/a&gt;: Perfect example of a platform-specific bug. On the web, the selected input box is highlighted in blue so you can import Platform to specify platform-related properties.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.expo.dev/guides/using-custom-fonts/" rel="noopener noreferrer"&gt;Custom Fonts&lt;/a&gt;: Adding custom fonts from Google Fonts allows for the same font across platforms.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.expo.dev/guides/configuring-statusbar/" rel="noopener noreferrer"&gt;StatusBar&lt;/a&gt;: This is possible for Android but not iOS. You can change the color behind the StatusBar, but only on Android.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Tips for success
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Platform-specific bugs:&lt;/strong&gt; Sometimes native behavior is different between platforms. For example, the word you’re currently typing will appear underlined on Android. As a result, you need to keep all emulators open while developing so you can catch platform-specific bugs as they happen.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Peer dependency errors:&lt;/strong&gt; If you’re getting faulty peer dependency errors, first look at your &lt;em&gt;package.json&lt;/em&gt; to see if you can resolve these manually. Otherwise, try re-running the npm command with the legacy peer dependency flag. These seem to happen because NPM 7 is pickier about peer dependencies than NPM 6. The legacy peer dependencies flag reverts to NPM 6 standards for peer dependencies.
&lt;code&gt;npm install @expo-google-fonts/inter — legacy-peer-deps&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Finding additional features:&lt;/strong&gt; Expo and React Native may not include all the components and extended functionality you need. Don’t hesitate to look for libraries in the &lt;a href="https://reactnative.directory/" rel="noopener noreferrer"&gt;React Native Directory&lt;/a&gt; for the features you want.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Search for solutions:&lt;/strong&gt; Google, StackOverflow, blogs, and forums are the best teachers. If you’re stumped on something, it’s very probable that another developer has faced the same issue. Search for a solution using keywords and code snippets, and you should be able to find a workaround. If all else fails, find the forum for the library you’re using and post a question there.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Create a &lt;a href="https://docs.expo.dev/guides/progressive-web-apps/" rel="noopener noreferrer"&gt;Progressive Web App&lt;/a&gt; (PWA):&lt;/strong&gt; Expo is automatically set up to build a PWA should you want to have one. You can follow the steps &lt;a href="https://blog.expo.dev/create-and-deploy-web-apps-and-pwas-with-expo-a286cc35d83c" rel="noopener noreferrer"&gt;here&lt;/a&gt; to make one in under five minutes!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Explore more tutorials on our &lt;a href="https://www.youtube.com/c/DataStaxDevs" rel="noopener noreferrer"&gt;DataStax Developers YouTube channel&lt;/a&gt; and &lt;a href="https://docs.google.com/forms/d/e/1FAIpQLSfEtzzVauuFpFJWUiepYndqchBpNsaOwm6raPJDsMt9nTvMbw/viewform" rel="noopener noreferrer"&gt;subscribe to our event alert&lt;/a&gt; to get notified about new developer workshops. For exclusive posts on all things data: Cassandra, streaming, Kubernetes, and more; follow &lt;a href="https://datastax.medium.com/" rel="noopener noreferrer"&gt;DataStax on Medium&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Resources
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=NzT_w3YHpuI" rel="noopener noreferrer"&gt;Building a To-Do list app with Javascript and NodeJS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/datastaxdevs/appdev-week1-todolist" rel="noopener noreferrer"&gt;GitHub: Run your first frontend application — To-Do list&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/playlist?list=PL2g2h-wyI4Sr09jyk19cSwv2Iwcl1V1Fl" rel="noopener noreferrer"&gt;Full DataStax app development series on YouTube&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://astra.dev/3z4bRp9" rel="noopener noreferrer"&gt;Astra DB — Serverless cloud database built on Apache Cassandra&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://reactnative.dev/docs/components-and-apis" rel="noopener noreferrer"&gt;Core Components and APIs · React Native&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.expo.io/guides/how-expo-works/" rel="noopener noreferrer"&gt;How Expo Works&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://auth.cloud.datastax.com/auth/realms/CloudUsers/protocol/saml/clients/absorb" rel="noopener noreferrer"&gt;DataStax Academy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.datastax.com/workshop" rel="noopener noreferrer"&gt;DataStax Workshops&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>node</category>
      <category>webdev</category>
      <category>react</category>
      <category>mobile</category>
    </item>
  </channel>
</rss>
