<?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: calebdeji</title>
    <description>The latest articles on DEV Community by calebdeji (@calebdeji).</description>
    <link>https://dev.to/calebdeji</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%2F164324%2F0144d0bb-405a-4330-89b7-711304f149d8.jpg</url>
      <title>DEV Community: calebdeji</title>
      <link>https://dev.to/calebdeji</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/calebdeji"/>
    <language>en</language>
    <item>
      <title>Automate Firebase cloud functions deployment with Github actions.</title>
      <dc:creator>calebdeji</dc:creator>
      <pubDate>Sun, 04 Jul 2021 08:31:38 +0000</pubDate>
      <link>https://dev.to/calebdeji/automate-firebase-cloud-functions-deployment-with-github-actions-5dbc</link>
      <guid>https://dev.to/calebdeji/automate-firebase-cloud-functions-deployment-with-github-actions-5dbc</guid>
      <description>&lt;p&gt;Deployment automation refers to the process that enables you to deploy your code to various environments at the occurrence of an event without human intervention. Deployment automation enables you to give little to no focus on the deployment process, hence saving you time that could be spent on other activities. &lt;/p&gt;

&lt;p&gt;Firebase cloud functions is a serverless framework that lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. You can read more about that &lt;a href="https://firebase.google.com/docs/functions"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Github actions provide a workflow that can help carry out various actions such as build the code in your repository, deploy to your production or staging environment, run tests on your code before carrying out some crucial operations, and so on. You can read more about Github actions &lt;a href="https://docs.github.com/en/actions/guides/about-continuous-integration"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This article assumes that you as a reader have some experience with firebase cloud functions, npm installed on your terminal, a firebase project created, and your cloud functions defined in your firebase project. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To deploy any firebase cloud functions project, you need to be authenticated via Firebase CLI but since GitHub actions will solely be responsible for the deployment process, you need to generate an authentication token from Firebase CLI and save it as a secret in your repository settings. &lt;/p&gt;

&lt;p&gt;To install Firebase CLI, open your terminal and run &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;npm install -g firebase-tools&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To generate the authentication token, run &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;firebase ci:login&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The  command above opens your browser and asks you to log in to the Google account connected to your firebase project. Upon login, a new token will be generated on your terminal. Open your Github repository and go to the Settings tab, click on the Secrets pane, copy and save the token generated on your terminal as a new secret. Once that's done, click on the Action tab, and click on &lt;strong&gt;&lt;em&gt;setup a workflow yourself&lt;/em&gt;&lt;/strong&gt;.&lt;br&gt;
Read and copy the following gist content to the new workflow file created.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;If you have custom environment variables used in your project, you need to store the environment data. You can use the below workflow code &lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Thanks for reading! Feel free to drop suggestions and questions in the comment box 😊.&lt;/p&gt;

</description>
      <category>automation</category>
      <category>deployment</category>
      <category>firebase</category>
      <category>firebasecloudfunctions</category>
    </item>
    <item>
      <title>Optimise rendering of children tree subscribed to Context API</title>
      <dc:creator>calebdeji</dc:creator>
      <pubDate>Mon, 14 Sep 2020 11:26:43 +0000</pubDate>
      <link>https://dev.to/calebdeji/optimise-rendering-of-children-tree-subscribed-to-context-api-18do</link>
      <guid>https://dev.to/calebdeji/optimise-rendering-of-children-tree-subscribed-to-context-api-18do</guid>
      <description>&lt;p&gt;A few months ago, I got to develop a web application that required optimal state management in the sense that each component in the application needs to re-render only when changes are made to state data bound to the component. Thinking of the perfect architecture that seemed to fit the project, I came up with an architectural pattern which followed the rule stating that the app should be contained in a global state manager ( that holds data that rarely &lt;em&gt;change&lt;/em&gt; such as authentication data) and also each route should have its own state manager ( Context API), hence to prevent unnecessary re-render whenever there's a change in data other routes.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This article assumes that you as a reader have some experience with state management using React. If you are new to React state management, I recommend that you check out this &lt;a href="https://kentcdodds.com/blog/application-state-management-with-react"&gt;article&lt;/a&gt; by Kent Dodds before proceeding.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Notice how each route encompasses a state manager that contains the route component. Putting this kind of structure in place is particularly important for the sake of readability, scalability, and maintainability. It is easy to handle errors in each route’s state manager, and &lt;em&gt;separation of concern&lt;/em&gt; actually makes development easy.&lt;/p&gt;

&lt;p&gt;I completed the project and it seemed perfect but then I noticed that each component subscribed to each route state manager re-rendered whenever changes were made to data held by the manager. The following is an example of what I meant&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  This is cool, so what is the problem?
&lt;/h3&gt;

&lt;p&gt;It works pretty well. However, the issue is that for every update made in the context data, all components that subscribed to the context API re-renders. We really do not want each expensive component subscribed to a particular context manager to re-render every time we update the state even though the data attached to the component didn't change. What shall we do to prevent this?&lt;/p&gt;

&lt;h3&gt;
  
  
  What's the solution to the problem then?
&lt;/h3&gt;

