<?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: Arnold</title>
    <description>The latest articles on DEV Community by Arnold (@arnoldddev).</description>
    <link>https://dev.to/arnoldddev</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%2F403863%2F6db3c899-896c-4b2f-a808-89feb05135d5.jpg</url>
      <title>DEV Community: Arnold</title>
      <link>https://dev.to/arnoldddev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arnoldddev"/>
    <language>en</language>
    <item>
      <title>Reading Env files in React</title>
      <dc:creator>Arnold</dc:creator>
      <pubDate>Sat, 12 Mar 2022 16:05:45 +0000</pubDate>
      <link>https://dev.to/arnoldddev/reading-env-files-in-react-1pm6</link>
      <guid>https://dev.to/arnoldddev/reading-env-files-in-react-1pm6</guid>
      <description>&lt;p&gt;React is a very popular framework, which most of us use today. Sometimes we want to use environment variables in our application but we don't know how to go about it.&lt;/p&gt;

&lt;p&gt;Environment variables are used to store sensitive information. In our &lt;code&gt;React&lt;/code&gt; application we can have environment variables and also when deploying, environment variables can be found on the server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;THIS IS HOW TO USE ENVIRONMENT VARIABLES ON YOUR MACHINE&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;.env&lt;/code&gt; SETUP
&lt;/h2&gt;

&lt;p&gt;To define permanent environment variables in our React application, we need to setup our &lt;code&gt;.env&lt;/code&gt; file.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;create a &lt;code&gt;.env&lt;/code&gt; file in the root of your React application&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;create custom environment variables beginning with &lt;code&gt;REACT_APP_&lt;/code&gt; just like the example below.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTE: it must start with &lt;strong&gt;&lt;code&gt;REACT_APP_&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// ENV FILE
REACT_APP_API_KEY=abcdefgh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this we are done setting our &lt;code&gt;.env&lt;/code&gt; file, now we have to read this &lt;code&gt;REACT_APP_API_KEY&lt;/code&gt; in our project.&lt;/p&gt;

&lt;h2&gt;
  
  
  READING &lt;code&gt;.env&lt;/code&gt; FILES
&lt;/h2&gt;

&lt;p&gt;In our react app, we have &lt;a href="https://nodejs.org/dist/latest-v8.x/docs/api/process.html#process_process_env"&gt;process.env&lt;/a&gt; available to us. So to read &lt;code&gt;REACT_APP_API_KEY&lt;/code&gt; we do&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;process.env.REACT_APP_KEY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;if we set &lt;code&gt;process.env.REACT_APP_API_KEY&lt;/code&gt; to a variable and log it out&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const apiKey = process.env.REACT_APP_API_KEY

console.log(apiKey)
//abcdefgh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this in place, we now know how to read &lt;code&gt;.env&lt;/code&gt; files. This won't work immediately if we try it, for it to work we have to do one last thing&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;RESTART YOUR DEVELOPMENT SERVER&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you miss to restart you dev server, it won't work. Also if you add or change anything in your &lt;code&gt;.env&lt;/code&gt; file, for you to use it you have to restart your dev server.&lt;br&gt;
That's it lads, tell me what you think in the comments section.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Rest and Spread operator</title>
      <dc:creator>Arnold</dc:creator>
      <pubDate>Wed, 01 Dec 2021 16:12:11 +0000</pubDate>
      <link>https://dev.to/arnoldddev/rest-and-spread-operator-18ig</link>
      <guid>https://dev.to/arnoldddev/rest-and-spread-operator-18ig</guid>
      <description>&lt;p&gt;Hello programmers,&lt;/p&gt;

&lt;p&gt;The ES6 &lt;code&gt;Rest&lt;/code&gt; and the &lt;code&gt;Spread&lt;/code&gt; parameters are still very unclear to some people, and it seems to have so many people confused because they are identical. The &lt;code&gt;Rest&lt;/code&gt; and &lt;code&gt;Spread&lt;/code&gt; operators are represented with &lt;code&gt;...&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;I still don't have any idea on why the both of them are represented with &lt;code&gt;...&lt;/code&gt; , honestly I feel like they should have come up with something else. So now let's dive in to what they are and what they are used for.&lt;/p&gt;

&lt;h2&gt;
  
  
  REST OPERATOR
&lt;/h2&gt;

&lt;p&gt;If we have a function and we don't know how many arguments that will be passed in, we use the &lt;code&gt;Rest&lt;/code&gt; operator. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq7om2ygn8n8onrd2ml03.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq7om2ygn8n8onrd2ml03.png" alt="Rest operator" width="800" height="911"&gt;&lt;/a&gt;&lt;br&gt;
In the image above the &lt;code&gt;...&lt;/code&gt; was used to handle what was passed into the function, if more values are passed into the function the &lt;code&gt;Rest&lt;/code&gt; operator will take care of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  SPREAD OPERATOR
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;Spread&lt;/code&gt; operator can be used in different situations, it can also work with a function. I'll show you the different scenarios were it can be used.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7axm2qhm939ejfsypvwg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7axm2qhm939ejfsypvwg.png" alt="Spread operator example 1" width="800" height="1073"&gt;&lt;/a&gt;&lt;br&gt;
In the picture above the &lt;code&gt;Spread&lt;/code&gt; operator was used to expand the array so it could be passed into the function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foafgbtbe5830lojukcmu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foafgbtbe5830lojukcmu.png" alt="spread operator example 2" width="800" height="927"&gt;&lt;/a&gt;&lt;br&gt;
In this image, the spread operator was used to neutralize an array so an operation could be carried out on each of the values in the array.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Basically, the &lt;code&gt;Spread&lt;/code&gt; operator is used to neutralize an array.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Alright, this is all I have on the &lt;code&gt;Rest&lt;/code&gt; and &lt;code&gt;Spread&lt;/code&gt; operator. I hope you guys apply it in your new projects.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
