<?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: Arjay</title>
    <description>The latest articles on DEV Community by Arjay (@arjayosma).</description>
    <link>https://dev.to/arjayosma</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%2F126548%2F2d11e2fd-8dbd-4a16-83d1-86a9acbf9bed.jpeg</url>
      <title>DEV Community: Arjay</title>
      <link>https://dev.to/arjayosma</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arjayosma"/>
    <language>en</language>
    <item>
      <title>Launched a SaaS Starter Kit on Product Hunt</title>
      <dc:creator>Arjay</dc:creator>
      <pubDate>Thu, 03 Mar 2022 15:41:52 +0000</pubDate>
      <link>https://dev.to/arjayosma/launched-a-saas-starter-kit-on-product-hunt-52no</link>
      <guid>https://dev.to/arjayosma/launched-a-saas-starter-kit-on-product-hunt-52no</guid>
      <description>&lt;p&gt;Hi Devs! 👋&lt;/p&gt;

&lt;p&gt;I recently launched Nextacular over at Product Hunt: &lt;a href="https://www.producthunt.com/posts/nextacular"&gt;https://www.producthunt.com/posts/nextacular&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'm very excited to share &lt;a href="https://nextacular.co"&gt;Nextacular🌙&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It has been in development since January this year and I've been gathering feedback on what are the basic SaaS features that founders should not sweat about to help them focus on building the core of their solutions. The feedback gathered resulted in Nextacular, which is a SaaS starter-kit built on top of modern technologies.&lt;/p&gt;

&lt;p&gt;Also, in our startup, our team didn't have a standard way of building our applications, so I thought of spending some time crafting this Workspace-based multi-tenant SaaS starter kit to be deployed on Vercel. This is an open-source initiative to contribute to the development community.&lt;/p&gt;

&lt;p&gt;More details about the app in the website and in the Product Hunt Listing.&lt;/p&gt;

&lt;p&gt;Please let me know your feedback! I appreciate all comments and inputs, and I'll constantly improve Nextacular to deliver an open-source alternative to building your next SaaS. 💬❤️&lt;/p&gt;

&lt;p&gt;Project Repository can be found here: &lt;a href="https://github.com/arjayosma/nextacular"&gt;https://github.com/arjayosma/nextacular&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Appreciate your support!&lt;/p&gt;

</description>
      <category>saas</category>
      <category>nextjs</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Set Up Firebase Phone Authentication in Expo (SDK 37) without Ejecting</title>
      <dc:creator>Arjay</dc:creator>
      <pubDate>Mon, 03 Aug 2020 11:14:53 +0000</pubDate>
      <link>https://dev.to/arjayosma/set-up-firebase-phone-authentication-in-expo-sdk-37-without-ejecting-52lb</link>
      <guid>https://dev.to/arjayosma/set-up-firebase-phone-authentication-in-expo-sdk-37-without-ejecting-52lb</guid>
      <description>&lt;h1&gt;
  
  
  Set Up Firebase Phone Authentication in Expo (SDK 37) without Ejecting
&lt;/h1&gt;

