<?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: Royce Chua</title>
    <description>The latest articles on DEV Community by Royce Chua (@roycechua).</description>
    <link>https://dev.to/roycechua</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%2F206028%2F8fac262e-42a3-47d3-9caf-83cafd7a07e4.jpg</url>
      <title>DEV Community: Royce Chua</title>
      <link>https://dev.to/roycechua</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/roycechua"/>
    <language>en</language>
    <item>
      <title>Globally control Modals on React Native (using refs)</title>
      <dc:creator>Royce Chua</dc:creator>
      <pubDate>Mon, 26 Sep 2022 01:05:21 +0000</pubDate>
      <link>https://dev.to/roycechua/globally-control-modals-on-react-native-using-refs-5368</link>
      <guid>https://dev.to/roycechua/globally-control-modals-on-react-native-using-refs-5368</guid>
      <description>&lt;p&gt;This article will demonstrate a simple example of how you can launch React Native modals using refs from any component instead of passing states and context data. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why?
&lt;/h2&gt;

&lt;p&gt;From the official React Native documentation regarding &lt;a href="https://reactnative.dev/docs/modal" rel="noopener noreferrer"&gt;Modals&lt;/a&gt;, we know that we can control modal visibility content and data using states and passing data through props but we cannot directly pass refs to the RN Modal component. This means that for larger and more complex projects, if you want to control a modal at a global level you can do some of these things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Passing props through components (a lot of components)&lt;/li&gt;
&lt;li&gt;Implement modal state management through context and reducers&lt;/li&gt;
&lt;li&gt;Use a third-party package that can handle that (which is probably limited in terms of providing ways to customize default behavior and UI)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The question now is what if we could implement a way so that we only have to make a custom modal component once and not resort to complex prop passing or use context?&lt;/p&gt;

&lt;p&gt;A simple &lt;strong&gt;.showModal(data)&lt;/strong&gt; method call from anywhere across different components would be perfect and the topic this blog will share.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some Disclaimers
&lt;/h2&gt;

&lt;p&gt;This probably is not for people new to React Native, but still a great opener to the idea of implementing custom functionality with refs. The contents of this blog is better applied to a larger project that will use the same modal in multiple components. If you're app is simple, it's probably better to stick to simpler implementations.&lt;/p&gt;

&lt;h2&gt;
  
  
  The implementation
&lt;/h2&gt;

&lt;p&gt;1) Create the Custom Modal &lt;/p&gt;

&lt;p&gt;I modified the raw &lt;a href="https://reactnative.dev/docs/modal" rel="noopener noreferrer"&gt;example here&lt;/a&gt; in the React Native documentation&lt;/p&gt;

&lt;p&gt;2) Add the modalRef then the hook &lt;strong&gt;useImperativeHandle&lt;/strong&gt; and &lt;strong&gt;forwardRef()&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CustomModal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;modalVisible&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setModalVisible&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;modalRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useRef&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;CustomModalRef&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="nf"&gt;useImperativeHandle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nx"&gt;modalRef&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;show&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nf"&gt;setModalVisible&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="na"&gt;hide&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nf"&gt;setModalVisible&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;}),&lt;/span&gt;
        &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="c1"&gt;// rest of your code&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;forwardRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;CustomModal&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I use Typescript so if you also do, you can use this type for  &lt;strong&gt;CustomModalRef&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;CustomModalRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;show&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;
    &lt;span class="na"&gt;hide&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3) Create a Modal Controller class that will use static variables and functions for managing the modal refs&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;MutableRefObject&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;CustomModalRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;show&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;
    &lt;span class="na"&gt;hide&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ModalController&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nx"&gt;modalRef&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;MutableRefObject&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;CustomModalRef&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nx"&gt;setModalRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;any&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;modalRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nx"&gt;showModal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;modalRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nx"&gt;hideModal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;modalRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;hide&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;showModal&lt;/strong&gt; and &lt;strong&gt;hideModal&lt;/strong&gt; static methods can be optional, you can directly call &lt;strong&gt;current.show&lt;/strong&gt; but I chose to create the methods to provide more custom functionality &lt;/p&gt;

&lt;p&gt;4) Assign the modal ref in Custom Modal to the static variable in the Modal Controller class&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CustomModal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;modalVisible&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setModalVisible&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;modalRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useRef&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;CustomModalRef&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="nf"&gt;useLayoutEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;ModalController&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setModalRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;modalRef&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[])&lt;/span&gt;

    &lt;span class="nx"&gt;useImperativeHandle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="c1"&gt;// rest of the code&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I used the &lt;strong&gt;useLayoutEffect&lt;/strong&gt; since I'm updating a ref value. You can read about the differences of &lt;strong&gt;useEffect&lt;/strong&gt; and &lt;strong&gt;useLayoutEffect&lt;/strong&gt; you can check this great &lt;a href="https://kentcdodds.com/blog/useeffect-vs-uselayouteffect" rel="noopener noreferrer"&gt;blog&lt;/a&gt; by Kent C. Dodds &lt;/p&gt;

&lt;p&gt;5) Declare the component in the top-level component (usually &lt;strong&gt;App.tsx&lt;/strong&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;NavigationContainer&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MainStack&lt;/span&gt;&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;CustomModal&lt;/span&gt;&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;NavigationContainer&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;6) Use the ModalController class to show/hide the modal&lt;br&gt;
&lt;strong&gt;Usage in a component (SomeScreen.js)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* 
* Component code/logic in between
*/&lt;/span&gt;
&lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
 &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;SomeComponent&lt;/span&gt;&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
 &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt; 
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Show modal"&lt;/span&gt; 
  &lt;span class="na"&gt;onPress&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;ModalController&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;showModal&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; 
 &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the expected behavior show in the GIF below&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%2F3dyhvclw7ldthab3aata.gif" 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%2F3dyhvclw7ldthab3aata.gif" alt="Image description" width="344" height="750"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Recommendations
&lt;/h2&gt;

&lt;p&gt;You can now extend this concept to accept data like a string message that makes a really flexible global modal that you can easily call without adding a new 3rd party library or a  context provider setup made specifically to manage modals. You can check this &lt;a href="https://github.com/roycechua/rn-global-modal-control-example" rel="noopener noreferrer"&gt;Github repository&lt;/a&gt; I made that shows this exact example but also with the added &lt;strong&gt;message&lt;/strong&gt; parameter. You can clone this repo and checkout from the &lt;strong&gt;boilerplate&lt;/strong&gt; branch.&lt;/p&gt;

&lt;p&gt;Thanks for taking the time to read this, hope it helped!&lt;/p&gt;

&lt;p&gt;Your support would be very much appreciated. Buying me a coffee would mean a lot&lt;br&gt;
&lt;a href="https://www.buymeacoffee.com/royce.chua" rel="noopener noreferrer"&gt;https://www.buymeacoffee.com/royce.chua&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This blog will probably have a video posted on Youtube soon. I'm putting together a &lt;a href="https://www.youtube.com/channel/UCVCAGgg9Gs9RgENKurnI6bQ" rel="noopener noreferrer"&gt;Youtube channel&lt;/a&gt; that will complement my blog called &lt;a href="https://www.youtube.com/channel/UCVCAGgg9Gs9RgENKurnI6bQ" rel="noopener noreferrer"&gt;Just Code&lt;/a&gt;. Please visit for some content soon.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some additional remarks
&lt;/h2&gt;

