<?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: Maher Alkendi</title>
    <description>The latest articles on DEV Community by Maher Alkendi (@ma7eer).</description>
    <link>https://dev.to/ma7eer</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%2F107624%2F2d10e591-4706-4d15-88e9-6fbfa962ce35.jpeg</url>
      <title>DEV Community: Maher Alkendi</title>
      <link>https://dev.to/ma7eer</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ma7eer"/>
    <language>en</language>
    <item>
      <title>Simple Git workflow for beginners</title>
      <dc:creator>Maher Alkendi</dc:creator>
      <pubDate>Fri, 07 Aug 2020 11:44:07 +0000</pubDate>
      <link>https://dev.to/ma7eer/simple-git-workflow-for-beginners-3941</link>
      <guid>https://dev.to/ma7eer/simple-git-workflow-for-beginners-3941</guid>
      <description>&lt;p&gt;This post is to share the git workflow I use for my projects. I am mainly writing this post so I can use it as a cheat sheet from time to time. However, I think it will serve as a good reference for any developer that wants to go beyond the &lt;code&gt;git add&lt;/code&gt; &lt;code&gt;git commit&lt;/code&gt; &lt;code&gt;git push&lt;/code&gt; workflow.&lt;/p&gt;

&lt;p&gt;This posts assumes that you are familiar with the basics of git. If you are not then I recommend the video below, by &lt;a href="https://twitter.com/traversymedia"&gt;Traversy Media&lt;/a&gt; for a quick overview:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/SWYqp7iY_Tc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Step 1: Create a branch for the feature you want to add and navigate to it&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout -b &amp;lt;branch-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step 2: Make changes to your code&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Use the following command to see changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git status
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step 3: Add changes to staging area&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add &amp;lt;files-changed&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step 4: Commit changes and add a short description&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -m "&amp;lt;commit message&amp;gt;"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For commit messages I use the article by Chris Beams as reference: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://chris.beams.io/posts/git-commit/"&gt;How to Write a Git Commit Message&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Step 5: Navigate to main branch&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout master
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step 6: Push changes from branch to create a pull request&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push origin &amp;lt;branch-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Pull request can be found on github or gitlab (whatever you are using). There you can review and add more comments to it.&lt;/p&gt;

&lt;p&gt;That is all!&lt;/p&gt;

&lt;p&gt;Got questions? Feel free to reach out via the comments or my &lt;a href="https://twitter.com/maheralkendi"&gt;twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok! Now back to learning 👨🏿‍💻&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>beginners</category>
    </item>
    <item>
      <title>2 things to pay attention to when monitoring your application server</title>
      <dc:creator>Maher Alkendi</dc:creator>
      <pubDate>Sun, 02 Aug 2020 12:48:54 +0000</pubDate>
      <link>https://dev.to/ma7eer/3-things-to-pay-attention-to-when-monitoring-your-application-server-50ca</link>
      <guid>https://dev.to/ma7eer/3-things-to-pay-attention-to-when-monitoring-your-application-server-50ca</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Managing an application server is a very sensitive task. Being able to understand the limitations and capabilities of your server is as important as developing the functionalities of your application. &lt;/p&gt;

&lt;p&gt;Imagine having a To-do list application that can add new To-do items by voice command, but adding anew to-do item takes too long. All the effort in building the application is gone because no one can use it. What's worse is that you have no idea where the problem is. Your server hosting service provides monitoring graphs but you don't understand them. There are too many concepts to learn and understand. Where to start?&lt;/p&gt;

&lt;p&gt;I always found concepts related to web servers daunting and scary. This is why I decided that in monitoring my servers I will focus on two of points only. The goal is to get comfortable with these concepts, then move to other items that are important to pay attention to when managing a server.&lt;/p&gt;

&lt;p&gt;In this case I recommend that beginners start by monitoring two items:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Server CPU&lt;/li&gt;
&lt;li&gt;Server Memory&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Target audience
&lt;/h2&gt;

&lt;p&gt;This article is intended for beginners who found themselves somehow managing a web server for a client or a company. If you are experienced in this field, please feel free to share your thoughts in the comments 😀&lt;/p&gt;

&lt;h2&gt;
  
  
  CPU
&lt;/h2&gt;

&lt;p&gt;CPU or &lt;code&gt;Central processing unit&lt;/code&gt; is the thing in the server or computer that executes the commands or instructions given by a program. In our case the server CPU is what runs our application. Each server can have access to more than one CPU core. The more CPU cores you have the more capable your server will be to handle large loads or expensive tasks.&lt;/p&gt;

&lt;p&gt;There are two metrics to pay attention to when monitoring CPU:&lt;/p&gt;

&lt;h3&gt;
  
  
  CPU load: How many tasks are in queue for our server to run?
&lt;/h3&gt;

&lt;h3&gt;
  
  
  CPU utilization: When running a task, how much effort needs to be exerted?
&lt;/h3&gt;

&lt;p&gt;Both CPU load and CPU utilization are best monitored over time. &lt;/p&gt;

&lt;p&gt;A great resource to start at is this article by Digital Ocean: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.digitalocean.com/community/tutorials/how-to-monitor-cpu-use-on-digitalocean-droplets"&gt;How To Monitor CPU Use on DigitalOcean Droplets&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Memory
&lt;/h2&gt;

&lt;p&gt;Memory can be divided into two: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;RAM (Random Access Memory)&lt;/li&gt;
&lt;li&gt;Disk Storage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;RAM is the memory that the server is actively using. This data will be lost if your server or application shuts down. &lt;/p&gt;

