<?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: Melvin Kosisochukwu</title>
    <description>The latest articles on DEV Community by Melvin Kosisochukwu (@melvinmanni).</description>
    <link>https://dev.to/melvinmanni</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%2F315273%2F38dd30ad-4417-4aa7-b937-741c26cd9343.jpeg</url>
      <title>DEV Community: Melvin Kosisochukwu</title>
      <link>https://dev.to/melvinmanni</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/melvinmanni"/>
    <language>en</language>
    <item>
      <title>Common mistakes you might make using the near-sdk-as and assemblyscript</title>
      <dc:creator>Melvin Kosisochukwu</dc:creator>
      <pubDate>Sun, 30 Jan 2022 16:15:00 +0000</pubDate>
      <link>https://dev.to/melvinmanni/common-mistakes-you-might-make-using-the-near-sdk-as-and-assemblyscript-264c</link>
      <guid>https://dev.to/melvinmanni/common-mistakes-you-might-make-using-the-near-sdk-as-and-assemblyscript-264c</guid>
      <description>&lt;p&gt;In this article, we will be exploring a few mistakes that you might make when getting started with the near-sdk-as. Before we dive into these mistakes, let us look at the near-sdk-as.&lt;/p&gt;

&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;The near-sdk-as package is used to write smart contracts to interact with the NEAR Blockchain. These smart contracts are written using assemblyscript, a typescript-based programming language optimized to compile to WebAssembly. Now I know what you might be thinking, "assemblyscript is typescript based, then it must be similar to typescript"… well, you are not wrong, but you are also not correct. If you are coming from a javascript/typescript environment, this thinking already sets you up to make inevitable mistakes when working with assemblyscript and the near-sdk-as.&lt;/p&gt;

&lt;p&gt;Let's look at these common mistakes:&lt;/p&gt;

&lt;h1&gt;
  
  
  Common Mistakes
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Javascript/Typescript packages
&lt;/h2&gt;

&lt;p&gt;You need to note that you cannot use Typescript/Javascript libraries with assemblyscript… I tried. It would be best to stick to strictly assemblyscript packages to avoid breaking your code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Generating Random Numbers
&lt;/h2&gt;

&lt;p&gt;Generating random numbers with assemblyscript is not exactly as easy as you get to do it in Javascript, but do not worry, near-sdk-as have an easier way to do this using the RNG class. It would be best to always browse through the documentation for packages before using them. Here is a sample use case for the RNG package:&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;RNG&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;near-sdk-as&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;roll&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;RNG&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;u32&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&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;u32&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MAX_VALUE&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;randomNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;roll&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;//roll.next() will return a random number that falls withing the max value for a u32(32 bit unsigned integer) data type&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For more information on how this works, you can read the documentation here.&lt;/p&gt;

&lt;h2&gt;
  
  
  Date.now() ?
&lt;/h2&gt;

&lt;p&gt;The blockchain provides you with a timestamp(literally). The Context class has a property &lt;code&gt;blockTimestamp&lt;/code&gt; that returns the current time in nanoseconds. It would be best not to use the native date constructor to get the current date and time.&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Context&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;near-sdk-core&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;currentTime&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;u64&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;time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;blockTimestamp&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;time&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;h2&gt;
  
  
  Using Signer the right way
&lt;/h2&gt;

&lt;p&gt;The signer property from the near-sdk-as Context class has a special use case: it can only be used in “change” functions/methods. There exist two types of methods/functions on the NEAR blockchain; change and view methods.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;View Methods&lt;/strong&gt;: These are methods that fetch or retrieve information from the storage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Change Methods&lt;/strong&gt;: These are methods that mutate/update the storage. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The change methods are transactions; therefore, it requires an account to sign these transactions. The property signer on the Context class can be used to access the account that signed the change method called. View methods do not require to be signed; therefore, signer property does not return an account for these methods. Some might find themselves trying to access a signing account from Context class in a view method, resulting in your smart contract panicking/failing.&lt;/p&gt;