&lt;p&gt;I forgot to mention here as a reminder that the implementation of the React Native modal does not allow multiple modals (unrelated to the contents of this blog). You must still make sure that you close the first one before opening the second modal using setTimeout(). This is also discussed in the react-native-modal library issues&lt;br&gt;
&lt;a href="https://github.com/react-native-modal/react-native-modal/issues/30" rel="noopener noreferrer"&gt;https://github.com/react-native-modal/react-native-modal/issues/30&lt;/a&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>javascript</category>
      <category>modals</category>
    </item>
    <item>
      <title>How to make your React Native 0.62 project compatible with iOS 14 and Xcode 12.5</title>
      <dc:creator>Royce Chua</dc:creator>
      <pubDate>Thu, 07 Oct 2021 20:12:11 +0000</pubDate>
      <link>https://dev.to/roycechua/how-to-make-your-react-native-0-62-project-compatible-with-ios-14-and-xcode-12-5-4mfa</link>
      <guid>https://dev.to/roycechua/how-to-make-your-react-native-0-62-project-compatible-with-ios-14-and-xcode-12-5-4mfa</guid>
      <description>&lt;h1&gt;
  
  
  Overview
&lt;/h1&gt;

&lt;p&gt;This guide is for the React Native developers that needs to work on a lower version React Native project (0.62 specifically). I haven't encountered any problems with Android so far so this blog is specifically for iOS fixes only. &lt;/p&gt;

&lt;h1&gt;
  
  
  The Guide
&lt;/h1&gt;

&lt;p&gt;This is broken into specific guides but I recommend going through them in order before running a build on Xcode. &lt;/p&gt;

&lt;h2&gt;
  
  
  Fix the missing Images for iOS 14 devices and above
&lt;/h2&gt;

&lt;p&gt;This directly refers to this &lt;a href="https://github.com/facebook/react-native/issues/29279" rel="noopener noreferrer"&gt;issue&lt;/a&gt; when iOS 14 just came out and the React Native framework still wasn't able to address breaking changes/bugs. To resolve the issue do this&lt;br&gt;
1) In the root project folder create a folder called &lt;strong&gt;patches&lt;/strong&gt;&lt;br&gt;
2) Create a new file called &lt;strong&gt;react-native+0.63.0.patch&lt;/strong&gt; and paste the following code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;diff &lt;span class="nt"&gt;--git&lt;/span&gt; a/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m b/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m
index 21f1a06..2444713 100644
&lt;span class="nt"&gt;---&lt;/span&gt; a/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m
+++ b/node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m
@@ &lt;span class="nt"&gt;-272&lt;/span&gt;,6 +272,9 @@ - &lt;span class="o"&gt;(&lt;/span&gt;void&lt;span class="o"&gt;)&lt;/span&gt;displayDidRefresh:&lt;span class="o"&gt;(&lt;/span&gt;CADisplayLink &lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;displayLink

 - &lt;span class="o"&gt;(&lt;/span&gt;void&lt;span class="o"&gt;)&lt;/span&gt;displayLayer:&lt;span class="o"&gt;(&lt;/span&gt;CALayer &lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;layer
 &lt;span class="o"&gt;{&lt;/span&gt;
+  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(!&lt;/span&gt;_currentFrame&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
+    _currentFrame &lt;span class="o"&gt;=&lt;/span&gt; self.image&lt;span class="p"&gt;;&lt;/span&gt;
+  &lt;span class="o"&gt;}&lt;/span&gt;
   &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;_currentFrame&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
     layer.contentsScale &lt;span class="o"&gt;=&lt;/span&gt; self.animatedImageScale&lt;span class="p"&gt;;&lt;/span&gt;
     layer.contents &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;__bridge &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;_currentFrame.CGImage&lt;span class="p"&gt;;&lt;/span&gt;
diff &lt;span class="nt"&gt;--git&lt;/span&gt; a/node_modules/react-native/scripts/.packager.env b/node_modules/react-native/scripts/.packager.env
new file mode 100644
index 0000000..361f5fb
&lt;span class="nt"&gt;---&lt;/span&gt; /dev/null
+++ b/node_modules/react-native/scripts/.packager.env
@@ &lt;span class="nt"&gt;-0&lt;/span&gt;,0 +1 @@
+export &lt;span class="nv"&gt;RCT_METRO_PORT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;8081
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: You can also refer to this &lt;a href="https://gist.github.com/roycechua23/8376e099d83a50351d56b1789c94979c" rel="noopener noreferrer"&gt;gist&lt;/a&gt; to copy the code.&lt;br&gt;
3) Run the commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn &lt;span class="nb"&gt;install
&lt;/span&gt;npx patch-package
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should automatically resolve the issue with the unrendered images. &lt;/p&gt;

&lt;h2&gt;
  
  
  Fix for No matching function for call to 'RCTBridgeModuleNameForClass' error
&lt;/h2&gt;

&lt;p&gt;This error will come up because of a newer version of Xcode. The error looks like the following image below&lt;br&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%2Fawz6rsuh3qx7fefojyv7.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%2Fawz6rsuh3qx7fefojyv7.png" alt="Alt Text" width="800" height="95"&gt;&lt;/a&gt;&lt;br&gt;
To resolve this, you need to remove the following:&lt;br&gt;
1) Go to the &lt;strong&gt;Podfile&lt;/strong&gt; in the ios folder and add the following to your target:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="n"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;find_and_replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dir&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;findstr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;replacestr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="kt"&gt;Dir&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;dir&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;each&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
      &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;File&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="n"&gt;replace&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gsub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;findstr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;replacestr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;replace&lt;/span&gt;
          &lt;span class="n"&gt;puts&lt;/span&gt; &lt;span class="s"&gt;"Fix: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
          &lt;span class="kt"&gt;File&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"w"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;replace&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
          &lt;span class="kt"&gt;STDOUT&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;flush&lt;/span&gt;
      &lt;span class="n"&gt;end&lt;/span&gt;
  &lt;span class="n"&gt;end&lt;/span&gt;
  &lt;span class="kt"&gt;Dir&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;dir&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="o"&gt;*/&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;each&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nf"&gt;method&lt;/span&gt;&lt;span class="p"&gt;(:&lt;/span&gt;&lt;span class="n"&gt;find_and_replace&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: This is actually just a function that will search and replace the existing code in node_modules causing the error.&lt;/p&gt;

&lt;p&gt;2) In the &lt;strong&gt;post_install&lt;/strong&gt; script, add the following function calls using the newly added find_and_replace() function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="n"&gt;post_install&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;installer&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
    &lt;span class="nf"&gt;flipper_post_install&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;installer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="err"&gt;##&lt;/span&gt; &lt;span class="kt"&gt;Fix&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="kt"&gt;XCode&lt;/span&gt; &lt;span class="mf"&gt;12.5&lt;/span&gt;
    &lt;span class="nf"&gt;find_and_replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"../node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"_initializeModules:(NSArray&amp;lt;id&amp;lt;RCTBridgeModule&amp;gt;&amp;gt; *)modules"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"_initializeModules:(NSArray&amp;lt;Class&amp;gt; *)modules"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;find_and_replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"../node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"RCTBridgeModuleNameForClass(strongModule))"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"RCTBridgeModuleNameForClass(Class(strongModule)))"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: the flipper_post_install(installer) function call should be present by default just add the codes under Fix for Xcode 12.5 &lt;/p&gt;