&lt;p&gt;Imagine fetching a large chunk of data from your database and storing it in an object. This object will have the data stored as long as the server and or application instance is running. Once a user refreshes the application page (as an example) then that object returns to being empty till another fetch happens.&lt;/p&gt;

&lt;p&gt;Disk Storage is more permanent. It is what you save in your database (as an example). It is important to pay attention to disk storage. If the storage is full then your application will likely stop functioning. For example a user will not be able to add more To-dos if there is no more storage space. If you are consistently monitoring disk storage then you can plan ahead for any memory shortage. &lt;/p&gt;

&lt;p&gt;A good resource for more in-depth readying is: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://haydenjames.io/measure-web-server-memory-usage-correctly/"&gt;Measure Linux web server memory usage correctly&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For a beginner that is managing a web server for a small client, I believe this is a good start. Simply focus on CPU and memory (Google how to monitor them on your particular hosting service). Once you are comfortable, then you will find yourself delving deeper into these concepts to provide the most reliable service to your clients. The goal is to always find the issue before your client points it out to you. Monitoring can help us plan ahead.&lt;/p&gt;

&lt;p&gt;Got questions? Feel free to reach out via the comments or my &lt;a href="https://twitter.com/maheralkendi"&gt;twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok! Now back to learning 👨🏿‍💻&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>cpu</category>
      <category>memory</category>
    </item>
    <item>
      <title>Basic form flow using xstate and react</title>
      <dc:creator>Maher Alkendi</dc:creator>
      <pubDate>Sun, 29 Dec 2019 18:15:08 +0000</pubDate>
      <link>https://dev.to/ma7eer/basic-form-flow-using-xstate-and-react-4fgg</link>
      <guid>https://dev.to/ma7eer/basic-form-flow-using-xstate-and-react-4fgg</guid>
      <description>&lt;p&gt;I am on a journey to learn how to use &lt;a href="https://xstate.js.org/docs/" rel="noopener noreferrer"&gt;xstate&lt;/a&gt;. As I learn, I decided to share pieces of my learnings. The goal is to increase my understanding and to add more &lt;code&gt;xstate&lt;/code&gt; implementation examples to the ecosystem. &lt;/p&gt;

&lt;p&gt;The app we will be building is a simple form that logs the submitted text to the console. This sounds super simple and can easily be implemented with react. However, how would we build this using xstate? &lt;/p&gt;

&lt;p&gt;Lets start by building the UI components of our app. Note that I am using &lt;a href="https://codesandbox.io" rel="noopener noreferrer"&gt;CodeSandbox&lt;/a&gt; to write my code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";
import ReactDOM from "react-dom";

import "./styles.css";

function App() {
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h1&amp;gt;Hello World!&amp;lt;/h1&amp;gt;
      &amp;lt;h2&amp;gt;Submit to log some text on the console&amp;lt;/h2&amp;gt;
      &amp;lt;form&amp;gt;
        &amp;lt;input
          type="text"
          placeholder="Enter text"
        /&amp;gt;
        &amp;lt;button&amp;gt;submit&amp;lt;/button&amp;gt;
      &amp;lt;/form&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(&amp;lt;App /&amp;gt;, rootElement);

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

&lt;/div&gt;



&lt;p&gt;This is what our app looks like in the browser:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fu2dbm43j3fdi5o47yyel.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%2Fu2dbm43j3fdi5o47yyel.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Alright, lets install &lt;code&gt;xstate&lt;/code&gt; and &lt;code&gt;@xstate/react&lt;/code&gt; as dependencies in our application. Then import them and start thinking about our simple form &lt;code&gt;State Machine&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
import { Machine } from "xstate";

const simpleFormMachine = Machine(
  {
    id: "simpleForm",
    initial: "idle",
    states: {
      idle: {},
      submitting: {}
      }
    }
  }
);

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

&lt;/div&gt;



&lt;p&gt;As a start we give our machine an unique id and an initial state. Next we enter our expected states. &lt;/p&gt;

&lt;p&gt;This is the flow we are expecting: the form is idle then the user starts an event, which is the "typing" event. In the "typing" event the form is still in idle state. Then when the user presses the submit button, the form starts submitting the data. That is when we should implement the logging logic.&lt;/p&gt;

&lt;p&gt;Based on the above narrative I saw fit we have two states for our form: &lt;code&gt;idle state&lt;/code&gt; and &lt;code&gt;submitting state&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We have a basic idea of what our &lt;code&gt;state machine&lt;/code&gt; will look like. However, where can we store the state of the input value? There are infinite representations of this state (whatever the user will input), which should lead us to conclude that we need to use the &lt;code&gt;xstate&lt;/code&gt; &lt;code&gt;extended state&lt;/code&gt;, named &lt;code&gt;context&lt;/code&gt;. Then we can pass this value to our &lt;code&gt;jsx&lt;/code&gt; input via the &lt;code&gt;@xstate/react&lt;/code&gt; library.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";
import ReactDOM from "react-dom";
import { Machine } from "xstate";
import { useMachine } from "@xstate/react";

import "./styles.css";