&lt;p&gt;Summary and Resources&lt;/p&gt;

&lt;p&gt;The mistakes above and a few that is not listed can be avoided or easily navigated by exploring the official documentation and reviewing a few open-source smart contracts provided by the NEAR Edu and NEAR community(&lt;a href="https://github.com/Learn-NEAR"&gt;https://github.com/Learn-NEAR&lt;/a&gt;).&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>near</category>
      <category>typescript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Using Doppler In a React-Firebase Application</title>
      <dc:creator>Melvin Kosisochukwu</dc:creator>
      <pubDate>Wed, 29 Sep 2021 08:20:18 +0000</pubDate>
      <link>https://dev.to/melvinmanni/using-doppler-in-a-react-firebase-application-4co6</link>
      <guid>https://dev.to/melvinmanni/using-doppler-in-a-react-firebase-application-4co6</guid>
      <description>&lt;p&gt;&lt;em&gt;Handling secrets/environment variables on a team/personal codebase can be very stressful. Doppler helps you scale through this problem by providing an environment to store your secrets that you and your team can use. You will like to keep most of these environment variables within the team; hence, it’s not best to push it to a GitHub repository to avoid vulnerability. In this article, we will look through how to implement Doppler with a React-firebase app.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://doppler.com/" rel="noopener noreferrer"&gt;Doppler&lt;/a&gt; is a universal secret manager; this means that you can use doppler to manage secrets across applications within groups with less risk of vulnerability and ease of work. Doppler makes it easy for you to share environment secrets for application and development with your team. It also eases integration with most of your cloud platforms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why use Doppler ?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scalability: It makes it easy to scale and make changes to environment variables in your application&lt;/li&gt;
&lt;li&gt;Ease of Work: Doppler allows you to focus on the core functionality of your application, removing the complications of sharing environment secrets across team members.&lt;/li&gt;
&lt;li&gt;Doppler supports integration with multiple cloud/hosting platforms for your application.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setting up Doppler
&lt;/h2&gt;

&lt;p&gt;For this tutorial, we will be setting up doppler for a simple react-firebase application; we will look at how to fetch and read the secrets in our application. Before we get started, we need to set up the doppler CLI; I will be walking you through how to do this on a mac.&lt;br&gt;
Run the command below in your terminal to install doppler&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;dopplerhq/cli/doppler
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once we have the doppler CLI installed you can run the &lt;code&gt;doppler&lt;/code&gt; command with the &lt;code&gt;--help&lt;/code&gt; flag to see a list of commands that are supported.&lt;br&gt;
To verify the doppler CLI version we run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;doppler &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I am currently working with v3.32.0. Next, I will need to login from my terminal; to do this you run the doppler login command below and select y&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;doppler login
? Open the authorization page &lt;span class="k"&gt;in &lt;/span&gt;your browser? &lt;span class="o"&gt;(&lt;/span&gt;Y/n&lt;span class="o"&gt;)&lt;/span&gt; y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command will open a browser window and prompt you to enter an auth code that will be made available on the terminal.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffut19qwce657zf29yt4a.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffut19qwce657zf29yt4a.png" alt="Doppler Auth page"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;? Open the authorization page &lt;span class="k"&gt;in &lt;/span&gt;your browser? Yes
Your auth code is:
kansas_loganberry_jewelry_lime_walnut

Waiting...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you enter the auth command, click next to navigate to the next screen and enter the token name. &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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr5ee6wvrd8pfi6nsn4ww.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr5ee6wvrd8pfi6nsn4ww.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on finish login, and &lt;em&gt;voila!&lt;/em&gt; CLI authentication to your Doppler account completed. &lt;br&gt;
&lt;strong&gt;Note&lt;/strong&gt;:  You will need to log in to your doppler account if you have not previously done this.&lt;/p&gt;
&lt;h2&gt;
  
  
  Setting Up React-Firebase Application
&lt;/h2&gt;

&lt;p&gt;It's time to set up our application; we will have a simple React application that writes messages and reads all messages written to the firestore. We will also build a rest api with the firebase cloud functions, this will be hosted on firebase. While setting up a firebase application on the console, enable hosting. Once we have everything set up, it's now time to handle integrating the secrets to doppler. I will be setting up the API key for an ip details API on Doppler, thus&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsl97wuezkm1g83m40k9n.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsl97wuezkm1g83m40k9n.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will be using this API key later in the application. Next, we need to create the firebase functions;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;firebase init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then select functions, the language you want to write your functions in(I will be choosing JavaScript)  and the project to use. Select yes for the rest of the option to successfully create your cloud functions. Once you are done this will create a folder “functions”. Next up is to cd into the folder and install express.&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;cd &lt;/span&gt;functions &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; npm &lt;span class="nb"&gt;install &lt;/span&gt;express
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using Doppler in your application
&lt;/h2&gt;

&lt;p&gt;In the root of the folder, create a file called environment.js, this will hold all the env configuration for firebase. In the environment.js file copy and paste in this code;&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;functions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;firebase-functions&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// use firebase config when deployed to firebase&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;deployedToFirebase&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODE_ENV&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;production&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;deployedToFirebase&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;functions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code block above will check if the app is in production and set the value of config to &lt;code&gt;functions.config().env&lt;/code&gt;. Go into the package.json and update the scripts to use the doppler environments on deploy.&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="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"serve"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"doppler run -- firebase emulators:start --only functions"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"shell"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"doppler run -- firebase functions:shell"&lt;/span&gt;&lt;span class="err"&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;"npm run shell"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"deploy"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"npm run update_config &amp;amp;&amp;amp; firebase deploy --only functions"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"update_config"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"firebase functions:config:unset env &amp;amp;&amp;amp; firebase functions:config:set env=&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;$(doppler secrets download --config prd --no-file --silent)&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"logs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"firebase functions:log"&lt;/span&gt;&lt;span class="w"&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;This will set up our firebase api to use doppler environments locally and in production.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using secrets in firebase application
&lt;/h2&gt;

&lt;p&gt;To use the environment variable, we will need to bring in the config created in the environment.js file, and just like accessing key values pairs in object literals, we will access the API_KEY variable stored on doppler.&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;environments&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./environment&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="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="kd"&gt;function&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;res&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;axios&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://ipgeolocation.abstractapi.com/v1/?api_key=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;environments&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;API_KEY&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="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;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&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;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;500&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="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="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;In the code block above, we import the environment file and use it to access the API_KEY variable, &lt;code&gt;environments.API_KEY&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Once done with building the API we can deploy it on firebase by running the deploy script;&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 deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In our react application we will be consuming the api deployed to firebase to write new messages and read all messages written to firestore.&lt;/p&gt;

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

&lt;p&gt;In this article, we looked at how to integrate doppler in managing secrets in our firebase application. We also looked at consuming the firebase API in our react application.To review full firebase functions and doppler configuration, you can find the source code in this &lt;a href="https://github.com/MelvinManni/doppler-firebase" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt;. You can also find the complete frontend source code &lt;a href="https://github.com/MelvinManni/doppler_firebase-fe" rel="noopener noreferrer"&gt;here&lt;/a&gt;. For additional information on integrating Doppler with other applications/platforms, you can refer to the &lt;a href="https://docs.doppler.com/docs" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>react</category>
      <category>firebase</category>
      <category>security</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Deploying React App With Router On Netlify</title>
      <dc:creator>Melvin Kosisochukwu</dc:creator>
      <pubDate>Sat, 25 Jul 2020 13:46:58 +0000</pubDate>
      <link>https://dev.to/melvinmanni/deploying-react-app-with-router-on-netlify-1l7g</link>
      <guid>https://dev.to/melvinmanni/deploying-react-app-with-router-on-netlify-1l7g</guid>
      <description>&lt;p&gt;Netlify has made it easy to deploy react projects for free, amazing right?. &lt;br&gt;
When I first tried to deploy an app with a router I came across a slight obstacle, this was an easily solved issue but at that moment, it was a little hard for me to get through it. &lt;br&gt;
This article is to help the next newbie that might come across such issues.&lt;/p&gt;

&lt;p&gt;The solution to getting your routing to work on Netlify lies in one file, the netlify.toml file. This is the netlify configuration file, for mor information on this check &lt;a href="https://docs.netlify.com/configure-builds/file-based-configuration/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;All you have to do is create a netlify.toml file in your root folder and inside the file include this 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%2Fv9h58rjlpc4du51q1k57.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%2Fv9h58rjlpc4du51q1k57.png" alt="Alt Text" width="586" height="670"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will catch all the redirects and your React app should work just fine. &lt;/p&gt;

&lt;p&gt;You can run npm build and manually upload your files or link it to your GitHub/Gitlab/Bithub repository and netlify will handle the continuous integration for your app(i.e all new changes pushed to your repository will be reflected online without you having to rebuild the app)&lt;/p&gt;

&lt;p&gt;I hope this article helps someone and if you have any inquiries or questions you can leave a comment, thank you.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>html</category>
      <category>beginners</category>
    </item>
    <item>
      <title>React: A Peek Under The Hood Part 1</title>
      <dc:creator>Melvin Kosisochukwu</dc:creator>
      <pubDate>Sat, 25 Jul 2020 11:31:26 +0000</pubDate>
      <link>https://dev.to/melvinmanni/react-a-peek-under-the-hood-part-1-257c</link>
      <guid>https://dev.to/melvinmanni/react-a-peek-under-the-hood-part-1-257c</guid>
      <description>&lt;p&gt;For most people who write React application, the starting point is usually with npx or create-react-app CLI. I am not different from this group, I kicked off learning react using CLI tools without prior knowledge of how React works under the hood. Although there is nothing wrong with this, there are a few perks to knowing how React works without the fancy tools and packages that come with the CLI boilerplate.&lt;br&gt;
I will be walking you through the most basic parts of building pure react apps with React CDN. Create a basic HTML file and insert a div with the id root, you can name the id anything but, I chose root because of popular convention and practice 😁. &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%2Fu6sueild97ajxf3n1c5h.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%2Fu6sueild97ajxf3n1c5h.png" alt="Alt Text" width="800" height="456"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After this go over to (&lt;a href="https://reactjs.org/docs/cdn-links.html" rel="noopener noreferrer"&gt;https://reactjs.org/docs/cdn-links.html&lt;/a&gt;) and grab the CDN links for React and React-dom. You have options to choose from development and production. Now create a .js file and link it beneath the CDN files, at this point your HTML file should be looking 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%2Fk8pewp87hn3s639y1jk6.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%2Fk8pewp87hn3s639y1jk6.png" alt="Alt Text" width="800" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have our HTML and JavaScript file set up let's start writing pure React codes :-D.&lt;/p&gt;

&lt;p&gt;Open up the Js file and declare a function(App) just like you'd normally do with boilerplate React app. Inside your function return React.createElement('p', {}, 'Hello World'). &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%2Flkuunh22jy1cfpzww2dp.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%2Flkuunh22jy1cfpzww2dp.png" alt="Alt Text" width="800" height="358"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I know it is all starting to look weird and new to you but if you look closely, you notice something familiar(createElement), this is the same API used in creating new DOM elements in javascript. Now let me break everything down. &lt;/p&gt;

&lt;p&gt;The React.createElement Method is passed 3 parameters. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first one is the element tag that you are creating.&lt;/li&gt;
&lt;li&gt;The second parameter holds the properties of the element (props, classes, id).&lt;/li&gt;
&lt;li&gt;The third parameter holds the children of the element, in this case, it is the string 'Hello World'.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;How exactly do we get this to render/make it display in the browser? that is the power of the react-dom. Just under the App function, insert this : ReactDOM.render(React.createElement(App), document.getElementById('root'));&lt;/p&gt;

&lt;p&gt;If you look at the line of code, you will notice that the App component/function is created before gluing it to the HTML page using the react-dom, the ReactDOM.render takes two parameters; The first parameter holds the component while the id of the DOM element that the component is to be appended in goes inside the second parameter.&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%2Fbb5scc3w5vvd1bp4r4ss.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%2Fbb5scc3w5vvd1bp4r4ss.png" alt="Alt Text" width="800" height="299"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The react-dom serves as a glue, it takes the component and renders it inside the element passed in the second parameter.&lt;/p&gt;

&lt;p&gt;If you have followed all these steps, congratulations you just wrote your first code using pure react.&lt;/p&gt;

&lt;p&gt;I will dive deeper and review how to pass in properties and multiple child elements using pure React in the next part.&lt;/p&gt;

&lt;p&gt;Make sure to leave a Reaction and Follow 😉, Thank you.&lt;/p&gt;

</description>
      <category>react</category>
      <category>html</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A Dive Into React Hooks</title>
      <dc:creator>Melvin Kosisochukwu</dc:creator>
      <pubDate>Thu, 23 Apr 2020 21:10:28 +0000</pubDate>
      <link>https://dev.to/melvinmanni/a-dive-into-react-hooks-36g2</link>
      <guid>https://dev.to/melvinmanni/a-dive-into-react-hooks-36g2</guid>
      <description>&lt;p&gt;If you have ever worked with React State, you must have come across ‘this’ binding. Personally, I do not like the use of classes in React and somewhere out in the world, there are people who don’t fancy using classes in React as much as I do. You're in luck, with the addition of React hooks that gets rid of the classes, ‘this’ binding and still does the same works that react states do with shorter, cleaner code.&lt;br&gt;
React hooks is an addition that was introduced with React 16.8. They let you use state and other React features without writing a class.&lt;br&gt;
Generally using classes in react results to a lot of lines of code that can be easily cut down using a function. A simple hello world program will look like this with classes and state.&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%2F7wp6q3elu4g6mu79cp7s.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%2F7wp6q3elu4g6mu79cp7s.png" alt="Alt Text" width="800" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When using a function and React hooks you can optimize this same code down to:&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%2F37nu1i3upzn6bkqewsvb.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%2F37nu1i3upzn6bkqewsvb.png" alt="Alt Text" width="774" height="964"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you observe the two codes you can clearly see that Hooks make things easier for you with shorter, faster code.&lt;br&gt;
Now let’s go into how React hooks actually work, what you should know before using react hooks.&lt;br&gt;
Before you decide to use React Hooks there a JavaScript principle you should already be proficient in and that is destructuring.&lt;br&gt;
What is destructuring? This is simply unpacking the values of an array or object into a distinct value. There is a really good article on destructuring &lt;a href="https://dev.to/sarah_chima/destructuring-assignment---arrays-16f"&gt;here&lt;/a&gt;.&lt;br&gt;
React hooks uses the principles of destructuring to unpack values from the useState() function.&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%2F2mesjcranykl1y45h3f5.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%2F2mesjcranykl1y45h3f5.png" alt="Alt Text" width="800" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The left side is where the variable name is declared. The first item is the variable name for the state and the second item in the array separated by a comma is the function for setting the value of the state, this serves the same purpose as the setState() function in classes.&lt;br&gt;
The right side is where the destructured array (useState function). The parameter for the function is where the value for the state is initialized. It might take a little getting used to but when you start using the hooks it gets a little bit easier.&lt;br&gt;
The setValue function can be used to update the value of the state.&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%2F93hwhroh7w2mkadm1u95.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%2F93hwhroh7w2mkadm1u95.png" alt="Alt Text" width="800" height="687"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The setValue function is called on button click and updates value from ‘World’ to ‘Earth’.&lt;br&gt;
For further insight on react hooks, you can check out &lt;a href="https://reactjs.org/docs/hooks-intro.html" rel="noopener noreferrer"&gt;the documentation&lt;/a&gt; from the React Team.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>reactnative</category>
    </item>
  </channel>
</rss>