&lt;h2&gt;
  
  
  Fix for errors related to flipper
&lt;/h2&gt;

&lt;p&gt;In some instances, you may encounter a build problem on Xcode or RN related to flipper. You can do the following to resolve the issue&lt;br&gt;
1) Update flipper version on the Podfile to 0.91 and platform :ios, from '9.0' to '10.0'. &lt;strong&gt;First parts of the Podfile&lt;/strong&gt; is shown for reference&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="nv"&gt;platform&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;ios&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="mf"&gt;10.0&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;
&lt;span class="n"&gt;require_relative&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="o"&gt;../&lt;/span&gt;&lt;span class="n"&gt;node_modules&lt;/span&gt;&lt;span class="sr"&gt;/@react-native-community/cli-platform-ios/&lt;/span&gt;&lt;span class="n"&gt;native_modules&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;

&lt;span class="n"&gt;def&lt;/span&gt; &lt;span class="n"&gt;add_flipper_pods&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;
  &lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="o"&gt;~&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;0.91&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;
  &lt;span class="n"&gt;pod&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="kt"&gt;FlipperKit&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;configuration&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="kt"&gt;Debug&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;
  &lt;span class="n"&gt;pod&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="kt"&gt;FlipperKit&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="kt"&gt;FlipperKitLayoutPlugin&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;configuration&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="kt"&gt;Debug&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;
  &lt;span class="n"&gt;pod&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="kt"&gt;FlipperKit&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="kt"&gt;SKIOSNetworkPlugin&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;configuration&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="kt"&gt;Debug&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;
  &lt;span class="n"&gt;pod&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="kt"&gt;FlipperKit&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="kt"&gt;FlipperKitUserDefaultsPlugin&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;configuration&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="kt"&gt;Debug&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;
  &lt;span class="n"&gt;pod&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="kt"&gt;FlipperKit&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="kt"&gt;FlipperKitReactPlugin&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;configuration&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="kt"&gt;Debug&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;
&lt;span class="n"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: If you can't afford to change the deployment platform to '10.0'. You can try to find a lower stable version of Flipper that's compatible with Xcode 12.5. &lt;br&gt;
2) Run pod install&lt;/p&gt;

&lt;h1&gt;
  
  
  Finally
&lt;/h1&gt;

&lt;p&gt;You should now be able to run the iOS project without any issues. Just comment any issues you encounter and hopefully either I or friends here at dev.to can help.&lt;/p&gt;

&lt;h1&gt;
  
  
  Ending Notes
&lt;/h1&gt;

&lt;p&gt;The fixes are actually based on Github issues and Stackoverflow sites and I compiled all of them for everyone's convenience.&lt;/p&gt;

&lt;p&gt;If ever I encounter problems with the initial Android run, I will add an Android section. Feel free to comment if ever you encounter problems running Android in the initial launch using the React Native version 0.62 template.&lt;/p&gt;

&lt;p&gt;I hope this article helped you in some way.&lt;/p&gt;

&lt;p&gt;If this article/blog/tutorial helped you and you would like to keep supporting this my work, I would appreciate it if you would buy me a coffee here: &lt;a href="https://www.buymeacoffee.com/royce.chua" rel="noopener noreferrer"&gt;https://www.buymeacoffee.com/royce.chua&lt;/a&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
    </item>
    <item>
      <title>Setup a Node Express API with TypeScript (2021)</title>
      <dc:creator>Royce Chua</dc:creator>
      <pubDate>Mon, 29 Mar 2021 15:46:22 +0000</pubDate>
      <link>https://dev.to/roycechua/setup-a-node-express-api-with-typescript-2021-11o1</link>
      <guid>https://dev.to/roycechua/setup-a-node-express-api-with-typescript-2021-11o1</guid>
      <description>&lt;p&gt;This tutorial will help you quickly setup a Node express API with TypeScript. &lt;/p&gt;

&lt;p&gt;All the steps done here can be cloned through my Github repository &lt;a href="https://github.com/roycechua23/node-express-typescript-starter" rel="noopener noreferrer"&gt;https://github.com/roycechua23/node-express-typescript-starter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important note for production:&lt;/strong&gt; This blog is meant to make developer life more straightforward. As such, we're focusing on initial setup and not for a production build. For production builds, you still need to transpile to JS using tsc&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"start:dev"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ts-node-dev ./index.ts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"tsc &amp;amp;&amp;amp; node ./lib/index.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that, lib can be replaced with dist or whatever your "outputDir" is on the TypeScript configuration file (tsconfig.json) that we'll also be going over later in this blog. &lt;/p&gt;

&lt;h2&gt;
  
  
  1. Pre-requisites
&lt;/h2&gt;

&lt;p&gt;For this blog you need to have Node.js(v10+) installed on your machine for this to work without any issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create initial folder and package.json
&lt;/h2&gt;

&lt;p&gt;Open your terminal and create your folder and package.json using&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;node-express-typescript-starter &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; npm init 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fill out all the information being asked. Set the entry point to index.ts and feel free to provide the other information with appropriate values.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Install the dependencies
&lt;/h2&gt;

&lt;p&gt;You need to install the following dependencies using npm&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;typescript &lt;span class="nt"&gt;--save-dev&lt;/span&gt;
npm &lt;span class="nb"&gt;install &lt;/span&gt;ts-node-dev &lt;span class="nt"&gt;--save-dev&lt;/span&gt;
npm &lt;span class="nb"&gt;install &lt;/span&gt;express 
npm &lt;span class="nb"&gt;install&lt;/span&gt; @types/express &lt;span class="nt"&gt;--save-dev&lt;/span&gt;
npm &lt;span class="nb"&gt;install&lt;/span&gt; @types/node &lt;span class="nt"&gt;--save-dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is only for a minimal setup. The &lt;strong&gt;ts-node-dev&lt;/strong&gt; dependency will continuously recompile and run the .ts file directly instead of compiling the .ts file then running .js file. It will be our replacement for nodemon which is only for .js files.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Create a tsconfig.json file
&lt;/h2&gt;

&lt;p&gt;You can create a TypeScript configuration file using the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx tsc &lt;span class="nt"&gt;--init&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will automatically create a tsconfig.json for you with the default settings (you can change them anytime you want).&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Modify the scripts in package.json
&lt;/h2&gt;

&lt;p&gt;Using your code editor or IDE, modify the &lt;em&gt;scripts:&lt;/em&gt; in package.json to include the keyword and value as shown below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ts-node-dev ./index.ts"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can remove the test key for now.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Create the index.ts file
&lt;/h2&gt;