&lt;p&gt;If we were using class-based components, we could easily prevent re-renders with the &lt;strong&gt;&lt;em&gt;shouldComponentUpdate&lt;/em&gt;&lt;/strong&gt; method or employ the use of pure React components that are made for issues like this but these are functional components. Don't be scared, we have a savior called &lt;code&gt;useMemo&lt;/code&gt;. &lt;em&gt;&lt;code&gt;useMemo&lt;/code&gt;??&lt;/em&gt; Ah Yes.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;useMemo is a built-in React hook that returns a memoized value. It allows you recompute expensive functions only when one of the dependencies has changed&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Note the following:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;useMemo will only recompute the memoized value when one of the dependencies has changed. This optimization helps to avoid expensive calculations on every render. Remember that the function passed to &lt;code&gt;useMemo&lt;/code&gt; runs during rendering. Don’t do anything there that you wouldn’t normally do while rendering.  For example, side effects belong in the &lt;a href="https://reactjs.org/docs/hooks-reference.html#useeffect"&gt;&lt;code&gt;useEffect&lt;/code&gt; hook&lt;/a&gt;, not &lt;code&gt;useMemo&lt;/code&gt;. You can read more on &lt;code&gt;useMemo&lt;/code&gt; &lt;a href="https://reactjs.org/docs/hooks-reference.html#usememo"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;How do we use &lt;code&gt;useMemo&lt;/code&gt; in this kind of scenario? The answer to the “how” is shown in the code snippet below.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Our components would still re-execute, but React wouldn't re-render the child tree if all useMemo inputs were the same.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This pattern helps us to solve the problem we have at hand - any child of each component that subscribed to a particular context API only re-renders when the necessary data attached to its &lt;code&gt;useMemo&lt;/code&gt; changes.&lt;/p&gt;

&lt;p&gt;Context API shouldn't be used as a global state manager that holds data that changes frequently for performance's sake, you can use Redux for that. Thanks for reading.&lt;/p&gt;

&lt;p&gt;Feel free to drop suggestions and questions in the comments section below.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>NextJS throws error on navigating from the page that imports a script in the head tag</title>
      <dc:creator>calebdeji</dc:creator>
      <pubDate>Wed, 22 Apr 2020 06:11:53 +0000</pubDate>
      <link>https://dev.to/calebdeji/nextjs-throws-error-on-navigating-from-the-page-that-imports-a-script-in-the-head-tag-50d0</link>
      <guid>https://dev.to/calebdeji/nextjs-throws-error-on-navigating-from-the-page-that-imports-a-script-in-the-head-tag-50d0</guid>
      <description>&lt;div class="ltag__stackexchange--container"&gt;
  &lt;div class="ltag__stackexchange--title-container"&gt;
    
      &lt;div class="ltag__stackexchange--title"&gt;
        &lt;h1&gt;
          &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pTF_nE4a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/stackoverflow-logo-b42691ae545e4810b105ee957979a853a696085e67e43ee14c5699cf3e890fb4.svg" alt=""&gt;
            &lt;a href="https://stackoverflow.com/questions/61358305/nextjs-throws-error-on-navigating-from-the-page-that-imports-a-script-in-the-hea" rel="noopener noreferrer"&gt;
               NextJS throws error on navigating from the page that imports a script in the head tag
            &lt;/a&gt;
        &lt;/h1&gt;
        &lt;div class="ltag__stackexchange--post-metadata"&gt;
          &lt;span&gt;Apr 22 '20&lt;/span&gt;
            &lt;span&gt;Comments: 1&lt;/span&gt;
            &lt;span&gt;Answers: 0&lt;/span&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;a class="ltag__stackexchange--score-container" href="https://stackoverflow.com/questions/61358305/nextjs-throws-error-on-navigating-from-the-page-that-imports-a-script-in-the-hea" rel="noopener noreferrer"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5MiFESHx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/stackexchange-arrow-up-eff2e2849e67d156181d258e38802c0b57fa011f74164a7f97675ca3b6ab756b.svg" alt=""&gt;
        &lt;div class="ltag__stackexchange--score-number"&gt;
          0
        &lt;/div&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Rk_a5QFN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/stackexchange-arrow-down-4349fac0dd932d284fab7e4dd9846f19a3710558efde0d2dfd05897f3eeb9aba.svg" alt=""&gt;
      &lt;/a&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--body"&gt;
    
&lt;p&gt;I have been facing an issue with NextJS. I tried to import a CDN script on a particular page. It works on the first load but then throws an error whenever I navigate to another page, thereby making it unusable when navigating to the initial page.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import React, { useState,&lt;/code&gt;&lt;/pre&gt;…
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--btn--container"&gt;
    
      &lt;a href="https://stackoverflow.com/questions/61358305/nextjs-throws-error-on-navigating-from-the-page-that-imports-a-script-in-the-hea" rel="noopener noreferrer"&gt;Open Full Question&lt;/a&gt;
    
  &lt;/div&gt;
&lt;/div&gt;


</description>
    </item>
    <item>
      <title>Question: How do I deal with environment variables in production?</title>
      <dc:creator>calebdeji</dc:creator>
      <pubDate>Fri, 06 Dec 2019 00:09:36 +0000</pubDate>
      <link>https://dev.to/calebdeji/question-how-do-i-deal-with-environment-variables-in-production-i1k</link>
      <guid>https://dev.to/calebdeji/question-how-do-i-deal-with-environment-variables-in-production-i1k</guid>
      <description>&lt;p&gt;So I was checking the source code (in browser) of some of my projects and I discovered that even though I used environment variables to store sensitive information I could still see the values when rendered in the browser, meaning that my values are injected during runtime, hence still makes my projects vulnerable. How do I deal with env variables in production so that no one will see the values when the page source is viewed?&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>environmentvariables</category>
      <category>frontenddevelopment</category>
    </item>
  </channel>
</rss>