&lt;p&gt;I am so excited about a lot of things for the release of SDK 37. One of which is that Expo made it fairly easy to implement Firebase Phone Number Authentication. We just have to set up a few things first before we can actually use phone authentication in our projects.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3840%2F1%2Ac7_amBdTMerg3kHCiEd60A.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3840%2F1%2Ac7_amBdTMerg3kHCiEd60A.jpeg" alt="Photo by [Dan Nelson](https://unsplash.com/@danny144?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/phone-lock?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText)"&gt;&lt;/a&gt;&lt;em&gt;Photo by &lt;a href="https://unsplash.com/@danny144?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Dan Nelson&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/phone-lock?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;An Expo managed workflow project. &lt;em&gt;If you don’t have one, follow the instructions &lt;a href="https://expo.io/learn" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A Firebase project. &lt;em&gt;If you don’t have one, just go to your &lt;a href="https://firebase.google.com/" rel="noopener noreferrer"&gt;Firebase Console&lt;/a&gt; and set it up. Make sure to register a Firebase web app.&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Install Dependencies
&lt;/h2&gt;

&lt;p&gt;We need to install the dependencies identified below to make our authentication work:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ expo install expo-firebase-recaptcha react-native-webview firebase
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;By installing the expo-firebase-recaptcha dependency, we now have the components for creating the reCAPTCHA verifier to be used for our phone authentication workflow.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;NOTE: expo-firebase-recaptcha requires react-native-webview to be installed as well. This is because the reCAPTCHA verifier will be shown inside a WebView modal.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Firebase Settings
&lt;/h3&gt;

&lt;p&gt;First things first make sure that the &lt;strong&gt;Phone&lt;/strong&gt; sign-in method is enabled.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AUK_3LIfLp2y0s77_RXhJOw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AUK_3LIfLp2y0s77_RXhJOw.png" alt="Enabled Phone Sign-In Method"&gt;&lt;/a&gt;Enabled Phone Sign-In Method&lt;/p&gt;

&lt;p&gt;Let’s grab a copy of our Firebase configuration inside our console from one of our Firebase web apps. Just replace the &lt;strong&gt;XXXXXX&lt;/strong&gt; values with your own configuration values.&lt;/p&gt;

&lt;p&gt;Create a file firebase.js from within our project and import our Firebase dependency&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="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;firebase&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;firebase&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@firebase/auth&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;firebaseConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;AIzaXXXXXX&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;authDomain&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;expo-firebase-phone-auth-XXXXXXX.firebaseapp.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;databaseURL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://expo-firebase-phone-auth-XXXXXXX.firebaseio.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;projectId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;expo-firebase-phone-auth-XXXXXXX&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;storageBucket&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;expo-firebase-phone-auth-XXXXXXX.appspot.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;messagingSenderId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;XXXXXX&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;appId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1:XXXXXXX:web:a1XXXXXXX&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;measurementId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;G-XXXXXXX&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nx"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;initializeApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firebaseConfig&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;firebase&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Optional:&lt;/strong&gt; You can save this configuration inside your app.json file as an extra field. If you do this approach, make sure to install expo-constants dependency to access these values at runtime.&lt;/p&gt;

&lt;h3&gt;
  
  
  App Set-Up
&lt;/h3&gt;

&lt;p&gt;For the purpose of this article, let’s just play around a single screen application. The &lt;em&gt;gists&lt;/em&gt; below are from a single source file but are broken down into different sections for simplicity and ease.&lt;/p&gt;

&lt;p&gt;This app will have two input boxes: (1) for the phone number; and (2) for the verification code. Each with designated buttons that will execute our verification process.&lt;/p&gt;

&lt;p&gt;We’ll also add the reCAPTCHA modal, which will help us validate if our user is a robot or not.&lt;/p&gt;

&lt;p&gt;Let’s now implement the sendVerification and confirmCode functions.&lt;/p&gt;

&lt;p&gt;That’s it! We’re now ready to test our application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Seeing it in Action
&lt;/h3&gt;

&lt;p&gt;Let’s add our mobile number in the first input field. Let’s also add the country code so that we can definitely receive the SMS. Press the &lt;strong&gt;Send Verification&lt;/strong&gt; button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Optional&lt;/strong&gt;: There’s also an option in firebase that we can add test numbers to avoid sending spam messages to the correct number.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A3NW8i8Rn86Wlyc5R4zLZZw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A3NW8i8Rn86Wlyc5R4zLZZw.jpeg" alt="Our application screen"&gt;&lt;/a&gt;&lt;em&gt;Our application screen&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After pressing the &lt;strong&gt;Send Verification&lt;/strong&gt; button, in a few seconds, we will receive an SMS from “&lt;strong&gt;Phone Code&lt;/strong&gt;” containing a 6-digit code. We’ll copy that code and add that into our second input field, which is the verification code field. After putting the verification code, press the &lt;strong&gt;Send Confirmation&lt;/strong&gt; button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AaSJG2vUNY5utBsJsGzTIew.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AaSJG2vUNY5utBsJsGzTIew.jpeg" alt="A sample SMS message with a verification code"&gt;&lt;/a&gt;&lt;em&gt;A sample SMS message with a verification code&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Once done, inside our Firebase console, we will be able to see a newly added user (phone number) into our &lt;strong&gt;Users&lt;/strong&gt; tab.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ArRMbH5dFaRoQm3g6iO2pnA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ArRMbH5dFaRoQm3g6iO2pnA.png" alt="Newly added user"&gt;&lt;/a&gt;&lt;em&gt;Newly added user&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Congratulations! We were able to implement Firebase phone authentication into our managed Expo project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Phone authentication is one of the many ways we can verify our users. Implemented properly, it’s also one of the secure ways to validate if our users are not robots. With the release of Expo’s SDK 37, they made it very easy to implement this method of authenticating our users without ejecting.&lt;/p&gt;

&lt;p&gt;If you wish to take a look at an example, I prepared a small project and you can access it here: &lt;a href="https://github.com/arjayosma/expo-firebase-phone-authentication" rel="noopener noreferrer"&gt;https://github.com/arjayosma/expo-firebase-phone-authentication&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you liked this article and wish to receive more articles like this, &lt;strong&gt;read my blog at &lt;a href="https://arjayosma.com" rel="noopener noreferrer"&gt;https://arjayosma.com&lt;/a&gt; or follow&lt;/strong&gt; me here and on &lt;a href="https://twitter.com/arjayosma" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thank you and I hope you enjoyed the article! Let me know your thoughts on how we can enhance this further.&lt;/p&gt;

&lt;p&gt;You may wish to discuss different tech and business stuff, drop an email to &lt;a href="mailto:arjay.osma@gmail.com"&gt;arjay.osma@gmail.com&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>javascript</category>
      <category>expo</category>
      <category>firebase</category>
    </item>
    <item>
      <title>How To Simplify React Forms State Handlers</title>
      <dc:creator>Arjay</dc:creator>
      <pubDate>Thu, 14 May 2020 14:00:00 +0000</pubDate>
      <link>https://dev.to/arjayosma/how-to-simplify-react-forms-state-handlers-28lf</link>
      <guid>https://dev.to/arjayosma/how-to-simplify-react-forms-state-handlers-28lf</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Recently posted this article about a React Design Pattern on my blog and wanted to share it here in Dev.to as well.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;Web application forms are essential for data processing and display of information. We’ve had our fair share of using them for the reasons identified above. They’re an inevitable part of web development.&lt;/p&gt;

&lt;p&gt;While learning React, you must’ve encountered constructs such as the example below from various tutorials. A piece of small code snippet that shows you how to use &lt;a href="https://reactjs.org/docs/forms.html#controlled-components"&gt;controlled components&lt;/a&gt; in &lt;code&gt;render&lt;/code&gt; functions and how to assign them into different state variables.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hook Example (&amp;gt; v16.8) - Functional Component
&lt;/h3&gt;

&lt;p&gt;In this example, let’s assume we have three input fields that need to be stored inside our component’s state.&lt;br&gt;
&lt;/p&gt;

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

const MyForm = () =&amp;gt; {
  // Form states
  const [firstName, setFirstName] = useState("")
  const [lastName, setLastName] = useState("")
  const [email, setEmail] = useState("")

  // Form handlers
  const handleFirstNameChange = event =&amp;gt; {
    setFirstName(event.target.value)
  }
  const handleLastNameChange = event =&amp;gt; {
    setLastName(event.target.value)
  }
  const handleEmailChange = event =&amp;gt; {
    setEmail(event.target.value)
  }

  // Render components
  return (
    &amp;lt;&amp;gt;
      &amp;lt;input onChange={handleFirstNameChange} type="text" value={firstName} /&amp;gt;
      &amp;lt;input onChange={handleLastNameChange} type="text" value={lastName} /&amp;gt;
      &amp;lt;input onChange={handleEmailChange} type="text" value={email} /&amp;gt;
    &amp;lt;/&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Notice that we have three different &lt;code&gt;onChange&lt;/code&gt; handlers for each of our input fields. That’s a lot and will be a lot more if we add another input field.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;Our example above will definitely work. However, when we encounter a requirement that will demand us to add another input field for our form, we will be forced to add another state handler.&lt;/p&gt;

&lt;p&gt;This may pose as a threat to the maintainability and readability of our dear code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;Fortunately, we have a simple pattern that we can use for us to retain the maintainability and readability of our source codes.&lt;/p&gt;

&lt;p&gt;We can create a custom React hook that we can use across our codebase repetitively without confusing our future selves. The solution will look something like the custom hook below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * src/hooks/form.js
 */
import { useState } from "react"

export const useInputState = initialValue =&amp;gt; {
  // Initialize state holder and value setter
  const [value, setValue] = useState(initialValue)
  // On value change handler
  const onChange = event =&amp;gt; setValue(event.target.value)
  // Reset the current state
  const clear = () =&amp;gt; setValue(initialValue)
  return [value, onChange, clear]
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This custom hook works by handling the state value internally. It will return the &lt;strong&gt;value&lt;/strong&gt; , &lt;strong&gt;change handler&lt;/strong&gt; , and the &lt;strong&gt;setter of the state&lt;/strong&gt; respectively, which will be used by the calling function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;To use the hook we recently created, see the example below that modifies our first example above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react"
import { useInputState } from "hooks/form"

const MyForm = () =&amp;gt; {
  // Form states and change handlers
  const [firstName, handleFirstNameChange] = useInputState("")
  const [lastName, handleLastNameChange] = useInputState("")
  const [email, handleEmailChange] = useInputState("")

  // Render components
  return (
    &amp;lt;&amp;gt;
      &amp;lt;input onChange={handleFirstNameChange} type="text" value={firstName} /&amp;gt;
      &amp;lt;input onChange={handleLastNameChange} type="text" value={lastName} /&amp;gt;
      &amp;lt;input onChange={handleEmailChange} type="text" value={email} /&amp;gt;
    &amp;lt;/&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We minimized the number of lines in our original code by using the custom hook that we just created. We called on the &lt;code&gt;useInputState&lt;/code&gt; hook and initialized it with the default value. Then we destructure the array returned by the hook with &lt;code&gt;value&lt;/code&gt; data and the &lt;code&gt;onChange&lt;/code&gt; function. In the modified code, we renamed the destructured values accordingly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Different Flavors
&lt;/h2&gt;

&lt;p&gt;This is not the only way to create and use this hook.&lt;/p&gt;

&lt;p&gt;While updating my source codes, I did not use the hook above. Instead, I used a different approach wherein the returned value of the hook is not an array but an object. Check out the code below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Declaration
export const useInputState = initialValue =&amp;gt; {
  const [value, setValue] = useState(initialValue)
  const onChange = event =&amp;gt; setValue(event.target.value)
  return {
    value,
    setValue,
    attributes: {
      value,
      onChange,
    },
  }
}

/* ------------------------------------------------------ */

// Usage
const MyForm = () =&amp;gt; {
  const { value: firstName, attributes } = useInputState("")
  // ...
  return (
    &amp;lt;&amp;gt;
      &amp;lt;input type="text" {...attributes} /&amp;gt;
      {/* ... */}
    &amp;lt;/&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As usual, you can play around this setup and take into consideration how you’re going to use this on your end.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits
&lt;/h2&gt;

&lt;p&gt;These are the benefits of using this hook:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Simple and clean code.&lt;/li&gt;
&lt;li&gt;Fewer lines to maintain.&lt;/li&gt;
&lt;li&gt;Readable code and easy to digest.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For sure, there’s a lot more than what was identified.&lt;/p&gt;

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

&lt;p&gt;The introduction of &lt;a href="https://reactjs.org/docs/hooks-intro.html"&gt;React hooks&lt;/a&gt; allows you to always use functions instead of having to juggle the existing concepts of React such as functions, classes, and Higher-Order Components. This makes our codebases lean and simple to maintain.&lt;/p&gt;

&lt;p&gt;We are also adding a new concept in our arsenal of &lt;a href="https://en.wikipedia.org/wiki/Software_design_pattern"&gt;Design Patterns&lt;/a&gt; that we can apply to our codebases, which can definitely make our development lives easier.&lt;/p&gt;

&lt;p&gt;Before we go, always remember to stay awesome!&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>designpatterns</category>
      <category>forms</category>
    </item>
    <item>
      <title>How To Conditionally Wrap A React Component</title>
      <dc:creator>Arjay</dc:creator>
      <pubDate>Tue, 05 May 2020 00:00:00 +0000</pubDate>
      <link>https://dev.to/arjayosma/how-to-conditionally-wrap-a-react-component-44gp</link>
      <guid>https://dev.to/arjayosma/how-to-conditionally-wrap-a-react-component-44gp</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Recently posted this article about a React Design Pattern on my blog and wanted to share it here in Dev.to as well.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;While working on your React project, you’ve probably encountered a scenario where you want to conditionally place a component inside a parent component.&lt;/p&gt;

&lt;p&gt;Maybe you’ve found yourself using this format in one of your codes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  condition ? (
    &amp;lt;ProtectedLayout&amp;gt;
      &amp;lt;p&amp;gt;This is a short message.&amp;lt;/p&amp;gt;
    &amp;lt;/ProtectedLayout&amp;gt;
  ) : (
    &amp;lt;UnprotectedLayout&amp;gt;
      &amp;lt;p&amp;gt;This is a short message.&amp;lt;/p&amp;gt;
    &amp;lt;/UnprotectedLayout&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Yes! We’ve been there and it is working. Nothing’s wrong. Convincing ourselves that if it works when the browser is refreshed, then it is already good for us.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;If you take a good look, there is a problem with this setup, and the problem is that we’re duplicating the code.&lt;/p&gt;

&lt;p&gt;How and why? In the example above, as mentioned, we’re writing the code above twice. Imagine if we have more than that as our child component, that alone will increase the number of lines we have to code and maintain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;For us to solve this issue, let’s create a function that will wrap our child component if it satisfies the condition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Wrapper = ({ children, condition, wrapper }) =&amp;gt;
  condition ? wrapper(children) : children
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This wrapping component works by passing a &lt;strong&gt;condition&lt;/strong&gt; and a &lt;strong&gt;wrapping&lt;/strong&gt; function as props and encloses the &lt;strong&gt;child&lt;/strong&gt; component via the function. Easy, right?&lt;/p&gt;

&lt;p&gt;Just 2 lines of code and let’s break it down, API style!&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Props&lt;/th&gt;
&lt;th&gt;Definition&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;children&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The component we want to wrap with the &lt;code&gt;wrapper&lt;/code&gt; function&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;condition&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The condition that will identify if the child component should be wrapped&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;wrapper&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A function that will accept the &lt;code&gt;children&lt;/code&gt; component and will return the already &lt;code&gt;wrapped&lt;/code&gt; component&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Usage
&lt;/h3&gt;

&lt;p&gt;To use this component, see the example below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Wrapper
  condition={shouldWrap}
  wrapper={children =&amp;gt; &amp;lt;ProtectedLayout&amp;gt;{children}&amp;lt;/ProtectedLayout&amp;gt;}
&amp;gt;
  &amp;lt;p&amp;gt;This is a short message.&amp;lt;/p&amp;gt;
&amp;lt;/Wrapper&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We enclose the &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; child component inside the &lt;code&gt;&amp;lt;Wrapper&amp;gt;&lt;/code&gt; component passing the different props needed.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;wrapper&lt;/code&gt; prop should receive the &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; child component as the function parameter and inside the wrapping function, we define how our &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; child will look like once the &lt;code&gt;condition&lt;/code&gt; prop is satisfied.&lt;/p&gt;

&lt;h2&gt;
  
  
  Different Flavors
&lt;/h2&gt;

&lt;p&gt;Of course, this is not the only flavor we can do to wrap our components. We also have alternative ways of doing this, but I’ll leave it up to you to find it out by playing around with the base function or wrapper component.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Take into consideration how you’re going to use this wrapping component for your codebase.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Possible Use Cases and Examples
&lt;/h2&gt;

&lt;p&gt;Here are possible use cases that I believe will require us to wrap our component(s) this way:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If you want to wrap your components into different wrappers.&lt;/li&gt;
&lt;li&gt;If you want OR not want to enclose your component.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  My Use Cases
&lt;/h2&gt;

&lt;p&gt;Most of my React projects require authentication, and given that setup, I receive features that demand distinct layouts for authenticated and unauthenticated users respectively. &lt;em&gt;Hence the example above&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Take a look at this code for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// The main component that uses the `wrapper` function
export default () =&amp;gt; {
  return (
    &amp;lt;BrowserRouter&amp;gt;
      &amp;lt;Switch&amp;gt;
        {/* Iterate through the list of routes */}
        {routes.map((item, index) =&amp;gt; {
          // Destructuring the individual route items
          const { component: Component, path, protectedPath } = item

          // The route component for the
          return (
            &amp;lt;Route
              key={index}
              {/* Conditionally wrapping the child component */}
              component={() =&amp;gt; (
                &amp;lt;Wrapper
                  condition={protectedPath}
                  wrapper={children =&amp;gt; &amp;lt;AdminLayout&amp;gt;{children}&amp;lt;/AdminLayout&amp;gt;}
                &amp;gt;
                  &amp;lt;Component /&amp;gt;
                &amp;lt;/Wrapper&amp;gt;
              )}
              exact
              path={path}
            /&amp;gt;
          )
        })}
      &amp;lt;/Switch&amp;gt;
    &amp;lt;/BrowserRouter&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Benefits
&lt;/h2&gt;

&lt;p&gt;These are the benefits of using this approach:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You get to have a clean code. Who wouldn’t want this, right?&lt;/li&gt;
&lt;li&gt;You will be able to practice the &lt;a href="https://dzone.com/articles/software-design-principles-dry-and-kiss"&gt;DRY and KISS principles&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;By practicing the two principles above, you can reuse this abstracted component again and again. Fewer lines to code and maintain.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;It may not be every day that we encounter these kinds of problems while coding. It’s also great to think twice if what we’re coding is going to be maintainable. You know, lesser headaches for our future selves.&lt;/p&gt;

&lt;p&gt;What we just did is an example of a &lt;a href="https://en.wikipedia.org/wiki/Software_design_pattern"&gt;Design Pattern&lt;/a&gt; that we can apply to our codebases.&lt;/p&gt;

&lt;p&gt;As developers, we should aim to find these recurring problems and find patterns that can be abstracted into a simple solution to make our lives easier.&lt;/p&gt;

&lt;p&gt;Finally, always remember to stay awesome!&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>designpatterns</category>
    </item>
    <item>
      <title>Our First Published App</title>
      <dc:creator>Arjay</dc:creator>
      <pubDate>Thu, 25 Apr 2019 01:26:25 +0000</pubDate>
      <link>https://dev.to/arjayosma/our-first-published-app-1nmc</link>
      <guid>https://dev.to/arjayosma/our-first-published-app-1nmc</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fw87cspobbrwk7y6rtop5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fw87cspobbrwk7y6rtop5.png" alt="Fridge Mobile App"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Fridge&lt;/strong&gt; - Reduce Wastes in Your Kitchen&lt;/p&gt;

&lt;p&gt;We recently launched our very first app. My partner and I have been working on this idea for the past few weeks and we're excited to announce that our very first app has been released into the wild.&lt;br&gt;
Feel free to download the application.&lt;/p&gt;

&lt;p&gt;Google Play Store: &lt;a href="http://bit.ly/FridgeGooglePlay" rel="noopener noreferrer"&gt;http://bit.ly/FridgeGooglePlay&lt;/a&gt;&lt;br&gt;
ProductHunt: &lt;a href="http://bit.ly/FridgeProductHunt" rel="noopener noreferrer"&gt;http://bit.ly/FridgeProductHunt&lt;/a&gt;&lt;br&gt;
Facebook Page: &lt;a href="http://bit.ly/FridgeMobile" rel="noopener noreferrer"&gt;http://bit.ly/FridgeMobile&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  About Fridge
&lt;/h2&gt;

&lt;p&gt;Fridge is a mobile application that helps you repurpose unused ingredients to reduce kitchen wastes. The app will require you to provide your ingredients and it will output awesome recipes for your reference.&lt;/p&gt;

&lt;h2&gt;
  
  
  Development
&lt;/h2&gt;

&lt;p&gt;The app has been developed using the managed workflow of &lt;a href="//expo.io"&gt;Expo&lt;/a&gt;. It has been a breeze developing the application using this platform.&lt;/p&gt;

&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;p&gt;Here are the features of the app:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Ingredients search
&lt;/li&gt;
&lt;li&gt;Recipe search (based on ingredients selected)
&lt;/li&gt;
&lt;li&gt;Viewing of recipes
&lt;/li&gt;
&lt;li&gt;Sharing to different platforms&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It's not rich in features yet, but we're positive we can deliver more features for the app moving forward.&lt;/p&gt;

&lt;h2&gt;
  
  
  Future
&lt;/h2&gt;

&lt;p&gt;We're considering into deploying the application into the App Store also to cater to our iOS users.&lt;/p&gt;

&lt;p&gt;🙏 Let us know what you think and feel free to message us if you have any questions!&lt;/p&gt;

&lt;p&gt;If you have development-related questions, please feel free to comment down below.&lt;/p&gt;

</description>
      <category>fridgemobile</category>
      <category>mobileapp</category>
      <category>expo</category>
      <category>reactnative</category>
    </item>
  </channel>
</rss>