&lt;p&gt;Create the index.ts file using your code editor and copy and paste the sample code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Application&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Response&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Application&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Body parsing Middleware&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;urlencoded&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;extended&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}));&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Response&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello World!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Connected successfully on port &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Error occured: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Run the code
&lt;/h2&gt;

&lt;p&gt;To run the Node express API simply run the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It should now display the message &lt;strong&gt;"Connected successfully on port 3000"&lt;/strong&gt; on the console. &lt;/p&gt;

&lt;p&gt;If you encounter an error &lt;strong&gt;"Error: listen EADDRINUSE: address already in use :::3000"&lt;/strong&gt;, this means that you have other services currently running on port 3000 (ex. React Apps, other Node.js Apps, etc..)&lt;/p&gt;

&lt;p&gt;Test this out by either opening your browser or Postman with a GET Request to &lt;strong&gt;localhost:3000&lt;/strong&gt;.&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%2Fcs94snlmh0hyt8tegiv6.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%2Fcs94snlmh0hyt8tegiv6.png" alt="Alt Text" width="800" height="648"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Try modifying the code
&lt;/h2&gt;

&lt;p&gt;Try modifying the the return message "Hello World!" to any message you like. It should automatically restart the node server and you can try it out again to see the changes.&lt;/p&gt;

&lt;p&gt;Congratulations, you have now successfully setup your Node Express API with TypeScript without doing any additional complex task.&lt;/p&gt;

&lt;p&gt;Your support would be very much appreciated by reacting to this post. Buying me a coffee would mean a lot&lt;br&gt;
&lt;a href="https://www.buymeacoffee.com/royce.chua" rel="noopener noreferrer"&gt;https://www.buymeacoffee.com/royce.chua&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>express</category>
      <category>typescript</category>
    </item>
    <item>
      <title>How To Make Your Own Custom React Native Templates (2021)</title>
      <dc:creator>Royce Chua</dc:creator>
      <pubDate>Tue, 16 Feb 2021 14:11:18 +0000</pubDate>
      <link>https://dev.to/roycechua/how-to-make-your-own-custom-react-native-templates-2021-20l5</link>
      <guid>https://dev.to/roycechua/how-to-make-your-own-custom-react-native-templates-2021-20l5</guid>
      <description>&lt;h1&gt;
  
  
  Overview
&lt;/h1&gt;

&lt;p&gt;I was looking for a tutorial on how to make my own React Native (RN) templates that I could init with new RN projects using the flag --template after the init&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx react-native init someproject --template mytemplate&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;because I would always see on the internet are premade templates that I didn't really want to use initially because I wanted something more simple and specific that I could easily work my way around without much trouble.&lt;/p&gt;

&lt;p&gt;I happened to find this helpful Medium Article by Chris Geirman of the Daily JS back in 2017 titled "&lt;a href="https://medium.com/dailyjs/the-1-2-3s-of-react-native-templates-1f5dda037e11" rel="noopener noreferrer"&gt;The 1-2-3's of React Native Templates&lt;/a&gt;". &lt;/p&gt;

&lt;p&gt;I didn't get to finish it because I encountered some problems when trying to do it most likely because it was already outdated. One of the errors shown by React Native led me to making this article. &lt;/p&gt;

&lt;p&gt;I made this as simple as possible so that anyone could follow along and it get it done immediately.&lt;/p&gt;

&lt;h1&gt;
  
  
  Main Steps Involved
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Creating the template's repository&lt;/li&gt;
&lt;li&gt;Creating the app template (make the React Native project you want to use as your template)&lt;/li&gt;
&lt;li&gt;Creating the actual template structure (the app template +  other config files)&lt;/li&gt;
&lt;li&gt;Testing it!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you ever get lost or stuck refer to this or the Youtube Video if you want a video based guide/walkthrough &lt;a href="https://youtu.be/Jhg88_ohyM0" rel="noopener noreferrer"&gt;here on Youtube&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Background
&lt;/h1&gt;

&lt;p&gt;A React Native template is simply like the app that you first see when you run the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx react-native init someproject
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run with either &lt;code&gt;npx react-native run-android&lt;/code&gt; or &lt;br&gt;
&lt;code&gt;npx react-native run-ios&lt;/code&gt; such as the Android App shown below&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%2Fi%2Ffc4yk70jcyqoh6ekrqbq.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%2Fi%2Ffc4yk70jcyqoh6ekrqbq.png" alt="Demo App of npx init" width="800" height="1600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The difference with custom React Native templates is that we get to put what is in the app by default such as Navigation, A State Management Library, UI libraries, AsyncStorage, and more. We'll keep things simple for now.&lt;/p&gt;
&lt;h1&gt;
  
  
  Demo
&lt;/h1&gt;

&lt;p&gt;I am currently making my own preferred custom React Native template but you can try a demo app by running the command in your terminal below which will create the app test&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx react-native init test --template https://github.com/roycechua23/react-native-template-simpleredux-boilerplate1.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run with either &lt;code&gt;cd someproject &amp;amp;&amp;amp; npx react-native run-android&lt;/code&gt; or &lt;br&gt;
&lt;code&gt;cd test &amp;amp;&amp;amp; npx react-native run-ios&lt;/code&gt; such as the Android App shown below.&lt;/p&gt;

&lt;p&gt;The result should be &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%2Fwqv17t075fnr4bcp71xo.gif" 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%2Fwqv17t075fnr4bcp71xo.gif" alt="Alt Text" width="317" height="666"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Minimal effort and I now have a UI Framework with React Navigation as well Redux (behind the scenes) already setup.&lt;/p&gt;
&lt;h1&gt;
  
  
  Let's Start
&lt;/h1&gt;

&lt;p&gt;First, it's convenient to tell you that this custom template can either be on your computer as a repository or on remote repositories on Github, Gitlab, Bitbucket so on..&lt;/p&gt;

&lt;p&gt;As mentioned by Chris Geirman on his &lt;a href="https://medium.com/dailyjs/the-1-2-3s-of-react-native-templates-1f5dda037e11" rel="noopener noreferrer"&gt;Medium Article&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Your template can be called from npm, file://, http://, https://, or git://.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Initial Repo Setup
&lt;/h2&gt;

&lt;p&gt;1.) I'm going to setup a sample repository on Github called &lt;strong&gt;testRNTemplate&lt;/strong&gt; (you can name yours whatever you want). This will contain the sample template for this article.&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%2Fi%2Fm8it5jup5erhb9b4a6bm.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%2Fi%2Fm8it5jup5erhb9b4a6bm.png" alt="Alt Text" width="800" height="402"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Create Initial Template App
&lt;/h2&gt;

&lt;p&gt;2.) On your local machine, open the terminal and create an initial React Native App using&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx react-native init ProjectName
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command should install the latest stable React Native version.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note: It's absolutely important to follow the capitalizations in exact name &lt;em&gt;ProjectName&lt;/em&gt;&lt;/strong&gt; because the flag &lt;strong&gt;--template&lt;/strong&gt; will convert ProjectName into the name of your app.&lt;/p&gt;

&lt;p&gt;3.) Run the App using&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;then&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;If you are on Mac&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Important Note:&lt;/strong&gt; For React Native projects running on the latest version 0.63 or 0.64. Please make sure that your &lt;strong&gt;Cocoapods&lt;/strong&gt; version is on version &lt;strong&gt;1.10.1&lt;/strong&gt; to avoid any errors in running the iOS app. You can update using this command:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configuring the Template App
&lt;/h2&gt;