const simpleFormMachine = Machine(
  {
    id: "simpleForm",
    initial: "idle",
    context: {
      inputValue: ""
    },
    states: {
      idle: {},
      submitting: {}
  }
);

function App() {
  const [current, send] = useMachine(simpleFormMachine);
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h1&amp;gt;Hello World!&amp;lt;/h1&amp;gt;
      &amp;lt;h2&amp;gt;Submit to log some text on the console&amp;lt;/h2&amp;gt;
      &amp;lt;form&amp;gt;
        &amp;lt;input
          type="text"
          placeholder="Enter text"
          value={current.context.inputValue}
        /&amp;gt;
        &amp;lt;button&amp;gt;submit&amp;lt;/button&amp;gt;
      &amp;lt;/form&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(&amp;lt;App /&amp;gt;, rootElement);

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

&lt;/div&gt;



&lt;p&gt;To test that our input value is connected to our &lt;code&gt;state machine's&lt;/code&gt; context, simply change the initial value of &lt;code&gt;inputValue&lt;/code&gt; and you will see the change reflected in the input.&lt;/p&gt;

&lt;p&gt;Next lets implement &lt;code&gt;onChange&lt;/code&gt; using &lt;code&gt;xstate&lt;/code&gt;. When the user starts inserting text in the input box the onChange event is triggered. When this happens we should send a message to the &lt;code&gt;state machine&lt;/code&gt; telling it that the user is currently typing. Our machine should then implement an action to assign our context to the value being inputted by the user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...

const simpleFormMachine = Machine(
  {
    id: "simpleForm",
    initial: "idle",
    context: {
      inputValue: ""
    },
    states: {
      idle: {
        on: {
          TYPING: {
            actions: "typing"
          }
        }
      },
      submitting: {}
    }
  },
  {
    actions: {
      typing: assign((ctx, e) =&amp;gt; ({ inputValue: e.value }))
    }
  }
);

function App() {
  const [current, send] = useMachine(simpleFormMachine);
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h1&amp;gt;Hello World!&amp;lt;/h1&amp;gt;
      &amp;lt;h2&amp;gt;Submit to log some text on the console&amp;lt;/h2&amp;gt;
      &amp;lt;form&amp;gt;
        &amp;lt;input
          type="text"
          placeholder="Enter text"
          value={current.context.inputValue}
          onChange={e =&amp;gt;
            send({
              type: "TYPING",
              value: e.target.value
            })
          }
        /&amp;gt;
        &amp;lt;button&amp;gt;submit&amp;lt;/button&amp;gt;
      &amp;lt;/form&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;Now lets implement our submit logic. This happens when the form is submitted, via the submit button or the &lt;code&gt;enter&lt;/code&gt; key. In this case we want our form to send an event indicating it is submitting. Our machine will then change from &lt;code&gt;idle&lt;/code&gt; to &lt;code&gt;submitting&lt;/code&gt; state. As we enter this state we should log the current context value to the console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...

const simpleFormMachine = Machine(
  {
    id: "simpleForm",
    initial: "idle",
    context: {
      inputValue: ""
    },
    states: {
      idle: {
        on: {
          TYPING: {
            actions: "typing"
          },
          SUBMIT: "submitting"
        }
      },
      submitting: {
        entry: "log"
      }
    }
  },
  {
    actions: {
      typing: assign((ctx, e) =&amp;gt; ({ inputValue: e.value })),
      log: (ctx, e) =&amp;gt; console.log(ctx.inputValue)
    }
  }
);

function App() {
  const [current, send] = useMachine(simpleFormMachine);
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h1&amp;gt;Hello World!&amp;lt;/h1&amp;gt;
      &amp;lt;h2&amp;gt;Submit to log some text on the console&amp;lt;/h2&amp;gt;
      &amp;lt;form
        onSubmit={e =&amp;gt; {
          e.preventDefault();
          send("SUBMIT");
        }}
      &amp;gt;
        &amp;lt;input
          type="text"
          placeholder="Enter text"
          value={current.context.inputValue}
          onChange={e =&amp;gt;
            send({
              type: "TYPING",
              value: e.target.value
            })
          }
        /&amp;gt;
        &amp;lt;button&amp;gt;submit&amp;lt;/button&amp;gt;
      &amp;lt;/form&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The app is almost complete. However, the only issue we have is that we are not going back to an idle state after submitting the form. Lets send a second event after the 'SUBMIT' event. Lets call it 'STOPPED_TYPING'. when this event occurs we will go back to the idle state and we should trigger an action to clear the form.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...

const simpleFormMachine = Machine(
  {
    id: "simpleForm",
    initial: "idle",
    context: {
      inputValue: ""
    },
    states: {
      idle: {
        on: {
          TYPING: {
            actions: "typing"
          },
          SUBMIT: "submitting"
        }
      },
      submitting: {
        entry: "log",
        on: {
          STOPPED_TYPING: {
            target: "idle",
            actions: "clear"
          }
        }
      }
    }
  },
  {
    actions: {
      typing: assign((ctx, e) =&amp;gt; ({ inputValue: e.value })),
      log: (ctx, e) =&amp;gt; console.log(ctx.inputValue),
      clear: assign((ctx, e) =&amp;gt; ({ inputValue: "" }))
    }
  }
);

function App() {
  const [current, send] = useMachine(simpleFormMachine);
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h1&amp;gt;Hello World!&amp;lt;/h1&amp;gt;
      &amp;lt;h2&amp;gt;Submit to log some text on the console&amp;lt;/h2&amp;gt;
      &amp;lt;form
        onSubmit={e =&amp;gt; {
          e.preventDefault();
          send("SUBMIT");
          send("STOPPED_TYPING");
        }}
      &amp;gt;
        &amp;lt;input
          type="text"
          placeholder="Enter text"
          value={current.context.inputValue}
          onChange={e =&amp;gt;
            send({
              type: "TYPING",
              value: e.target.value
            })
          }
        /&amp;gt;
        &amp;lt;button&amp;gt;submit&amp;lt;/button&amp;gt;
      &amp;lt;/form&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;For the full code check out the codeSandbox below: &lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/icy-tree-jxe3d"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;See below for the final state chart:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6fb9alcbv3z48epejkky.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%2F6fb9alcbv3z48epejkky.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Did I miss anything? Got a better way of doing this? leave a comment! :]&lt;/p&gt;

&lt;p&gt;Ok! Now back to learning 👨🏿‍💻&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>react</category>
      <category>xstate</category>
    </item>
    <item>
      <title>Writing documentation for your React Components</title>
      <dc:creator>Maher Alkendi</dc:creator>
      <pubDate>Sat, 28 Dec 2019 12:55:58 +0000</pubDate>
      <link>https://dev.to/ma7eer/writing-documentation-for-your-react-components-1kbi</link>
      <guid>https://dev.to/ma7eer/writing-documentation-for-your-react-components-1kbi</guid>
      <description>&lt;p&gt;Speak with any developer that has worked in a team or on a large coding project and they will tell you that one of the most important things you could do as you build you application is writing documentation. &lt;/p&gt;

&lt;p&gt;To understand why, simply build an app then come back to the code a month from now and see how lost you will get even though you wrote the code. &lt;/p&gt;

&lt;p&gt;Now while writing documentation sounds like a great idea, it isn't the easiest thing to do. Developers are often pressured by time or sometimes you just don't feel like writing an essay about your code.&lt;/p&gt;

&lt;p&gt;If you develop in React and you don't document your code at all then start by simply documenting your React components only. Get in that habit and go from there. In this article, I will write down some items that you can consider as checkpoints anytime you write a React Component. Try as much as possible to do this for all your components and it will become a habit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Description/Purpose of the component
&lt;/h2&gt;

&lt;p&gt;What does this component do? &lt;/p&gt;

&lt;p&gt;Answer that question and you are done with the first step. This is a good place for pictures of what the component should look like in the browser.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
const DeleteButton = () =&amp;gt; {...}
...

# Description:
# This component will delete an item when pressed. 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Something as simple as that one line will go a long way. This just happens to be a simple example but for a more complex component, it will be very helpful.&lt;/p&gt;

&lt;h2&gt;
  
  
  List all props
&lt;/h2&gt;

&lt;p&gt;Just have a table with all props that the component has. In addition, mention what type of value it is expecting.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const DeleteButton = ({ element, isPermanent }) =&amp;gt; {...}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Prop&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;type&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;element&lt;/td&gt;
&lt;td&gt;element we want to delete&lt;/td&gt;
&lt;td&gt;String&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;isPermanent&lt;/td&gt;
&lt;td&gt;Should we archive or delete from db?&lt;/td&gt;
&lt;td&gt;Boolean&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  List all components
&lt;/h2&gt;

&lt;p&gt;If your component uses any other components, then list them. List the ones that are from external libraries as well.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import ExternalComponent from 'ExternalLibrary'

const DeleteButton = ({ element, isPermanent }) =&amp;gt; {
...

return (
  &amp;lt;ButtonWrapper&amp;gt;
   ...
   &amp;lt;ExternalComponent /&amp;gt;
   ...
  &amp;lt;/ButtonWrapper&amp;gt;
 )
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;ButtonWrapper&lt;/td&gt;
&lt;td&gt;Sets the button layout&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ExternalComponent&lt;/td&gt;
&lt;td&gt;Does something cool&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That is all. If you are like me and find it difficult to fit documentation into your development flow, then try the steps in this article as a start. Let me know how it works out! I will be using this on a real project and do plan to write a follow up article with an update and better examples.&lt;/p&gt;

&lt;p&gt;If you have any more ideas, share in the comments!&lt;/p&gt;

&lt;p&gt;Ok! Now back to learning 👨🏿‍💻&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>react</category>
      <category>documentation</category>
    </item>
    <item>
      <title>Dynamically Appending a script tag in a React App</title>
      <dc:creator>Maher Alkendi</dc:creator>
      <pubDate>Sat, 21 Dec 2019 16:17:05 +0000</pubDate>
      <link>https://dev.to/ma7eer/dynamically-appending-a-script-tag-in-a-react-app-1md3</link>
      <guid>https://dev.to/ma7eer/dynamically-appending-a-script-tag-in-a-react-app-1md3</guid>
      <description>&lt;p&gt;These days most libraries have a special/custom React component you can simply insert into your &lt;code&gt;jsx&lt;/code&gt; code, then add some props and it works. What if you face a situation where you really need to use a library but they do not have any React specific support? &lt;/p&gt;

&lt;p&gt;I was attempting to use the Paypal Checkout API to allow my client to make online payment. This API allows me as a developer to move all payment responsibilities to Paypal via their checkout widget. See &lt;a href="https://developer.paypal.com/docs/checkout/" rel="noopener noreferrer"&gt;docs&lt;/a&gt; for more details. &lt;/p&gt;

&lt;p&gt;However, there is no strict React support. What they provide in the documentation is a &lt;code&gt;script&lt;/code&gt; tag that you can drop somewhere in your &lt;code&gt;html&lt;/code&gt; and the buttons would appear. My app in this case was a React application and my template is &lt;code&gt;jsx&lt;/code&gt; instead of &lt;code&gt;html&lt;/code&gt;. How would I handle a case like this? &lt;/p&gt;

&lt;p&gt;I am writing this article to mirror that case with a simple example and show you one way you can handle it. &lt;/p&gt;

&lt;p&gt;First of all lets simulate the situation with Paypal. Paypal provides us with a &lt;code&gt;script&lt;/code&gt; tag such as this: &lt;code&gt;&amp;lt;script src="https://www.paypal.com/sdk/js?client-id=sb"&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;. if you copy the url, it will take you to a blank page with a lot of text. This text is the javascript code. What we need is a server to send us some javascript code. &lt;/p&gt;

&lt;p&gt;The fastest way I know to do this is with &lt;code&gt;node js&lt;/code&gt; and &lt;code&gt;Express js&lt;/code&gt;. Lets start by creating a folder for our application and initiating a &lt;code&gt;package.json&lt;/code&gt;. This can all be done in our terminal.&lt;/p&gt;

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

# create a new directory
mkdir script-link

# navigate to the new directory
cd script-link

# initiate a package.json
npm init -y


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

&lt;/div&gt;

&lt;p&gt;Next lets install &lt;code&gt;Express js&lt;/code&gt;, then create a file &lt;code&gt;index.js&lt;/code&gt; to write our server code in. Again, all can be done via the terminal.&lt;/p&gt;

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

# install express js
npm i -S express

# create a index.js file
touch index.js


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

&lt;/div&gt;

&lt;p&gt;Now that we have our file open, lets start our server at port &lt;code&gt;3001&lt;/code&gt;. If you are unfamiliar with how this is done. check out the &lt;a href="https://expressjs.com/en/starter/hello-world.html" rel="noopener noreferrer"&gt;Express js documentation&lt;/a&gt;. Otherwise, I will try to comment the code as much as possible. &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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fskxrd21q42vz3gd3mxmo.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%2Fskxrd21q42vz3gd3mxmo.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;to start our application, all we need to do is run &lt;code&gt;node index.js&lt;/code&gt;. Now lets go to our browser and navigate to &lt;code&gt;http://localhost:3001/&lt;/code&gt;. This is what we should see on the screen:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fvsiznkp7dhjqia8877ls.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%2Fvsiznkp7dhjqia8877ls.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are almost there! Now we need to send some javascript code instead. This is the time to think about what we want our mini widget to do. To make it simple all it will do is create a button that will show an alert anytime it is clicked. This is what the code looks like:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F0f0z4v3p65q0drijmmry.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%2F0f0z4v3p65q0drijmmry.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and this is what you should see if you add this as a &lt;code&gt;script&lt;/code&gt; tag to an &lt;code&gt;html&lt;/code&gt; file:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ft8x09d3i0lugrwxbth8e.gif" 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%2Ft8x09d3i0lugrwxbth8e.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have that, lets make our server send the code if a request is made. We do this by specifying the type of response file we are sending and by sending our javascript code in the form of a string. &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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fu57obwmokfaey3hmgx3z.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%2Fu57obwmokfaey3hmgx3z.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we restart our server, and refresh the browser page, this is what we should see:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3u3i8qhgjwkje89d5uk4.gif" 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%2F3u3i8qhgjwkje89d5uk4.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;OK! we are now sending javascript code just like the Paypal API does. Lets now start a React application that can use this little widget. &lt;/p&gt;

&lt;p&gt;First lets start a React application via the terminal.&lt;/p&gt;

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

npx create-react-app some-react-app


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

&lt;/div&gt;

&lt;p&gt;Once the app is setup we can run it by typing &lt;code&gt;npm start&lt;/code&gt; in our terminal. This will show us the default React page we are all familiar with. Next lets change the code in the &lt;code&gt;App.js&lt;/code&gt; file and add our own. All I did was add a &lt;code&gt;h1&lt;/code&gt; tag with some text.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6y20gz8hj6j4jbgxt58c.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%2F6y20gz8hj6j4jbgxt58c.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to use the code that is in our server, we need to have a &lt;code&gt;script&lt;/code&gt; tag. One method we can use is putting the &lt;code&gt;script&lt;/code&gt; tag in our &lt;code&gt;index.html&lt;/code&gt; that is in our public folder. However, lets say the javascript code has some function that we want to invoke at a particular point, how would we do that? For maximum control the best choice is to somehow add the code in a React component. &lt;/p&gt;

&lt;p&gt;Since the &lt;code&gt;script&lt;/code&gt; tag is just an &lt;code&gt;html&lt;/code&gt; tag we can simply append it to a tag in our template/jsx. &lt;/p&gt;

&lt;p&gt;First lets create a &lt;code&gt;div&lt;/code&gt; tag that we can use as a ref to append to. We do this because this is &lt;code&gt;jsx&lt;/code&gt; not &lt;code&gt;html&lt;/code&gt;, so we can't simply select the &lt;code&gt;div&lt;/code&gt; the way you would normally do. We have to create an instance of it via React ref.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F5n7kuh6p6xvfbg1hpurv.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%2F5n7kuh6p6xvfbg1hpurv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally we use the &lt;code&gt;useEffect&lt;/code&gt; hook to make sure we run the code when all components have been rendered. inside our &lt;code&gt;useEffect&lt;/code&gt; hook we create a &lt;code&gt;script&lt;/code&gt; tag, give it a &lt;code&gt;src&lt;/code&gt; attribute with our express server link, and append the &lt;code&gt;script&lt;/code&gt; tag to our &lt;code&gt;div&lt;/code&gt; instance. This is what it looks like:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fz4lpf8mcycf9xddefbnb.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%2Fz4lpf8mcycf9xddefbnb.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is what our app should look like now: &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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fax2o4753aqvor1tw6wnf.gif" 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%2Fax2o4753aqvor1tw6wnf.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nice! We have successfully dynamically appended a &lt;code&gt;script&lt;/code&gt; tag in our React application. Now, if we wanted, we could take this code and put it into a separate component. This will allow us to re-use it anywhere in our app. &lt;/p&gt;

&lt;p&gt;This is a simple demo but can give you an idea of how some of those great and convenient custom React components, that many libraries provide, are created. In addition, the idea of appending a &lt;code&gt;script&lt;/code&gt; tag is new to me and I wanted to document and share it.&lt;/p&gt;

&lt;p&gt;Please leave a comment if you have any take on this!&lt;/p&gt;

&lt;p&gt;Ok! Now back to learning 👨🏿‍💻&lt;/p&gt;

</description>
      <category>react</category>
      <category>express</category>
      <category>html</category>
    </item>
    <item>
      <title>What Payment API do you use if you don't live in a place where Stripe and other major Payment APIs works?</title>
      <dc:creator>Maher Alkendi</dc:creator>
      <pubDate>Tue, 29 Oct 2019 02:34:54 +0000</pubDate>
      <link>https://dev.to/ma7eer/what-payment-api-do-you-use-if-you-don-t-live-in-a-place-where-stripe-and-other-major-payment-apis-works-4o6k</link>
      <guid>https://dev.to/ma7eer/what-payment-api-do-you-use-if-you-don-t-live-in-a-place-where-stripe-and-other-major-payment-apis-works-4o6k</guid>
      <description>

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>What is the JAMStack missing to compete with Wordpress?</title>
      <dc:creator>Maher Alkendi</dc:creator>
      <pubDate>Sun, 08 Sep 2019 01:32:09 +0000</pubDate>
      <link>https://dev.to/ma7eer/what-is-the-jamstack-missing-to-compete-with-wordpress-30hm</link>
      <guid>https://dev.to/ma7eer/what-is-the-jamstack-missing-to-compete-with-wordpress-30hm</guid>
      <description>&lt;p&gt;The JAMStack is on the rise and I love the development environment it provides, but in the freelance world it is not the preferred option. Right now Wordpress is king. What does the JAMStack need to compete? &lt;/p&gt;

</description>
      <category>discuss</category>
      <category>jamstack</category>
      <category>wordpress</category>
    </item>
    <item>
      <title>Create a signature pad in React</title>
      <dc:creator>Maher Alkendi</dc:creator>
      <pubDate>Fri, 06 Sep 2019 15:39:39 +0000</pubDate>
      <link>https://dev.to/ma7eer/create-a-signature-pad-in-react-3mmi</link>
      <guid>https://dev.to/ma7eer/create-a-signature-pad-in-react-3mmi</guid>
      <description>&lt;p&gt;I was recently asked by a client to build a form that allows users to sign using a wireless pen mouse. The goal of the client was to obtain user signatures for a report that would be used for a future audit. &lt;/p&gt;

&lt;p&gt;At first I was considering building my own signature pad from scratch. However, I didn't have the time to do that. This feature needed to be live in a week. This unfortunately is the reality when working in real life situations. This is why I wanted to write about this specific case. You won't always have the time to build every single feature in an app from scratch. Sometimes you have to rely on libraries created by other developers. This article will help beginners see how you can combine different libraries to create a working product. &lt;/p&gt;

&lt;p&gt;OK let start building the signature pad. First I wrote a &lt;a href="https://en.wikipedia.org/wiki/User_story" rel="noopener noreferrer"&gt;user story&lt;/a&gt;. Below is the user story for what we will be building: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User sees a button that can be clicked to open a popup&lt;/li&gt;
&lt;li&gt;User can see and draw on a canvas when the popup is opened&lt;/li&gt;
&lt;li&gt;User has the option to exit popup via an 'Close' button, clear the canvas via a 'Clear' button, or save the signature as an image via the 'Save' button.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that we know what we are building lets start coding it. We can use the user story list items as our milestones.&lt;/p&gt;

&lt;h2&gt;
  
  
  User sees a button that can be clicked to open a popup
&lt;/h2&gt;

&lt;p&gt;I will use React for this task, so lets bootstrap the project by using create-react-app. &lt;/p&gt;

&lt;p&gt;To do that all we need to do is type the following command on our terminal:&lt;/p&gt;

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

npx create-react-app signature-pad


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

&lt;/div&gt;

&lt;p&gt;For more information on create-react-app check out this &lt;a href="https://github.com/facebook/create-react-app" rel="noopener noreferrer"&gt;Github Repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once our project is ready, we navigate into our folder and start up our code editor. In my case I am using &lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;VS Code&lt;/a&gt;.&lt;/p&gt;

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

# navigate to the project folder in your terminal
cd signature-pad

# command to start VS Code once you are in root folder of the project
code .


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

&lt;/div&gt;

&lt;p&gt;Now that we have everything set lets start up our project by typing the following command:&lt;/p&gt;

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

# start project
npm start


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

&lt;/div&gt;

&lt;p&gt;This is what we should see once the project starts:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F9qgyxthglqithu46vk07.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%2F9qgyxthglqithu46vk07.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you open up your &lt;code&gt;App.js&lt;/code&gt; file this is what we should see:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F125kinoret8n7cm5qprq.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%2F125kinoret8n7cm5qprq.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets get rid of all this code and add the one thing we need. A button that when clicked should open up a popup with a signature pad, per our user story.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbkhrlzhv2uqxbztz5ecq.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%2Fbkhrlzhv2uqxbztz5ecq.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is what our app should look like now:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkghmxxybim76464v6u5v.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%2Fkghmxxybim76464v6u5v.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our final step for this part of the project is to show a popup when the button is clicked. A good library that can help with this is reactjs-popup. To install it we type&lt;/p&gt;

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

npm install --save reactjs-popup


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

&lt;/div&gt;

&lt;p&gt;This library can be used to create Popup Models, Tool-tips, and Nested Menus. In our case we will focus on using it to create Popup Models. For more information on it check out their very helpful &lt;a href="https://react-popup.elazizi.com/introduction/" rel="noopener noreferrer"&gt;documentation page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we have the library installed we import it into our &lt;code&gt;App.js&lt;/code&gt; file. Next we add the &lt;code&gt;Popup&lt;/code&gt; component to our render method. This component takes in many props. In our case we focus on two: modal props (by default this is false which results in getting a tool-tip) and the trigger props which takes in a component that will trigger the popup. In our case this is our button that we already created. &lt;/p&gt;

&lt;p&gt;Now when we click on the button we should get a popup. the content of the popup will go inside our &lt;code&gt;Popup&lt;/code&gt; component.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fial8f4lv376vijo124mi.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%2Fial8f4lv376vijo124mi.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is what we should have now:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F7sx7ga2jbl0eaitt37os.gif" 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%2F7sx7ga2jbl0eaitt37os.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have successfully completed the first part of our User story. Now lets more to the next one!&lt;/p&gt;

&lt;h2&gt;
  
  
  User can see and draw on a canvas when the popup is opened
&lt;/h2&gt;

&lt;p&gt;To build the canvas inside our popup we will be using react-signature-canvas. This is a powerful library that will make working with a signature pad very easy. Specifically when we start thinking about adding features such as clear and save to our pad. &lt;/p&gt;

&lt;p&gt;To install it we type:&lt;/p&gt;

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

npm install --save react-signature-canvas


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

&lt;/div&gt;

&lt;p&gt;Once we have that installed we import the &lt;code&gt;SignatureCanvas&lt;/code&gt; component and place it inside our &lt;code&gt;Popup&lt;/code&gt; component. That is all!&lt;/p&gt;

&lt;p&gt;We now have a canvas inside our popup. This is what the code looks like:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F65frxbbm7raxop89z6ot.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%2F65frxbbm7raxop89z6ot.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and this is what our app should be showing:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fcpbqvuw29g34ty2u1ycu.gif" 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%2Fcpbqvuw29g34ty2u1ycu.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before we move to the next item in the user story lets add some styling to our canvas. All I will do is give give our canvas a border in order for us to easily identify it and give it a width and height. &lt;/p&gt;

&lt;p&gt;the &lt;code&gt;SignaturePad&lt;/code&gt; component has a prop called &lt;code&gt;canvasProps&lt;/code&gt; which allows us to pass attributes to the canvas. In this case I will give the canvas a class called  "signatureCanvas".&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fnzvenjmpm0a84mat838n.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%2Fnzvenjmpm0a84mat838n.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You probably noticed that I am also importing a css file called &lt;code&gt;sigCanvas.css&lt;/code&gt;. This is where I will put all my canvas related styles. &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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F5a4poqag5qzd34fnvzqb.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%2F5a4poqag5qzd34fnvzqb.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The result should look like this:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fj8dioinywl970demx660.gif" 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%2Fj8dioinywl970demx660.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;OK ready for our final step.&lt;/p&gt;

&lt;h2&gt;
  
  
  User has the option to exit popup via an 'Close' button, clear the canvas via a 'Clear' button, or save the signature as an image via the 'Save' button.
&lt;/h2&gt;

&lt;p&gt;lets start with the close button. lets add a button with an onClick, inside that onClick will be a way to close the popup. The &lt;code&gt;reactjs-popup&lt;/code&gt; docs recommend providing a function as a child to the &lt;code&gt;Popup&lt;/code&gt; component. this function has a parameter &lt;code&gt;close&lt;/code&gt; that will handle our close event and will return the components that we want inside the popup.&lt;/p&gt;

&lt;p&gt;In addition we should not allow users to close the popup except via this button. To do that we need to pass the &lt;code&gt;closeOnDocumentClick&lt;/code&gt; prop and pass it a true value. &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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ftlar1rs5gmy3xps7txte.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%2Ftlar1rs5gmy3xps7txte.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is what our app looks like now:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fi1itxvv3vx2kdjal67ay.gif" 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%2Fi1itxvv3vx2kdjal67ay.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next we need a button to clear the canvas. &lt;code&gt;react-signature-canvas&lt;/code&gt; provides several methods that help with manipulating our canvas. In order to use this method we need to get an instant of our canvas. This can be done via React refs.&lt;/p&gt;

&lt;p&gt;Let use React Hooks for this. First we create a ref called &lt;code&gt;sigCanvas&lt;/code&gt; using &lt;code&gt;useRef&lt;/code&gt; hook, the initial value is an empty object. Next we pass this into a &lt;code&gt;SignaturePad&lt;/code&gt; component using a prop called ref. finally we create a function called &lt;code&gt;clear&lt;/code&gt; that will be called anytime the clear button is clicked. &lt;/p&gt;

&lt;p&gt;inside the clear function, we simply invoke the method &lt;code&gt;clear()&lt;/code&gt; via our canvas ref &lt;code&gt;sigCanvas&lt;/code&gt;. I realize these are a lot of steps, so I wrote comments in the code shown below:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Foev6dgxn8va6p116yje2.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%2Foev6dgxn8va6p116yje2.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is what our app should look like now:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fk16uhqdcwbo8buw3mz1j.gif" 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%2Fk16uhqdcwbo8buw3mz1j.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now for the final button, the save button. This button should simply output a base64 string representing the image. You can use this to store it in a database or instead you can upload the image into your server. In our case we won't be connecting to any servers, so we will simply log the base64 code to the console.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;react-signature-canvas&lt;/code&gt; has a method called &lt;code&gt;getTrimmedCanvas()&lt;/code&gt; that can trim the white space from the canvas (to optimize the image) and give back a base64 string representing the image. All this via our &lt;code&gt;sigCanvas&lt;/code&gt; ref.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fr13v0e309kyu2gudvz4n.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%2Fr13v0e309kyu2gudvz4n.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is what our app should look like now:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkipqi1bf7xpo1jjzsdle.gif" 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%2Fkipqi1bf7xpo1jjzsdle.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Alright! all basic functionalities are complete!&lt;/p&gt;

&lt;p&gt;I do want to add one more part to this project. Lets output the saved signature on our screen instead of just logging it. &lt;/p&gt;

&lt;p&gt;We can simply add an image tag below our popup button and pass it our image URL. Of course this image URL will be what we logged into the console, so instead of doing that we can store it in state. &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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkhhpy6z4oi946k92ak2z.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%2Fkhhpy6z4oi946k92ak2z.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This should be the result: &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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6kacvb3k8u2v164inrop.gif" 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%2F6kacvb3k8u2v164inrop.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's all folks! we successfully completed our user story. Of course there is room to improve but all the basic functionalities are there. &lt;/p&gt;

&lt;p&gt;You can play around with the code and add more features to it by following the &lt;a href="https://codesandbox.io/s/react-signature-canvas-example-xevhz" rel="noopener noreferrer"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Got questions? Feel free to reach out via the comments or &lt;a href="https://twitter.com/maheralkendi" rel="noopener noreferrer"&gt;my twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok! Now back to learning 👨🏿‍💻&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>hooks</category>
    </item>
    <item>
      <title>Do you make your SVG using code? or using software?</title>
      <dc:creator>Maher Alkendi</dc:creator>
      <pubDate>Thu, 29 Aug 2019 12:32:47 +0000</pubDate>
      <link>https://dev.to/ma7eer/do-you-make-your-svg-using-code-or-using-software-4m7e</link>
      <guid>https://dev.to/ma7eer/do-you-make-your-svg-using-code-or-using-software-4m7e</guid>
      <description>&lt;p&gt;I am very new to the design world and I find websites such as &lt;a href="https://www.splitwise.com/"&gt;Splitwise&lt;/a&gt; fascinating! &lt;/p&gt;

&lt;p&gt;Now I want to dip my toe's in but I want to know. For more complex SVG's what do you use to build them? what is your process?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>svg</category>
      <category>design</category>
    </item>
    <item>
      <title>Easy way to get parameters from a URL</title>
      <dc:creator>Maher Alkendi</dc:creator>
      <pubDate>Fri, 26 Jul 2019 11:16:49 +0000</pubDate>
      <link>https://dev.to/ma7eer/easy-way-to-get-parameters-from-a-url-ae5</link>
      <guid>https://dev.to/ma7eer/easy-way-to-get-parameters-from-a-url-ae5</guid>
      <description>&lt;p&gt;Getting Url parameters can be tricky. I am sure I am not the only one that has used google to search for the perfect regular expression to help extract a parameter from a Url. &lt;/p&gt;

&lt;p&gt;While learning and mastering Regular Expressions is probably the best in this case. You might not have the time to learn them and just need a nice fix that is neat and easy to understand. &lt;/p&gt;

&lt;p&gt;The code below shows how this can easily be done using the URL API&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%2F3b2so03va3t6xl8n4tqb.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%2F3b2so03va3t6xl8n4tqb.png" alt="code snippet" width="800" height="426"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can read more about the ins and outs of this API by checking out the link below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/URL_API" rel="noopener noreferrer"&gt;URL - Web APIs | MDN&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reading through the MDN docs, you’ll notice this API has two interfaces the &lt;code&gt;URL interface&lt;/code&gt; and the &lt;code&gt;URLSearchParams interface&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;URL interface&lt;/code&gt; in this case allows us to parse our Url and returns an object that represents it.&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%2Fl9gpgun6qfpht2xyk7ni.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%2Fl9gpgun6qfpht2xyk7ni.png" alt="URL Object" width="800" height="591"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that one of the keys in the object (searchParams) refers to the &lt;code&gt;URLSearchParams interface&lt;/code&gt;. This interface gives us methods that allow us to work with the query string in a Url. &lt;/p&gt;

&lt;p&gt;You can read more about the query string here: &lt;a href="https://en.wikipedia.org/wiki/Query_string" rel="noopener noreferrer"&gt;Query string - Wikipedia&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also check out all the methods that &lt;code&gt;URLSearchParams interface&lt;/code&gt; provides here: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams" rel="noopener noreferrer"&gt;URLSearchParams - Web APIs | MDN&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this case all we need to do is call &lt;code&gt;URLSearchParams.get()&lt;/code&gt;and pass it the parameter name we need, as a string. Feel free to play around further with this API. No need for an editor this can all be done from your browser console!&lt;/p&gt;

&lt;p&gt;Now while this API is amazing! It does have one issue. It is not supported by IE.&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%2Fr4tr3y8x1805he2eqkd7.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%2Fr4tr3y8x1805he2eqkd7.PNG" alt="Browser compatibility" width="800" height="726"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;MDN does suggest we use window.URL in this case. Strangely enough I tested it on IE 11 and it didn't work. The docs on MDN do not give much more detail on an alternative for IE, so if you have to support IE try using a poly-fill. I like the solution shown on &lt;a href="http://www.jquerybyexample.net/2012/06/get-url-parameters-using-jquery.html" rel="noopener noreferrer"&gt;JQUERY BY EXAMPLE&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When using any of these cool Web APIs it is important to check for browser compatibility. In my case I needed this method for a dashboard project that I am building for a client and the client only uses chrome (luckily). This allowed me to utilize this API.&lt;/p&gt;

&lt;p&gt;Hope this short article can help you on your next project!&lt;/p&gt;

&lt;p&gt;Got questions? Feel free to reach out via the comments or &lt;a href="https://twitter.com/maheralkendi" rel="noopener noreferrer"&gt;my twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok! Now back to learning 👨🏿‍💻&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>url</category>
      <category>api</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