&lt;p&gt;4.) When you finally get your App try to run it first and make sure that it installed successfully by displaying the default React Native Welcome Screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Project Dependencies and Setup
&lt;/h2&gt;

&lt;p&gt;Picture of iOS and Android App&lt;/p&gt;

&lt;p&gt;4.1) In my case, I wanted &lt;strong&gt;React Navigation&lt;/strong&gt; library and a UI framework like &lt;strong&gt;React Native Paper&lt;/strong&gt; with &lt;strong&gt;React Native Vector Icons&lt;/strong&gt; pre-installed so I install them using &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
yarn add react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context @react-native-community/masked-view
yarn add @react-navigation/stack

yarn add react-native-paper
yarn add react-native-vector-icons
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please take note of &lt;strong&gt;react-native-vector-icons&lt;/strong&gt; setup instructions on Github &lt;a href="https://github.com/oblador/react-native-vector-icons" rel="noopener noreferrer"&gt;https://github.com/oblador/react-native-vector-icons&lt;/a&gt;. It will have many instructions but follow the part that you see in the image below. &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%2Fi%2Fwdzsur8vjjsfhs0eeanl.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%2Fi%2Fwdzsur8vjjsfhs0eeanl.png" alt="Alt Text" width="800" height="560"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I added this library in because out of all the starting libraries this is where I struggled with when I was beginning to learn the &lt;strong&gt;react-native-cli&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Then finalize the installation on ios by using the command&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Testing new libraries on App.js (as a demo)
&lt;/h2&gt;

&lt;p&gt;4.2) We should check if the installation of the packages was successful by changing the code in our &lt;strong&gt;app.js&lt;/strong&gt; with the following code below (you can copy paste it directly)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;StyleSheet&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;View&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-native&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Title&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-native-paper&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;NavigationContainer&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@react-navigation/native&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createStackNavigator&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@react-navigation/stack&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ProfileScreen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;navigation&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;View&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Title&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Welcome&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;Profile&lt;/span&gt; &lt;span class="nx"&gt;Screen&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Title&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="nx"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;contained&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;icon&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;home&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; 
        &lt;span class="nx"&gt;onPress&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;navigation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Home&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nx"&gt;Go&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;Home&lt;/span&gt; &lt;span class="nx"&gt;Screen&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/View&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;HomeScreen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;navigation&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;View&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Title&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Welcome&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="nx"&gt;Native&lt;/span&gt; &lt;span class="nx"&gt;Home&lt;/span&gt; &lt;span class="nx"&gt;Screen&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Title&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="nx"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;contained&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;icon&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;account&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; 
        &lt;span class="nx"&gt;onPress&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;navigation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Profile&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nx"&gt;Go&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;Profile&lt;/span&gt; &lt;span class="nx"&gt;Screen&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/View&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Stack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createStackNavigator&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;NavigationContainer&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Navigator&lt;/span&gt; &lt;span class="nx"&gt;initialRouteName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Home&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Screen&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Home&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;component&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;HomeScreen&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; 
            &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt;&lt;span class="na"&gt;headerShown&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;}}&lt;/span&gt; 
          &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Screen&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Profile&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;component&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;ProfileScreen&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Stack.Navigator&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/NavigationContainer&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;styles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;StyleSheet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;container&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;justifyContent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;center&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;alignItems&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;center&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;We crammed a lot of code into the app.js just to see if everything works (navigation, paper UI, and the icons).&lt;/p&gt;

&lt;p&gt;4.3) Then run &lt;code&gt;yarn run android&lt;/code&gt; and &lt;code&gt;yarn run ios&lt;/code&gt; (if you are on mac). The result should be &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%2Fi%2F7sr7do2o3yu6mu2t2l9z.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%2Fi%2F7sr7do2o3yu6mu2t2l9z.png" alt="Alt Text" width="800" height="803"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From here, You can customize it based on your needs or just simply what you want your RN Template to look like. After that we can finally start making the template structure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the actual template structure
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;If you've encountered problems, you can refer to the completed project here &lt;a href="https://github.com/roycechua23/testRNTemplateProject" rel="noopener noreferrer"&gt;https://github.com/roycechua23/testRNTemplateProject&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To make our custom React Native we need to follow this structure Esemesek on Github &lt;a href="https://github.com/Esemesek/react-native-new-template" rel="noopener noreferrer"&gt;https://github.com/Esemesek/react-native-new-template&lt;/a&gt;&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%2Fi%2F1v845d7dn17j99c77rxu.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%2Fi%2F1v845d7dn17j99c77rxu.png" alt="Alt Text" width="800" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Breaktime
&lt;/h2&gt;

&lt;p&gt;Fun story, I was following the earlier blog when I encountered an error saying something's wrong with my template and I the error messages pointed me to esemek's github repository (above) which should mean that this is the official. &lt;/p&gt;

&lt;p&gt;I did end up finding the official React Native Guide that points to esemek's repo but it wasn't easy to find because it's in the init.md of the react-native-community/cli repository here &lt;a href="https://github.com/react-native-community/cli/blob/master/docs/init.md#creating-custom-template" rel="noopener noreferrer"&gt;https://github.com/react-native-community/cli/blob/master/docs/init.md#creating-custom-template&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;It was a real adventure (trust me, you don't want to repeat it) trying to find this but anyway let's move on. &lt;/p&gt;

&lt;h2&gt;
  
  
  Continuation
&lt;/h2&gt;

&lt;p&gt;5.) Download or clone the repository on &lt;a href="https://github.com/Esemesek/react-native-new-template" rel="noopener noreferrer"&gt;https://github.com/Esemesek/react-native-new-template&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;6.) On your file explorer, create a new folder and for convenience name it after your template repository in my case  &lt;strong&gt;&lt;em&gt;testRNTemplate&lt;/em&gt; then rename your &lt;em&gt;ProjectName&lt;/em&gt; folder to template&lt;/strong&gt;  then copy it or move it (like I did) over to the newly created folder&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%2Fi%2Ff9mti6wpybgi3mwpxsqf.gif" 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%2Fi%2Ff9mti6wpybgi3mwpxsqf.gif" alt="Alt Text" width="771" height="435"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;7.) Copy over &lt;strong&gt;package.json&lt;/strong&gt;, &lt;strong&gt;script.js&lt;/strong&gt;, and &lt;strong&gt;template.config.js&lt;/strong&gt; from the &lt;strong&gt;react-native-new-template&lt;/strong&gt; folder over to your newly created &lt;strong&gt;testRNTemplate&lt;/strong&gt; folder.&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%2Fi%2F0mk0iaox02ua1ax66jeh.gif" 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%2Fi%2F0mk0iaox02ua1ax66jeh.gif" alt="Alt Text" width="770" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;8.) In the &lt;strong&gt;testRNTemplate&lt;/strong&gt; folder modify the contents of package.json with your details 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;{
  "name": "testrntemplate",
  "version": "0.0.1",
  "description": "React Native Template",
  "repository": "https://github.com/roycechua23/testRNTemplate.git",
  "author": "Royce Chua",
  "license": "MIT"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Please remember to change your repository based on your specific repository because that repository is specific to the repository I made in Step 1.&lt;/p&gt;

&lt;p&gt;9.) At the &lt;strong&gt;testRNTemplate&lt;/strong&gt; folder, open a terminal and you can now push all of the code to the repository we created in 1.) using git. You can refer to these commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git init 
git add . 
git commit -m "first commit"
git remote add origin https://github.com/roycechua23/testRNTemplate.git
git branch -M main
git push -u origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fwpxqlddb6r4wyhoate5t.gif" 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%2Fwpxqlddb6r4wyhoate5t.gif" alt="Alt Text" width="926" height="502"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;10.) Give it a try by opening a terminal and running&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx react-native init SomeApp --template https://github.com/roycechua23/testRNTemplate.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fi%2Fjmdeed2j0o4zthl3zefc.gif" 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%2Fi%2Fjmdeed2j0o4zthl3zefc.gif" alt="Alt Text" width="929" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Installation complete:&lt;br&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%2Fi%2F5d6nbnkg6sturpvz5exq.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%2Fi%2F5d6nbnkg6sturpvz5exq.png" alt="Alt Text" width="800" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should see the same screens we made a while ago on Android and iOS. This template can be reused over and over again saving you time and trouble.&lt;/p&gt;

&lt;p&gt;If this article/blog/tutorial helped you and you would like to keep supporting my work, I would appreciate it if you would buy me a coffee here: &lt;a href="https://www.buymeacoffee.com/royce.chua" rel="noopener noreferrer"&gt;https://www.buymeacoffee.com/royce.chua&lt;/a&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>boilerplate</category>
      <category>template</category>
      <category>custom</category>
    </item>
    <item>
      <title>A Beginners Guide/Tutorial to Redux with React Native and a Todo App</title>
      <dc:creator>Royce Chua</dc:creator>
      <pubDate>Sun, 04 Oct 2020 17:05:12 +0000</pubDate>
      <link>https://dev.to/roycechua/redux-todo-app-in-react-native-4of2</link>
      <guid>https://dev.to/roycechua/redux-todo-app-in-react-native-4of2</guid>
      <description>&lt;p&gt;I would just like to share this implementation of the Todo App with React Native and Redux that is patterned after the folder structure in the Todo App in the Basic Tutorial of the React Redux Documentation so I decided to make this a beginners guide to Redux article as well to explain the app I shared below.&lt;/p&gt;

&lt;p&gt;Here is the expo link:&lt;br&gt;
&lt;a href="https://snack.expo.io/@roycechua/redux-react-native-sample-simple-todo" rel="noopener noreferrer"&gt;https://snack.expo.io/@roycechua/redux-react-native-sample-simple-todo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to try it out first, then if you need the explanations about the app and Redux then here is my take on it below. If you want more formal explanations by the way please refer to the documentations below or visit other more detailed explanations in the dev.to community.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Redux Documentation (&lt;a href="https://redux.js.org/" rel="noopener noreferrer"&gt;https://redux.js.org/&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is not directly related to React/React Native because Redux can be used with other Frameworks as well. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React-Redux Documentation (&lt;a href="https://react-redux.js.org/" rel="noopener noreferrer"&gt;https://react-redux.js.org/&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This contains the functions and component we need to use Redux with React/React Native.  &lt;/p&gt;
&lt;h1&gt;
  
  
  What can the app do?
&lt;/h1&gt;

&lt;p&gt;This Todo App simply allows you to add and remove tasks as shown in the snack.expo.io. I did this because I found it hard to actually study the React Todo App because of how much stuff is on there. So I made this app from scratch as well as the article to help beginners, or developers in general including myself who want to learn about Redux and how it works on React Native.&lt;/p&gt;
&lt;h1&gt;
  
  
  Redux?
&lt;/h1&gt;

&lt;p&gt;So if you don't know what's Redux, you can just think of it like a collection of functions with a component called the &lt;strong&gt;Provider&lt;/strong&gt; that allows you to access and change your state from any component within the app. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Redux&lt;/strong&gt; is a State Management Library for projects that have so many state variables that needs to be accessed from multiple components as well as for many other reasons you can read about in their official websites. Redux mostly removes the need to pass state values as props around components (in some instances components that have components that have components.. so on) just to get other state values like your App Settings. &lt;/p&gt;
&lt;h1&gt;
  
  
  The Important Parts
&lt;/h1&gt;

&lt;p&gt;The 5 important parts for anyone starting out in learning about Redux should focus on understanding are these:&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Store
&lt;/h2&gt;

&lt;p&gt;Store is like a literal storage area, A plastic container with Dividers. You can either retrieve or update what's inside of those little boxes inside (Don't mind what's inside).&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%2Fi%2Fk7itdzzoryx7670wxj69.jpg" 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%2Fi%2Fk7itdzzoryx7670wxj69.jpg" alt="Alt Text" width="800" height="435"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;store&lt;/strong&gt; is the &lt;strong&gt;global app state container&lt;/strong&gt; and its made accessible by the Provider component from &lt;strong&gt;react-redux&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; 
   /* The Rest of your App's Components */ 
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's why in the &lt;strong&gt;App.js&lt;/strong&gt; file which is my most top-level component in the App. The code looks like this &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%2Fi%2Fjmu0amna272a1bhp7mje.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%2Fi%2Fjmu0amna272a1bhp7mje.png" alt="Alt Text" width="800" height="518"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice how the store is given as a prop, the value of the prop which I conveniently named store as well but... What is being passed to the store prop?&lt;/p&gt;

&lt;p&gt;Simply put a store is just(but not really just) a &lt;strong&gt;Function that returns an Object or Array&lt;/strong&gt; but most of the time an object.&lt;/p&gt;

&lt;p&gt;You can change up the code in the snack to be like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt; &lt;span class="na"&gt;store&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt; 
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;TodoApp&lt;/span&gt;&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;/&lt;/span&gt;&lt;span class="na"&gt;Provider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So know we know what the store requires, a function that returns an object. &lt;/p&gt;

&lt;p&gt;So what's the object? It's your global state.&lt;/p&gt;

&lt;p&gt;But remember the major rule, you cannot directly modify or make changes to that object like you can do with a normal Javascript Object because we want to make its contents easy to determine or determinable (if there's such a word). &lt;/p&gt;

&lt;p&gt;That fat arrow function we created that to return an empty object is actually what we'll use to make changes to the state. Enter the reducer but for now will go back to the snack.&lt;/p&gt;

&lt;p&gt;Now that we know this let's explore what's on the snack. If you would notice the &lt;code&gt;import store from './redux/store'&lt;/code&gt; when you open the file you see this&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%2Fi%2Ftgnpkcn5xyalw7osxzgi.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%2Fi%2Ftgnpkcn5xyalw7osxzgi.png" alt="Alt Text" width="800" height="244"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What's createStore()? The &lt;strong&gt;createStore&lt;/strong&gt; function basically adds some additional functions like &lt;strong&gt;.dispatch()&lt;/strong&gt; that will allow you to send an action to the reducer but it still returns your state.&lt;/p&gt;

&lt;p&gt;Inside the createStore is the reducer which is what we'll be talking about next.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Reducer
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;reducer&lt;/strong&gt; is just a function that returns an object either your entire state if you're only using 1 Reducer like in our example or multiple pieces of the global state (Like the boxes above inside the 1 big container). &lt;/p&gt;

&lt;p&gt;What does this function take in as arguments? The reducer function takes in two things: A &lt;strong&gt;State&lt;/strong&gt;, and an &lt;strong&gt;Action&lt;/strong&gt;. An &lt;strong&gt;action&lt;/strong&gt; is just a Javascript Object with two keys &lt;br&gt;
&lt;code&gt;{ type: 'ADD_TODO', payload: { /* Whatever value(s) you want */ } }&lt;/code&gt;&lt;br&gt;
But let's talk more about Actions later, let's focus on Reducers. &lt;/p&gt;

&lt;p&gt;Here is the Todos Reducer simplified and commented (I purposely changed the code here compared to the snack so you could see a variation in the implementation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;todo_list&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;todos_reducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// action.type is a String&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ADD_TODO&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="c1"&gt;// The name of the action tells what it's gonna do &lt;/span&gt;
      &lt;span class="c1"&gt;// Add any code you need here &lt;/span&gt;

      &lt;span class="cm"&gt;/* 
        This is essentially a new object with values copied from 
        state along with a new todo_list 
        return {
             ...state, 
             // new todo_list (don't forget to copy existing todo items)
        } 
      */&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
           &lt;span class="na"&gt;todo_list&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;todo_list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; 
      &lt;span class="p"&gt;}&lt;/span&gt; 
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DELETE_TODO&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="cm"&gt;/* 
        state.todo_list.filter() will return a new array
        without the elements that you specified in the condition.
      */&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;todo_list&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;todo_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
           &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nl"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reason the documentation calls it a &lt;strong&gt;pure function&lt;/strong&gt; is because &lt;strong&gt;we do not and should not modify the state we return&lt;/strong&gt; but what we could do is create a copy of the current state then either exclude(for delete) or include(add or update) our changes or additions to the state. Also, &lt;strong&gt;Asynchronous code&lt;/strong&gt; are not allowed in a reducer.&lt;/p&gt;

&lt;p&gt;The point is reducer functions either return the original state or a &lt;strong&gt;brand new state&lt;/strong&gt; whose values are copied from the original state. &lt;/p&gt;

&lt;p&gt;Going back to this where we see &lt;strong&gt;rootReducer&lt;/strong&gt;&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%2Fi%2Ftgnpkcn5xyalw7osxzgi.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%2Fi%2Ftgnpkcn5xyalw7osxzgi.png" alt="Alt Text" width="800" height="244"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What is the rootReducer? We need to go to the actual file itself on the snack, there is another folder on redux named reducers. &lt;/p&gt;

&lt;p&gt;The index.js file contains a single most important function which is &lt;strong&gt;combineReducers({ todos })&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Just to be clear &lt;strong&gt;rootReducer is actually combineReducers({ todos })&lt;/strong&gt;. The reason why we hid it away is because we just want to make the code more manageable and nice to look at.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;combineReducers()&lt;/strong&gt; from the redux library simply &lt;em&gt;allows you to combine multiple reducer functions&lt;/em&gt; which I've said holds pieces of your global state. For example, besides todos_reducer, when the app grows larger it might have a user account portion of the state that will need its own reducer.  &lt;/p&gt;

&lt;p&gt;So why did I wrap my todos reducer inside a combineReducers() function when I only had one reducer? It's to prepare my app to be scaled to accommodate multiple reducers if it ever does.&lt;/p&gt;

&lt;p&gt;You can just think of combineReducers as one big reducer function composed of many smaller reducer functions.&lt;/p&gt;

&lt;p&gt;Now, going to my todos reducer we're going to find that it only varies a little bit from what I already made above &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%2Fi%2Fg8hm5vtcjwu9kab80qou.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%2Fi%2Fg8hm5vtcjwu9kab80qou.png" alt="Alt Text" width="800" height="570"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to try it while your reading this part. &lt;/p&gt;

&lt;p&gt;So what does the &lt;strong&gt;global state&lt;/strong&gt; look like if we have added some todos?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="nl"&gt;todos&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
        &lt;span class="na"&gt;todos_list&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;task&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Go for a walk&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;task&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Take your vitamins&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the reason why the global store should return an object, because when you eventually have more than one reducer, eventually every reducer will have a key in the global state and its value is the &lt;strong&gt;initialState&lt;/strong&gt; you defined in that reducer file. &lt;/p&gt;

&lt;p&gt;So now we know the store and reducer, we can finally shed some light on Actions which we've already seen here on Reducer.&lt;/p&gt;

&lt;h1&gt;
  
  
  3. Actions
&lt;/h1&gt;

&lt;p&gt;Actions as I said before is nothing more than another Javascript object but it has two keys (as a standardized way only, it's not strict) which are &lt;strong&gt;type&lt;/strong&gt; and &lt;strong&gt;payload&lt;/strong&gt;. &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%2Fi%2F9r503kkhqt4tqmh5n0o4.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%2Fi%2F9r503kkhqt4tqmh5n0o4.png" alt="Alt Text" width="800" height="535"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From my snack example on the actions.js file here, you can see that this is exactly what it does, it returns an object. &lt;/p&gt;

&lt;p&gt;The functions that returns the action object are called the &lt;strong&gt;action creators&lt;/strong&gt;. Action creators is what we will be importing to our React Native / React Components.&lt;/p&gt;

&lt;p&gt;Remember that the Action object (shown below) is what will tell the Reducer function what to do and the data it needs to do the intended task.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ADD_TODO&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="nx"&gt;nextTodoId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;task&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our addTodo action creator can take in input from the user in the component when we call it later but in fact, &lt;strong&gt;if&lt;/strong&gt; I didn't need parameters or inputs from the user in the addTodo action creator, I would have just simply written the &lt;strong&gt;addTodo&lt;/strong&gt; action as&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;addTodo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ADD_TODO&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="nx"&gt;nextTodoId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;task&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A JAVASCRIPT OBJECT WITH NO WAY OF GETTING USER INPUT&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So what is special about Actions is its purpose. &lt;/p&gt;

&lt;p&gt;Again as a constant reminder, &lt;strong&gt;Actions&lt;/strong&gt; dictate what code should the reducer execute assuming that it knows that action (remember the switch statement?). That's the purpose of the &lt;strong&gt;action.type&lt;/strong&gt; and &lt;strong&gt;action.payload&lt;/strong&gt;. The &lt;strong&gt;action.payload&lt;/strong&gt; is the actual data you want to store in the state or use for updating or deleting data in the state. &lt;/p&gt;

&lt;p&gt;But the main point about Actions is that it isn't capable of doing anything it's only a message to be sent to the reducer so that the reducer knows what to do with your state.&lt;/p&gt;

&lt;p&gt;So then, How does the message reach the Reducer(s)? &lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;dispatch&lt;/strong&gt; function that we got from createStore() remember?&lt;/p&gt;

&lt;h1&gt;
  
  
  4. Dispatch
&lt;/h1&gt;

&lt;p&gt;If you'll visit the Redux documentation you'll see a demo of how dispatch is used in their counter app.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;store.dispatch({ type: 'INCREMENT' })&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is how the Action reaches the Reducer because remember the store creation?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let store = createStore(Your_Reducer);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In short, the dispatch is a function from your created store that is used to send your action to the reducer(s) and the reducer(s) will determine what to do using their &lt;strong&gt;switch case comparison&lt;/strong&gt; with &lt;strong&gt;action.type&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;But, you may be wondering because my snack.expo app does not have this dispatch()? so where is it? &lt;/p&gt;

&lt;p&gt;There's a little magic the &lt;strong&gt;react-redux&lt;/strong&gt; library did for us to avoid manually passing the dispatch() from component to component to component... as well as other functions &lt;em&gt;unless we explicitly need to&lt;/em&gt; and that's through the &lt;strong&gt;connect()&lt;/strong&gt; higher-ordered function.&lt;/p&gt;

&lt;h1&gt;
  
  
  5. Connect
&lt;/h1&gt;

&lt;p&gt;connect() which is imported from &lt;strong&gt;react-redux&lt;/strong&gt; is the last important part of our Redux for beginners journey because this is the function that allows you to perform dispatch() in your component but also retrieve any redux state variables you want to access for your component.&lt;/p&gt;

&lt;p&gt;I made this todoapp a one liner so that you can quickly go to it on screens/TodoApp. Observe these imports on the snack.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;connect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-redux&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;addTodo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;deleteTodo&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../redux/actions&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then scroll to the bottom and find the export default code.&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%2Fi%2Fudbyq1mp2pheny6t6pq2.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%2Fi%2Fudbyq1mp2pheny6t6pq2.png" alt="Alt Text" width="800" height="553"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It looks weird but essentially the main syntax to use the connect is &lt;br&gt;
&lt;code&gt;export default connect()(YourComponent);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;But what's the magic that allows this component to access our todo list for display? and how does this component allow adding and deleting a todo?&lt;/p&gt;

&lt;p&gt;The magic is definitely not black magic but the connect() does a lot of things for you already so you don't have to. &lt;/p&gt;

&lt;p&gt;connect() should be passed with two objects, the first one is the &lt;strong&gt;mapStateToProps&lt;/strong&gt; object (again just a standardized name) and &lt;strong&gt;mapDispatchToProps&lt;/strong&gt; object.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;mapStateToProps&lt;/strong&gt; object if you follow my code which is actually based on the generic redux syntax. This code allows you to retrieve the redux state through the state parameter and assign a key to that redux state variable. In my case I needed to return the todos_list so I could display it to the screen. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important: Remember that you need to retrieve them as prop objects (either destructured or as props.todos_list)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;mapDispatchToProps&lt;/strong&gt;, you will need to add the actions to that object and they will automatically be wrapped around in the dispatch() function like this &lt;strong&gt;dispatch(addTodo)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But I could have also implemented it this way just for the sake of having a choice. &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%2Fi%2Fnmaed50r2ummvrtmi088.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%2Fi%2Fnmaed50r2ummvrtmi088.png" alt="Alt Text" width="428" height="107"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my case for this app at least, this method was unnecessary. So I used the more convenient one in my snack. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important: Remember that you still need to retrieve them as prop objects (either destructured or as props.addTodo)&lt;/strong&gt;&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%2Fi%2Ft6b6nzq95h10bkzom5he.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%2Fi%2Ft6b6nzq95h10bkzom5he.png" alt="Alt Text" width="800" height="288"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Simply calling the mapped action like addTodo(), allowed me to quickly invoke the dispatch function by calling the addTodo function that returns my Action object which gets interpreted(like the example below) then sent to the rootReducer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ADD_TODO&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;task&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Go for a walk&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are many ways that the &lt;strong&gt;connect()&lt;/strong&gt; function can be confusing as well as the &lt;strong&gt;mapStateToProps&lt;/strong&gt; and &lt;strong&gt;mapDispatchToProps&lt;/strong&gt; object but this is one approach I could suggest you to try.&lt;/p&gt;

&lt;p&gt;There's totally more information about this on the documentation of &lt;strong&gt;react-redux&lt;/strong&gt; &lt;a href="https://react-redux.js.org/using-react-redux/connect-mapstate" rel="noopener noreferrer"&gt;here for mapStatetoProps&lt;/a&gt; and &lt;a href="https://react-redux.js.org/using-react-redux/connect-mapdispatch" rel="noopener noreferrer"&gt;here for mapDispatchtoProps&lt;/a&gt; which hopefully after reading this article can help you navigate it better.&lt;/p&gt;

&lt;p&gt;And that's it for the beginners guide to Redux. If you take the time to really understand these 5 things at least to the point where your comfortable by making your own app with Redux, you'll understand it faster (trust me).&lt;/p&gt;




&lt;p&gt;One of the authors of Redux Dan Abramov also gave reasons why we might not need Redux which you can visit &lt;a href="https://medium.com/@dan_abramov/you-might-not-need-redux-be46360cf367" rel="noopener noreferrer"&gt;here&lt;/a&gt; on Medium so I definitely would read it after going through all this laborious work because implementing Redux at the end of the day is still dependent on you and your application's needs unless your work requires it (so you don't really have a choice). &lt;/p&gt;

&lt;h1&gt;
  
  
  Where do we go from here?
&lt;/h1&gt;

&lt;p&gt;It's totally up to you but I suggest to practice more on this fundamentals before considering other Redux stuff but here you go&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Need to make your asynchronous code work with the reducer? &lt;br&gt;
Check out &lt;a href="https://redux-saga.js.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Redux Saga&lt;/strong&gt;&lt;/a&gt; which is what I use at work or &lt;a href="https://github.com/reduxjs/redux-thunk" rel="noopener noreferrer"&gt;&lt;strong&gt;Redux Thunk&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Want to make the processes faster? You know avoiding all those typing? &lt;br&gt;
Check out &lt;a href="https://github.com/jkeam/reduxsauce" rel="noopener noreferrer"&gt;&lt;strong&gt;Reduxsauce&lt;/strong&gt;&lt;/a&gt; or &lt;a href="https://redux-toolkit.js.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;ReduxJS Toolkit&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://react-redux.js.org/api/hooks" rel="noopener noreferrer"&gt;&lt;strong&gt;Redux hooks&lt;/strong&gt;&lt;/a&gt; will allow you to do a different implementation of Redux on your app, check it out too.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There's really so many more but that's the most important ones. &lt;/p&gt;

&lt;p&gt;Thanks for taking the time to read this, hope it helped!&lt;/p&gt;

&lt;p&gt;Your support would be very much appreciated. Buying me a coffee would mean a lot &lt;br&gt;
&lt;a href="https://www.buymeacoffee.com/royce.chua" rel="noopener noreferrer"&gt;https://www.buymeacoffee.com/royce.chua&lt;/a&gt;&lt;/p&gt;

</description>
      <category>redux</category>
      <category>reactnative</category>
      <category>react</category>
    </item>
  </channel>
</rss>
