<?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>Forem: Lucius Emmanuel Emmaccen</title>
    <description>The latest articles on Forem by Lucius Emmanuel Emmaccen (@emmaccen).</description>
    <link>https://forem.com/emmaccen</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%2F372534%2F450e41d1-63dc-4a79-adf9-3bd1abb70f49.jpg</url>
      <title>Forem: Lucius Emmanuel Emmaccen</title>
      <link>https://forem.com/emmaccen</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/emmaccen"/>
    <language>en</language>
    <item>
      <title>React useReducer</title>
      <dc:creator>Lucius Emmanuel Emmaccen</dc:creator>
      <pubDate>Thu, 11 May 2023 09:33:57 +0000</pubDate>
      <link>https://forem.com/emmaccen/react-usereducer-dhn</link>
      <guid>https://forem.com/emmaccen/react-usereducer-dhn</guid>
      <description>&lt;h4&gt;
  
  
  Table of content
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Introduction&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The useReducer Syntax&lt;br&gt;
2.1. What is a state in React&lt;br&gt;
2.2. What is a dispatch in React&lt;br&gt;
2.3. The Reducer function&lt;br&gt;
2.4. Initial state&lt;br&gt;
2.5. Lazy initialization &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How the useReducer hook works&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bailing out of a dispatch&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;useReducer with Typescript &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;useState Vs useReducer&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When to use useReducer &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When not to use useReducer &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Recommend videos&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Interesting reads&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Conclusion &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;State management has been a common topic in the development world over the years. It's a challenging part of the development process, especially for huge applications. This challenge has been solved in many different ways over time and keeps evolving in positive ways.&lt;/p&gt;

&lt;p&gt;In this article, we're going to learn from grassroots, what there is to know about the &lt;code&gt;useReducer&lt;/code&gt; hook, how it helps you manage application state better (and logic), along with real-world examples of how it works and why you might want to use it in your next or current project.&lt;/p&gt;

&lt;h2&gt;
  
  
  The useReducer Syntax
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;const [state, dispatch] = useReducer(reducer, initialArg, init);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;useReducer&lt;/strong&gt; is a function that takes up to three arguments and returns a &lt;strong&gt;state&lt;/strong&gt; and a &lt;strong&gt;dispatch&lt;/strong&gt;. These three arguments are used to determine what the &lt;strong&gt;state&lt;/strong&gt; is and how the &lt;strong&gt;dispatch&lt;/strong&gt; function works.&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%2F54jhsxflsn09gjjpdigi.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%2F54jhsxflsn09gjjpdigi.png" alt="useReducer hook by Lucius emmanuel" width="800" height="282"&gt;&lt;/a&gt;&lt;br&gt;
Don't worry about understanding this upfront, we'll go through every inch of what this means and how it works.&lt;/p&gt;
&lt;h3&gt;
  
  
  What is a state in React?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;const [state, ...&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;A state in react is a piece of data that represents the current status of our application. This &lt;strong&gt;state&lt;/strong&gt; can be used to provide information on the screen or perform background computations/calculations that allow our application to function. &lt;strong&gt;State&lt;/strong&gt; is a fundamental idea in React.&lt;br&gt;
Here's a visual example of a &lt;strong&gt;state&lt;/strong&gt; in React, holding some information about a user.&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%2Fzrscnrf1yhcd86g822ls.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%2Fzrscnrf1yhcd86g822ls.png" alt="States in useReducer by Lucius emmanuel" width="800" height="282"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  What is a dispatch in React?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;const [state, dispatch...&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Dispatch in React is simply a function that takes an instruction about what to do, then passes that instruction to the &lt;strong&gt;reducer&lt;/strong&gt; as an "action". In simple terms, see &lt;strong&gt;dispatch&lt;/strong&gt; as a friendly boss that likes to tell the &lt;strong&gt;reducer&lt;/strong&gt; what to do and is happy about it 😎&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%2Fh5cepjdresrw2cqs1d6n.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%2Fh5cepjdresrw2cqs1d6n.png" alt="the reducer function by Lucius emmanuel" width="800" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're familiar with &lt;strong&gt;Redux&lt;/strong&gt;, this term &lt;strong&gt;dispatch&lt;/strong&gt; might not be new to you but, we'll go through this article assuming you're new to both &lt;strong&gt;Redux&lt;/strong&gt; and &lt;strong&gt;useReducer&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  The reducer function
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;const [state, dispatch] = useReducer(reducer, ...&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The reducer function is a special handler that takes in two parameters. The application's current &lt;code&gt;state&lt;/code&gt; and an &lt;code&gt;action&lt;/code&gt; object, then it uses that to determine/compute the next state of our application (it returns a new state).&lt;br&gt;
Remember how we talked about the &lt;code&gt;dispatch&lt;/code&gt; telling the reducer what to do by passing it an action 💭?. These actions usually contain a &lt;code&gt;type&lt;/code&gt; (what to do) and a &lt;code&gt;payload&lt;/code&gt; (what it needs to do the job).&lt;/p&gt;

&lt;p&gt;Here's a typical example of what a reducer function looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function reducer(state, action) {
  switch (action.type) {
    case "FIX_BUGS":
      return { totalBugs: state.totalBugs - 1 };
    case "CREATE_BUGS":
      return { totalBugs: state.totalBugs + 1 };
    case "SET_TOTAL_BUGS":
      return { totalBugs: action.payload };
    default:
      throw new Error();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we're starting to connect the dots as we'll go through what all these mean visually.&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%2Frw0537lfmsf55ov7aqzj.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%2Frw0537lfmsf55ov7aqzj.png" alt="the use reducer function by Lucius emmanuel" width="800" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s delve into what’s happening in the switch statement. In a real-world application, you’d most likely have more complex logic in the &lt;code&gt;switch&lt;/code&gt; but for this example, we’ll be keeping it simple.&lt;/p&gt;

&lt;p&gt;We have three cases in our &lt;code&gt;switch&lt;/code&gt; statement, which are &lt;code&gt;case "FIX_BUGS"&lt;/code&gt;, &lt;code&gt;case "CREATE_BUGS"&lt;/code&gt; and &lt;code&gt;case "SET_TOTAL_BUGS"&lt;/code&gt;. These are the actions we're explicitly trying to handle. The &lt;code&gt;default&lt;/code&gt; only fires when we &lt;code&gt;dispatch&lt;/code&gt; an action that doesn't match any of our cases. See &lt;strong&gt;cases&lt;/strong&gt; (or action types) as a store of all possible things a particular reducer can do. If the &lt;code&gt;reducer&lt;/code&gt; were a person, "cases" would be the skill list on the CV.&lt;/p&gt;

&lt;p&gt;Here's a visual representation of how the &lt;strong&gt;dispatch&lt;/strong&gt; tells the reducer what to do.&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%2F77mm1gfpcyqp8lyuwjp8.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%2F77mm1gfpcyqp8lyuwjp8.png" alt="dispatch actions paired with reducer by Lucius emmanuel" width="800" height="575"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The initial state
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;const [state, dispatch] = useReducer(reducer, initialArg, ...&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The initial state in a react &lt;code&gt;useReducer&lt;/code&gt; function is the starting state of our application e.g. The default state. In the example we used earlier, we're setting the total bugs of our application in the reducer function based on what type of action the &lt;code&gt;dispatch&lt;/code&gt; tells us. For this reason, we can set the starting point or default state of our bugs count to say... "0" 🤔? or maybe even "100"? 🐛.&lt;/p&gt;

&lt;p&gt;Let's do a hundred! 😎 &lt;code&gt;{totalBugs : 100}&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Lazy initialization
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;const [state, dispatch] = useReducer(reducer, initialArg, init);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;useReducer&lt;/code&gt; takes in an optional third parameter we'll call &lt;code&gt;init&lt;/code&gt;. This &lt;code&gt;init&lt;/code&gt; is going to be a function we'll pass as the third argument to &lt;code&gt;useReducer&lt;/code&gt;. This can be useful if we'd like to create the initial state lazily.&lt;/p&gt;

&lt;p&gt;A common use case would be a situation where the initial state needs to go through some calculations to arrive at a default state or has to fetch data from an API, etc. It looks something like this in code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const init = (initalState) =&amp;gt; {
  console.log(initalState); // 100

//... do some code magic 🪄
//...

  return inital;  // return desired state

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  How the useReducer hook works
&lt;/h2&gt;

&lt;p&gt;Now that we've gone through the syntax: &lt;code&gt;const [state, dispatch] = useReducer(reducer, initialArg, init);&lt;/code&gt; from left to right, it's time to start putting together the pieces in code.&lt;/p&gt;

&lt;p&gt;Here's the complete code snippet for our bugs count application.&lt;br&gt;
&lt;/p&gt;

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

function reducer(state, action) {
  switch (action.type) {
    case "FIX_BUGS":
      return { totalBugs: state.totalBugs - 1 };
    case "CREATE_BUGS":
      return { totalBugs: state.totalBugs + 1 };
    case "SET_TOTAL_BUGS":
      return { totalBugs: action.payload };
    default:
      throw new Error();
  }
}
const init = (inital) =&amp;gt; {
  console.log(inital); // 100
  return inital;
};

export default function App() {
  const [state, dispatch] = useReducer(reducer, { totalBugs: 100 }, init);

  // creating a new state so we don't add extra in the reducer state
  // (this is just for examples)
  const [inputState, setInputState] = useState(0);

  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h1&amp;gt;useReducer&amp;lt;/h1&amp;gt;
      &amp;lt;p&amp;gt;{state.totalBugs} Bugs Left 🧑‍💻&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; dispatch({ type: "FIX_BUGS" })}&amp;gt;FIX_BUGS&amp;lt;/button&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; dispatch({ type: "CREATE_BUGS" })}&amp;gt;
        CREATE_BUGS
      &amp;lt;/button&amp;gt;
      &amp;lt;input
        onChange={(e) =&amp;gt; setInputState(+e.target.value)}
        value={inputState}
        type="number"
      /&amp;gt;
      &amp;lt;button
        onClick={() =&amp;gt;
          dispatch({ type: "SET_TOTAL_BUGS", payload: inputState })
        }
      &amp;gt;
        SET_TOTAL_BUGS
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a live preview of the working code. I created a sandbox.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/usereducer-function-sjh0e8"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;From the walkthrough of the &lt;strong&gt;useReducer&lt;/strong&gt; syntax and what each bolt and knot means, to seeing the actual code in action. We can denote that the &lt;code&gt;useReducer&lt;/code&gt; is a function that can take up to three arguments and returns a &lt;code&gt;state&lt;/code&gt; and a &lt;code&gt;dispatch&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here's a simple and summarized visual representation of the &lt;code&gt;useReducer&lt;/code&gt; lifecycle in 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%2Fuploads%2Farticles%2Fzv9q0kllclyw1d00bjcj.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%2Fzv9q0kllclyw1d00bjcj.png" alt="useReducer lifecycle by Lucius emmanuel" width="800" height="506"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Bailing out of a dispatch
&lt;/h2&gt;

&lt;p&gt;If you return the same &lt;code&gt;state&lt;/code&gt; in your &lt;code&gt;reducer&lt;/code&gt; hook as the current &lt;code&gt;state&lt;/code&gt;. React is smart enough to bail out of rendering or firing effects on components depending on that &lt;code&gt;state&lt;/code&gt;. This is because React uses the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is#Description" rel="noopener noreferrer"&gt;Object.is comparison algorithm&lt;/a&gt; and this tells React that nothing has changed.&lt;/p&gt;

&lt;h2&gt;
  
  
  useReducer with Typescript
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;useReducer&lt;/code&gt; is no stranger to us anymore but how do we actually use it with TypeScript 💭?. Now if you're already familiar with TypeScript, this one should be a piece of cake, however, if you're fairly new, don't worry, we'll have a quick and simple example to get us going.&lt;/p&gt;

&lt;p&gt;What we're going to do here is by no means a &lt;em&gt;rule&lt;/em&gt;, you're free to use any formula or paradigm that makes you sleep better at night 😉.&lt;/p&gt;

&lt;p&gt;Here it is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { ChangeEvent, useReducer } from "react";

// for our state
interface State {
  firstName: string;
  lastName: string;
  age: number;
  language: string;
}

// list of all possible types
enum ActionTypes {
  UPDATE = "UPDATE",
  RESET = "RESET"
}

// action type
interface Actions {
  type: ActionTypes;
  payload?: {
    key: string;
    value: string;
  };
}

// if we need to do some work to provide initial state
const init = (inital: State) =&amp;gt; {
  console.log(inital);
  return inital;
};

// the default state of our app
const initialState = {
  firstName: "",
  lastName: "",
  age: 0,
  language: ""
};

// the reducer handler function
const userFormReducer = (state: State, action: Actions) =&amp;gt; {
  switch (action.type) {
    case "UPDATE":
      return { ...state, [action.payload.key]: action.payload.value };
    case "RESET":
      return initialState;
    default:
      throw new Error();
  }
};

export const UserForm = () =&amp;gt; {
  const [state, dispatch] = useReducer(userFormReducer, initialState, init);

  // for input change event
  const handleChange = (event: ChangeEvent&amp;lt;HTMLInputElement&amp;gt;) =&amp;gt; {
    dispatch({
      type: ActionTypes.UPDATE,
      payload: { key: event.target.name, value: event.target.value }
    });
  };

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;TypeScript Example&amp;lt;/h1&amp;gt;
      &amp;lt;input
        value={state.firstName}
        type="text"
        name="firstName"
        onChange={handleChange}
        placeholder="first name"
      /&amp;gt;
      &amp;lt;input
        value={state.lastName}
        type="text"
        name="lastName"
        onChange={handleChange}
        placeholder="lastName"
      /&amp;gt;
      &amp;lt;input
        value={state.language}
        type="text"
        name="language"
        onChange={handleChange}
        placeholder="language"
      /&amp;gt;
      &amp;lt;input
        value={state.age}
        type="text"
        name="age"
        onChange={handleChange}
        placeholder=""
      /&amp;gt;
      &amp;lt;button
        onClick={() =&amp;gt; dispatch({ type: ActionTypes.RESET })}
        type="reset"
      &amp;gt;
        RESET
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;p&gt;To test this out yourself, live on Sandbox. I've also included the typescript example.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/usereducer-function-sjh0e8"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;This article is not about TypeScript, so we won't be explaining what's going on in that code. A few things to note however is that I intentionally put all the TypeScript code in one file. In a real-world application, you'd most certainly create files for different things and your approach might be quite different (Again, whatever helps you sleep better at night 😉).&lt;/p&gt;

&lt;h2&gt;
  
  
  useState Vs useReducer
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [state, dispatch] = useReducer(reducer, initialArg, init);
//vs
const [state, setState] = useState(initialState)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We won't be creating a webinar or zoom meeting to argue about this, but a rule of thumb is, that everything you can do with a &lt;code&gt;useReducer&lt;/code&gt; you can do with a &lt;code&gt;useState&lt;/code&gt;. In fact, the &lt;code&gt;useReducer&lt;/code&gt; hook is just an alternative to &lt;code&gt;useState&lt;/code&gt; with a few clear differences such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Readability&lt;/li&gt;
&lt;li&gt;Ease of use and,&lt;/li&gt;
&lt;li&gt;Syntax&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Note 💡&lt;br&gt;
React guarantees that &lt;code&gt;dispatch&lt;/code&gt; function identity is stable and won’t change on "re-renders". This is why it’s safe to omit from the &lt;code&gt;useEffect&lt;/code&gt; or &lt;code&gt;useCallback&lt;/code&gt; hook dependency list.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  When to use the useReducer hook
&lt;/h2&gt;

&lt;p&gt;use a &lt;code&gt;useReducer&lt;/code&gt; hook over &lt;code&gt;useState&lt;/code&gt; when you have complex state logic that involves multiple sub-values or when the next state depends on the previous one. This is fairly common when your application begins to grow in size. &lt;code&gt;useReducer&lt;/code&gt; also lets you improve performance for components that trigger deep updates because you can &lt;a href="https://reactjs.org/docs/hooks-faq.html#how-to-avoid-passing-callbacks-down" rel="noopener noreferrer"&gt;pass down a dispatch&lt;/a&gt; instead of callbacks.&lt;/p&gt;

&lt;h2&gt;
  
  
  When not to use useReducer
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;useReducer&lt;/code&gt; is awesome, but there are certain scenarios where it doesn't make our lives any easier. Here are a few of such cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Don't use a &lt;code&gt;useReducer&lt;/code&gt; hook when you're dealing with simple state logic.&lt;/li&gt;
&lt;li&gt;When your application needs a single source of truth. You'll be better off using a more powerful library like &lt;a href="https://react-redux.js.org/" rel="noopener noreferrer"&gt;Redux&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;When prop-drilling starts to yell at you. This happens when you get trapped in the hellish world of passing down too many props (state) to and from child components to a child component that later comes to hunt you.&lt;/li&gt;
&lt;li&gt;When state lifting to parent/top-level components no longer suffices.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Recommend videos
&lt;/h2&gt;

&lt;p&gt;There's always more to learn, so if you'd like to learn more tricks and hacks about the useReducer hook. I'd recommend you look up the video links below&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=wcRawY6aJaw" rel="noopener noreferrer"&gt;React Hooks useReducer Tutorial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=9KzQ9xFSAEU" rel="noopener noreferrer"&gt;useReducer with TypeScript&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  More interesting reads from my blogs
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/emmaccen/how-to-create-a-global-json-search-algorithm-in-javascript-55ko"&gt;How To Create A Global "JSON Search Algorithm" In JavaScript&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/emmaccen/how-to-know-if-an-element-is-visible-in-viewport-c45"&gt;How To Know If An Element Is Visible In Viewport&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/emmaccen/how-to-create-a-glassmorphic-template-in-pure-html-css-3jo4"&gt;How To Create A "Glassmorphic" Template In Pure HTML &amp;amp; CSS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;The useReducer is a powerful hook if used properly and I hope we've been able to learn about it without any confusion. If you'd like to contribute to this post or drop feedback, feel free to leave a comment 📝 and drop a like ❣️. Thanks for reading, you're awesome! 😎&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

&lt;p&gt;I'd love to connect with you 🙂&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/emmanuel-lucius-emmaccen/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Emmaccen" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;PS: This article was initially published on "Copycat"&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Most Software Developers Are Depressed</title>
      <dc:creator>Lucius Emmanuel Emmaccen</dc:creator>
      <pubDate>Tue, 29 Mar 2022 08:35:05 +0000</pubDate>
      <link>https://forem.com/emmaccen/most-software-developers-are-depressed-4h5i</link>
      <guid>https://forem.com/emmaccen/most-software-developers-are-depressed-4h5i</guid>
      <description>&lt;p&gt;It’s not uncommon to see people in tech talk about the new stuffs that’s out there, and how awesome a technology is.&lt;/p&gt;

&lt;p&gt;But… are most engineers really happy? I mean, the “real happiness?”&lt;/p&gt;

&lt;p&gt;This is not something that’s talked about a lot and I’d love to hear it from you, if you’ve found happiness, what made it work? And if you’re struggling to find happiness, what really makes you unhappy?&lt;/p&gt;

&lt;p&gt;I’ve got a few of mine too but I want this to be a discussion.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Happiness is attainable and we all deserve to be happy&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let’s talk!&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>watercooler</category>
      <category>happiness</category>
      <category>lifestyle</category>
    </item>
    <item>
      <title>Build Your Professional Portfolio Website In 2 Hours Using HTML &amp; CSS.</title>
      <dc:creator>Lucius Emmanuel Emmaccen</dc:creator>
      <pubDate>Wed, 23 Mar 2022 08:27:57 +0000</pubDate>
      <link>https://forem.com/emmaccen/build-your-professional-portfolio-website-in-2-hours-using-html-css-5g9i</link>
      <guid>https://forem.com/emmaccen/build-your-professional-portfolio-website-in-2-hours-using-html-css-5g9i</guid>
      <description>&lt;p&gt;Hello 👋 , in this article we're going to learn how to build a simple, yet professional portfolio using pure &lt;em&gt;HTML&lt;/em&gt; and &lt;em&gt;CSS&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;There are a million and one reasons to have a personal portfolio website, from helping you have a gallery of your work/projects online, to, improving your chances of getting a job etc. The fact is, not everyone needs to have one and I recently &lt;a href="https://dev.to/emmaccen/reasons-why-you-need-to-have-a-professional-portfolio-5cji"&gt;wrote an article&lt;/a&gt; explaining in detail what a portfolio is, why you might want to have one and it's importance in the world today.&lt;/p&gt;

&lt;h3&gt;
  
  
  What We'll Build 💪
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Contact Section (Serving as the Nav &amp;amp;&amp;amp; Footer) &lt;/li&gt;
&lt;li&gt;About Section&lt;/li&gt;
&lt;li&gt;Work/Portfolio&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It might be important to note that, this tutorial is beginner-friendly, you don't need to have a "god-mode" knowledge of HTML or CSS. We'll walk through the entire code together along with suggestions on how to improve them later because we'll be keeping things super simple and summarized.&lt;/p&gt;

&lt;h3&gt;
  
  
  File Structure 📂
&lt;/h3&gt;

&lt;p&gt;To follow along with this tutorial, you'll need a file structure such as 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%2Fuploads%2Farticles%2F7tb1p4ipy81grjl2b792.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%2F7tb1p4ipy81grjl2b792.png" alt="emmaccen's blog portfolio file structure" width="517" height="295"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Warm-Up
&lt;/h3&gt;

&lt;p&gt;Looking at the &lt;a href="https://www.figma.com/file/06sZmTFTbPFJjm918O7TKP/Dev-Portfolio?node-id=0%3A1" rel="noopener noreferrer"&gt;UI Design&lt;/a&gt; and having an overview of where we're going with code and how the finished website will look like, we can begin to mark out some key points such as colours, sections, styles etc.&lt;/p&gt;

&lt;p&gt;Because of this, we'll start by creating some global styles following the DRY (don't repeat yourself) principle. Also, for this tutorial, we'll be interchanging between &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid" rel="noopener noreferrer"&gt;Grid&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox" rel="noopener noreferrer"&gt;Flexbox&lt;/a&gt;. I promised to make this tutorial simple so, we won't be writing/coding anything complicated.&lt;/p&gt;

&lt;p&gt;If you find something you don't understand in this article, that's fine, you can always Google or learn them later. Don't let anything stop you, you're already awesome 👍.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I've decided to paste the code snippets in PNG formats. This is just me trying to compel/encourage you to code it out by hand because it helps with understanding and well as retention. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you don't want to go through the process of typing it out, head over to the end of the page and visit the GitHub link, you can download the entire project from there 🧑‍💻.&lt;/p&gt;

&lt;p&gt;With that out of the way, we're ready to start coding.&lt;/p&gt;

&lt;h3&gt;
  
  
  Index.html
&lt;/h3&gt;

&lt;p&gt;Your file structure should look something 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%2Fuploads%2Farticles%2Fmmcv5thh03hh2l2lcphk.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%2Fmmcv5thh03hh2l2lcphk.png" alt="VS code file structure" width="454" height="553"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please, ignore the &lt;code&gt;index.js&lt;/code&gt; and &lt;code&gt;README.md&lt;/code&gt; files. We won't be needing them for this tutorial. I'm using &lt;a href="https://code.visualstudio.com/download" rel="noopener noreferrer"&gt;VS code&lt;/a&gt; by the way, you can use any code editor you want.&lt;/p&gt;

&lt;p&gt;In your &lt;code&gt;index.html&lt;/code&gt; file, create a basic HTML template. You can generate this by typing &lt;code&gt;!&lt;/code&gt; followed by the &lt;em&gt;TAB key&lt;/em&gt;. See image for reference 👇&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%2Fox16ivovnjob2ua3el4s.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%2Fox16ivovnjob2ua3el4s.png" alt="VS HTML code snippet generator" width="800" height="283"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After you've done that, you should have something 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%2Fuploads%2Farticles%2Fr4en3pkpv3kg7la52yru.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%2Fr4en3pkpv3kg7la52yru.png" alt="HTML skeleton" width="800" height="618"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Few things to note from the image above.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I've included a &lt;a href="https://fonts.google.com/?query=inter" rel="noopener noreferrer"&gt;google font&lt;/a&gt; (we'll use this as our font but, feel free to use any font you want)&lt;/li&gt;
&lt;li&gt;I've linked the &lt;code&gt;index.css&lt;/code&gt; file so we can use it in our &lt;code&gt;index.html&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;For everything else, you can put anything you like. e.g the &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tags&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now, run the application and make sure it works as expected. I'm using &lt;a href="https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer" rel="noopener noreferrer"&gt;Live server&lt;/a&gt;, a VS Code extension that provides &lt;em&gt;real-time&lt;/em&gt; updates of your changes (You don't have to use it though).&lt;/p&gt;

&lt;p&gt;To verify that our &lt;code&gt;CSS&lt;/code&gt; file have been linked correctly.&lt;br&gt;
In your &lt;code&gt;CSS&lt;/code&gt; file, paste: &lt;code&gt;body {background-color: #333;}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now run the app, you should see a dark background.&lt;br&gt;
If that is not the case, try to verify you don't have a typo when linking your file, either way, I'm sure you'll figure it out 😎!.&lt;/p&gt;

&lt;p&gt;Moving forward.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For the files/assets (icons, images) we'll be using in this tutorial, Checkout the &lt;a href="https://github.com/Emmaccen/blogPortfolio" rel="noopener noreferrer"&gt;GitHub repo&lt;/a&gt;, you can download them from there, otherwise you can use &lt;a href="https://fontawesome.com/" rel="noopener noreferrer"&gt;Font Awesome&lt;/a&gt;, &lt;a href="https://www.flaticon.com/" rel="noopener noreferrer"&gt;Flat Icon&lt;/a&gt; or any icon library of your choice.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  CSS Globals and Setup ⚙️
&lt;/h3&gt;

&lt;p&gt;We'll create some global styles/variables and some basic setups, these are properties I know for sure we'll be using more than once in this tutorial and you don't have to know it all at first, just create a global when you notice you're re-writing the same thing more than once.&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%2Fr588o4dyv8nkbu5kz6i0.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%2Fr588o4dyv8nkbu5kz6i0.png" alt="CSS Globals code image" width="800" height="2553"&gt;&lt;/a&gt;&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%2Ft46da37drbmujg6j0uvx.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%2Ft46da37drbmujg6j0uvx.png" alt="CSS Globals code image" width="800" height="2243"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;You might have to click on the image if it appears to be blurry, stretched or unreadable&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;We'll be coding 3-sections for this portfolio and now that we have all the basic setup ready, let's get coding.&lt;/p&gt;

&lt;h3&gt;
  
  
  Contact Section (Also the Nav and Footer)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;HTML&lt;/li&gt;
&lt;/ul&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%2F1dsnnicq180ulc6f2qu8.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%2F1dsnnicq180ulc6f2qu8.png" alt="Contact section code image" width="800" height="261"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CSS&lt;/li&gt;
&lt;/ul&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%2Fnhrscy536n4rpflj61h6.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%2Fnhrscy536n4rpflj61h6.png" alt="contact section CSS code image" width="800" height="581"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visual 🔎&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you didn't miss anything out, you should have 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%2Fuploads%2Farticles%2F3wb1neuz8q4ief0v62mi.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%2F3wb1neuz8q4ief0v62mi.png" alt="Nav section Image" width="800" height="33"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can take some time to understand the HTML structure and how the styles apply. Also, as you move forward with the code, you'll soon come to realize that we're mostly just reusing the CSS we've written in globals earlier (Section: CSS Globals and Setup).&lt;/p&gt;

&lt;h3&gt;
  
  
  About Section
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;HTML&lt;/li&gt;
&lt;/ul&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%2F35a3s6k62lzri1u42m5h.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%2F35a3s6k62lzri1u42m5h.png" alt="About section code image" width="800" height="465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, if you're wondering what &lt;code&gt;&amp;lt;script&amp;gt;document.write(new Date().getFullYear() - 2013)&amp;lt;/script&amp;gt;&lt;/code&gt; does. It's javaScript and it's here so we won't have to calculate the years of experience by updating the portfolio/code manually. So if 2012, 2018, or 2020 is the year you started coding? Just replace 2013 in the code with yours.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Though the year you started coding might not exactly pass as experience but... you get the point 🍵&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;CSS &lt;/li&gt;
&lt;/ul&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%2Fkdjdc0tz2kitgh14koo8.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%2Fkdjdc0tz2kitgh14koo8.png" alt="About section CSS code image" width="800" height="927"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visuals 🔎&lt;/li&gt;
&lt;/ul&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%2F4crykbfva7cfkgljg40a.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%2F4crykbfva7cfkgljg40a.png" alt="About section visual image" width="800" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you don't see something similar to the visual 👆 image above, make sure all your &lt;em&gt;HTML Tags&lt;/em&gt; are closed correctly. Do some error checks on your syntax, I'm sure you'll fix it.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Experience Section
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;HTML&lt;/li&gt;
&lt;/ul&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%2Fwl7czf3xbmxkfg8i1c0w.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%2Fwl7czf3xbmxkfg8i1c0w.png" alt="Experience section code image" width="800" height="660"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the snippet above, the &lt;code&gt;duplicateThisDiv&lt;/code&gt; class is purely for reference, we won't be styling using that class name. Just duplicate the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; by as much experience you have.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CSS&lt;/li&gt;
&lt;/ul&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%2F9ngald5xipiujfcf53ej.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%2F9ngald5xipiujfcf53ej.png" alt="Experience section CSS code image" width="800" height="373"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visuals 🔎&lt;/li&gt;
&lt;/ul&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%2Fqbyecut5u9ok18gmx429.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%2Fqbyecut5u9ok18gmx429.png" alt="Experience section visual image" width="800" height="387"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Portfolio Section
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;HTML&lt;/li&gt;
&lt;/ul&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%2Fmh21ti3vxk8eirfyzub7.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%2Fmh21ti3vxk8eirfyzub7.png" alt="Portfolio section code image" width="800" height="465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;There's a &lt;code&gt;duplicateThisTag&lt;/code&gt; class in the snippet above. You already know what to do 👍&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CSS&lt;/li&gt;
&lt;/ul&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%2F87stagobwh92ns3an5i0.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%2F87stagobwh92ns3an5i0.png" alt="Portfolio section CSS code image" width="800" height="858"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visuals 🔎&lt;/li&gt;
&lt;/ul&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%2Fsigbnjlfd9lmq5ggm4uy.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%2Fsigbnjlfd9lmq5ggm4uy.png" alt="Portfolio section visual image" width="800" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Lastly
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The Footer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is just a replica of the Contact section, so just copy/paste it and use it as your footer. Don't forget to replace the &lt;code&gt;&amp;lt;nav&amp;gt;&lt;/code&gt; tag with a &lt;code&gt;footer&lt;/code&gt; tag in this case.&lt;/p&gt;

&lt;h4&gt;
  
  
  Full Design 🎨🖌️
&lt;/h4&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%2Fkqyjm0pjiedgbt1y12zt.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%2Fkqyjm0pjiedgbt1y12zt.png" alt="Lucius emmanuel's design" width="800" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  My Thoughts 🤔 💭
&lt;/h3&gt;

&lt;p&gt;I've seen people get better opportunities because they have an online portfolio, including myself (and you don't have to own the greatest portfolio on the planet). If you already have solid years of experience, you might not necessarily need one, however, having one has no disadvantage irrespective of your level in the tech world (I understand that you might have a different opinion).&lt;br&gt;
You can look up &lt;a href="https://dev.to/emmaccen/reasons-why-you-need-to-have-a-professional-portfolio-5cji"&gt;some reasons&lt;/a&gt; why you should consider having one if you're still unsure about the importance of it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pro Tips 💡
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Check out &lt;a href="https://michalsnik.github.io/aos/" rel="noopener noreferrer"&gt;AOS&lt;/a&gt; to add some life to your website. &lt;/li&gt;
&lt;li&gt;Keep an eye out if you want to learn how to host your website online (I'll be posting in a few days)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For design inspiration (To spark your creativity) look up: &lt;br&gt;
1 &lt;a href="https://www.behance.net/" rel="noopener noreferrer"&gt;Behance&lt;/a&gt;&lt;br&gt;
2 &lt;a href="https://dribbble.com/" rel="noopener noreferrer"&gt;Dribbble&lt;/a&gt;&lt;br&gt;
3 &lt;a href="https://www.awwwards.com/" rel="noopener noreferrer"&gt;Awwwards&lt;/a&gt;&lt;br&gt;
4 &lt;a href="https://www.webdesign-inspiration.com/" rel="noopener noreferrer"&gt;Web Design Inspiration&lt;/a&gt;&lt;br&gt;
5 &lt;a href="https://www.frontendmentor.io/" rel="noopener noreferrer"&gt;Frontend Mentor&lt;/a&gt; etc.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;a href="https://compressnow.com/" rel="noopener noreferrer"&gt;Compress Now&lt;/a&gt; to compress your images (save some file space)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://fonts.google.com/" rel="noopener noreferrer"&gt;Google fonts&lt;/a&gt; For fonts&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/Emmaccen/blogPortfolio" rel="noopener noreferrer"&gt;GitHub repo&lt;/a&gt; for this tutorial&lt;/li&gt;
&lt;li&gt;&lt;a href="https://vanilla-portfolio-website.netlify.app/" rel="noopener noreferrer"&gt;Live Website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.figma.com/file/06sZmTFTbPFJjm918O7TKP/Dev-Portfolio?node-id=0%3A1" rel="noopener noreferrer"&gt;Website UI Design&lt;/a&gt; by &lt;a href="https://www.behance.net/Adigun007/" rel="noopener noreferrer"&gt;Damilare&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Cover Design by me ❣️&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;It's been great having you read up to this point. I post simple tutorials like this, so don't forget to &lt;a href="https://dev.to/emmaccen"&gt;follow me&lt;/a&gt; to get more content. &lt;br&gt;
Do play with the comment/discussion area, like and bookmark this blog if you love it or share with others.&lt;br&gt;
Thank you! 🙏&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Socials&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/emmanuel-lucius-emmaccen/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://twitter.com/emmaccen" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Interesting reads&lt;/em&gt; 📚&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/emmaccen/how-to-create-a-glassmorphic-template-in-pure-html-css-3jo4"&gt;How to create a Glassmorphic template in pure HTML and CSS &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/emmaccen/how-to-know-if-an-element-is-visible-in-viewport-c45"&gt;How to know if an element is visible in viewport&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/emmaccen/how-to-integrate-a-rich-text-editor-wysiwyg-in-your-react-js-project-1i4o"&gt;Integrate a rich text editor in your React.js project&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>portfolio</category>
      <category>website</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Reasons Why You Need To Have A Professional Portfolio.</title>
      <dc:creator>Lucius Emmanuel Emmaccen</dc:creator>
      <pubDate>Mon, 02 Aug 2021 09:33:07 +0000</pubDate>
      <link>https://forem.com/emmaccen/reasons-why-you-need-to-have-a-professional-portfolio-5cji</link>
      <guid>https://forem.com/emmaccen/reasons-why-you-need-to-have-a-professional-portfolio-5cji</guid>
      <description>&lt;p&gt;I have often found people to shy away from the practice of having a professional portfolio. While it might seem negligible in some situations, more often than not, it has proven to be of great importance.&lt;/p&gt;

&lt;p&gt;In this article, we are going to observe and answer a few questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is a portfolio?&lt;/li&gt;
&lt;li&gt;Why do you need one?&lt;/li&gt;
&lt;li&gt;What jobs/industries use portfolios&lt;/li&gt;
&lt;li&gt;What should go into a portfolio&lt;/li&gt;
&lt;li&gt;What should not go into a portfolio&lt;/li&gt;
&lt;li&gt;Should you have a "hard copy" or "online" portfolio&lt;/li&gt;
&lt;li&gt;How do you create one?&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  What is a portfolio?
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;A portfolio is a collection of records or documentation that provides proof of accomplishments, experience, skills, attributions and work samples. It can be a website, a binder or a physical book, depending on the line of work or profession.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;It might be necessary to note that a &lt;strong&gt;Portfolio&lt;/strong&gt; is quite different from a &lt;strong&gt;Resume&lt;/strong&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dribbble.com/shots/15187218-Adam-Zonski-Personal-Portfolio-Website?utm_source=Clipboard_Shot&amp;amp;utm_campaign=nurpraditya&amp;amp;utm_content=Adam%20Zonski%20-%20Personal%20Portfolio%20Website&amp;amp;utm_medium=Social_Share&amp;amp;utm_source=Clipboard_Shot&amp;amp;utm_campaign=nurpraditya&amp;amp;utm_content=Adam%20Zonski%20-%20Personal%20Portfolio%20Website&amp;amp;utm_medium=Social_Share" rel="noopener noreferrer"&gt;Design by Nur Praditya&lt;/a&gt;&lt;br&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%2Fggt2jsdvv7ie7q819eok.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%2Fggt2jsdvv7ie7q819eok.png" alt="Design by Nur Praditya" width="788" height="414"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Why do you need one?
&lt;/h4&gt;

&lt;p&gt;Having a portfolio can improve your recognition in a professional or academic setting. It is an opportunity to illustrate your competencies, presents evidence of your skills and abilities, highlights a comprehensive idea of your best work and can be seen as a brochure for the services you are selling. It allows you to &lt;em&gt;show and not just tell&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Portfolios are great for freelancers or independent contractors, business owners or consultants who need to provide work samples to potential clients. The practice of putting together a portfolio: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Serves as a reminder of your past accomplishments and acquired skills&lt;/li&gt;
&lt;li&gt;Allows you to showcase your creativity and persona that differentiates you from your competition&lt;/li&gt;
&lt;li&gt;A source of motivation, high self-esteem and confidence&lt;/li&gt;
&lt;li&gt;Gives you credibility&lt;/li&gt;
&lt;li&gt;Makes you a more effective interviewee&lt;/li&gt;
&lt;li&gt;Helps potential clients visualize working with you&lt;/li&gt;
&lt;li&gt;Can help apply for jobs, scholarships, grants and negotiating promotions and raises.&lt;/li&gt;
&lt;li&gt;Can pass for work and learning experience&lt;/li&gt;
&lt;li&gt;Helps you to be seen and discovered (e.g. online portfolio)&lt;/li&gt;
&lt;li&gt;Allows you to market the services you provide and build a reputation and following.&lt;/li&gt;
&lt;li&gt;Demonstrates consistency and compels you to learn/do more&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are more reasons to consider, but I am sure you get the idea.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dribbble.com/shots/14909770-Landing-Page-CV-Head-of-Marketing?utm_source=Clipboard_Shot&amp;amp;utm_campaign=outcrowd&amp;amp;utm_content=Landing%20Page%20-%20CV%20Head%20of%20Marketing&amp;amp;utm_medium=Social_Share&amp;amp;utm_source=Clipboard_Shot&amp;amp;utm_campaign=outcrowd&amp;amp;utm_content=Landing%20Page%20-%20CV%20Head%20of%20Marketing&amp;amp;utm_medium=Social_Share" rel="noopener noreferrer"&gt;Design by Outcrowd&lt;/a&gt;&lt;br&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%2F7lzrom74o1b9x4uo31g9.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%2F7lzrom74o1b9x4uo31g9.png" alt="Design by Outcrowd" width="751" height="519"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  What jobs / industries use portfolios?
&lt;/h4&gt;

&lt;p&gt;Years back, it is common to see more people in the &lt;strong&gt;Visual Profession&lt;/strong&gt; having a portfolio, such as Artists and Creative professionals, photographers, architects, teachers, graphic designers, front-end engineers, painters, etc.&lt;/p&gt;

&lt;p&gt;In the world today, every professional can benefit from having one, even those in the fields &lt;em&gt;not directly&lt;/em&gt; related to visual. e.g. Backend engineers (could create documentation of their involvement in a project, a short video or utilize GitHub etc.), Radio broadcasters/podcasters, Attorneys, judges and politicians, coaches and athletes etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dribbble.com/shots/15380331-Modern-Furniture-Website-concept?utm_source=Clipboard_Shot&amp;amp;utm_campaign=thomsoon_com&amp;amp;utm_content=Modern%20Furniture%20-%20Website%20concept&amp;amp;utm_medium=Social_Share&amp;amp;utm_source=Clipboard_Shot&amp;amp;utm_campaign=thomsoon_com&amp;amp;utm_content=Modern%20Furniture%20-%20Website%20concept&amp;amp;utm_medium=Social_Share" rel="noopener noreferrer"&gt;Design by Tomasz Mazurczak&lt;/a&gt;&lt;br&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%2F78uf0pjfq0lkxd82yqzr.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%2F78uf0pjfq0lkxd82yqzr.png" alt="Design by Tomasz Mazurczak" width="784" height="526"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  What should go into a portfolio?
&lt;/h4&gt;

&lt;p&gt;Anything that spotlights your accomplishments and abilities should go in your portfolio. It should capture an idea of who you are and the services you provide.&lt;/p&gt;

&lt;p&gt;Here are some items I would recommend you incorporate in your portfolio:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A short and precise summary of who you are.&lt;/li&gt;
&lt;li&gt;Updated resume or CV&lt;/li&gt;
&lt;li&gt;List of skills, tools or technologies you use&lt;/li&gt;
&lt;li&gt;Work experience&lt;/li&gt;
&lt;li&gt;Diplomas (Education), professional certificates and Transcripts (if any)&lt;/li&gt;
&lt;li&gt;Reference letters, awards, testimonials, and LinkedIn recommendations&lt;/li&gt;
&lt;li&gt;Some of your content (if you create content) e.g. Blogs, YouTube videos, Podcasts etc.&lt;/li&gt;
&lt;li&gt;Work samples you have created e.g. Websites, UI/UX designs, project documentation or case studies, video presentations, Artwork (for artists), PowerPoint presentations, Slides etc.&lt;/li&gt;
&lt;li&gt;Lists of accomplishments/awards&lt;/li&gt;
&lt;li&gt;Thank you notes or emails from clients or co-workers (Testimonials) etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  What should not go into a portfolio?
&lt;/h4&gt;

&lt;p&gt;You might get tempted to want a whole Wikipedia of things on your portfolio, but more often than not, it does not increase positive perception. Being super precise and detailed is very important when structuring your portfolio (which is beyond the scope of this article) as it can considerably improve the way you are seen as a professional.&lt;br&gt;
Here are a couple of things I have found to be less useful in a portfolio&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Having a waterfall of summary in your "About Me" section. A couple of lines of text should pretty much tell the story&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do not put ratings or percentages on your skills&lt;/strong&gt;. I am guilty as I did it in the past. We could argue all day about it, but the truth is, own your skill and do not put a dent in it. Having things like: HTML(50%), CSS(90%), Photoshop(45%) etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Here's a screenshot taken from my first portfolio website&lt;/em&gt;&lt;br&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%2Fburclur56uitbmg0bwq8.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%2Fburclur56uitbmg0bwq8.png" alt="skills with ratings" width="800" height="366"&gt;&lt;/a&gt;&lt;br&gt;
Please, remove the ratings. Your 50% rating might be the 100% a company is looking for.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Overly-complicated, overly-designed layout&lt;/li&gt;
&lt;li&gt;Lack of proper structure and personality&lt;/li&gt;
&lt;li&gt;Do not tell personal stories.&lt;/li&gt;
&lt;li&gt;Do not include your house address (Employers will not perceive you as being security conscious, same for your CV). Your email is just fine.&lt;/li&gt;
&lt;li&gt;Only include things relevant to your field of work/study.&lt;/li&gt;
&lt;li&gt;Use only high-fidelity images (but one that will still load fast in the browser)&lt;/li&gt;
&lt;li&gt;Provide a way to get in touch e.g. A mail, link or a contact form.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your get-in-touch section might look something like this if you decided to go with a form field:&lt;br&gt;
&lt;em&gt;Screenshot is taken from my current portfolio&lt;/em&gt;&lt;br&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%2Fc2t7fqfcfvwr3icw2lzo.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%2Fc2t7fqfcfvwr3icw2lzo.png" alt="portfolio contact section" width="800" height="346"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Should you have a hard copy or online portfolio?
&lt;/h4&gt;

&lt;p&gt;Whether or not you use an online or hard copy portfolio, all depends on your industry and personal preference. Research your industry for what's common and beneficial, then, make a decision. &lt;br&gt;
whichever industry it is, it might still be beneficial to have an online presence.&lt;/p&gt;

&lt;h4&gt;
  
  
  How do you create one?
&lt;/h4&gt;

&lt;p&gt;For online portfolios, you can build one for yourself if you are a web developer, have someone build one for you, or use a prebuilt template.&lt;br&gt;
Anyone you decide, be sure to research and make good decisions on what design best suits your field.&lt;/p&gt;

&lt;p&gt;For hard-copy portfolios, you can use a ring binder or leather-bound padfolio. Be sure to organize/tab them into sections.&lt;/p&gt;

&lt;p&gt;Feel free to google &lt;em&gt;“online portfolio websites”  or  “online portfolio builder”&lt;/em&gt;. You can also get design inspiration from hundreds of websites out there if you are building one for yourself.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Please note: It does not have to be 100% a website.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I have seen people use several platforms as their portfolio, e.g.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.google.com/presentation/u/0/" rel="noopener noreferrer"&gt;Google slides&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://drive.google.com/" rel="noopener noreferrer"&gt;Google Drive portfolio&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;A PDF hosted online&lt;/li&gt;
&lt;li&gt;A &lt;a href="https://www.figma.com/" rel="noopener noreferrer"&gt;Figma&lt;/a&gt; or &lt;a href="https://www.adobe.com/" rel="noopener noreferrer"&gt;Adobe&lt;/a&gt; Design with a "live link"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Other options you could utilize:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your &lt;a href="https://www.linkedin.com/" rel="noopener noreferrer"&gt;LinkedIn profile&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.github.com/" rel="noopener noreferrer"&gt;GitHub profile&lt;/a&gt; with projects having detailed ReadMe.md describing project specifications, features and your involvement&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.behance.net/" rel="noopener noreferrer"&gt;Behance&lt;/a&gt; and, many more.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Again, research your industry and find what best suits you.&lt;/p&gt;

&lt;h5&gt;
  
  
  Pro Tips
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Replace practice projects with professional ones as soon as you start having them, e.g. Remove the calculator web app you coded and replace it with your new blog website (even if it is just presentation/static).&lt;/li&gt;
&lt;li&gt;Update the CV on your portfolio as you update them on your PC or mobile&lt;/li&gt;
&lt;li&gt;Do not waste considerable time trying to make it perfect, it never will. You can always make minor updates later in the future.&lt;/li&gt;
&lt;li&gt;Get your portfolio reviewed by a more senior person in your field&lt;/li&gt;
&lt;li&gt;You do not need to have a hundred completed projects before you start a portfolio. Start where you're at, and you'll never regret it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's pretty much it. This article doesn't cover all you need to know and I'd appreciate it if you can drop more &lt;strong&gt;suggestions&lt;/strong&gt;, &lt;strong&gt;Portfolio design Inspiration links&lt;/strong&gt;, &lt;strong&gt;Your thoughts&lt;/strong&gt;, &lt;strong&gt;Your portfolio website link&lt;/strong&gt; to inspire others, and &lt;strong&gt;Comments&lt;/strong&gt; in the discussion box below. You might provide/say something important to other readers. Also, your feedbacks are welcome if this post needs improvement. Do bookmark, like/unicorn this post for reference (and also to support me)&lt;/p&gt;

&lt;p&gt;Keep an eye out. Soon, I will post a step by step process on "How to build a simple online portfolio as a web developer".&lt;/p&gt;

&lt;p&gt;Thanks for reading 😊.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>portfolio</category>
      <category>resume</category>
    </item>
    <item>
      <title>How To Create A Global "JSON Search Algorithm" In JavaScript.</title>
      <dc:creator>Lucius Emmanuel Emmaccen</dc:creator>
      <pubDate>Mon, 01 Mar 2021 10:24:34 +0000</pubDate>
      <link>https://forem.com/emmaccen/how-to-create-a-global-json-search-algorithm-in-javascript-55ko</link>
      <guid>https://forem.com/emmaccen/how-to-create-a-global-json-search-algorithm-in-javascript-55ko</guid>
      <description>&lt;p&gt;Writing a &lt;strong&gt;Search&lt;/strong&gt; feature for every single page or section on your website can be really tedious, and even if you create a reusable function, you might end up changing the code multiple times for it to work for new or dynamic types of JSON data.&lt;/p&gt;

&lt;p&gt;I first noticed this problem at work, where I had to write and modify my reusable search function to work for new types of "JSON data" or situations where minor changes would require me to handle page-specific search instructions.&lt;/p&gt;

&lt;p&gt;For the most part, You'd require to know the &lt;strong&gt;keys&lt;/strong&gt; of the &lt;strong&gt;JSON&lt;/strong&gt; you'll be working with, so let's say you want to implement a search that can... search using &lt;em&gt;First Name&lt;/em&gt;, &lt;em&gt;Last Name&lt;/em&gt;, &lt;em&gt;Email Address&lt;/em&gt; etc your code might look something 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%2Fuploads%2Farticles%2Fh9jl4mzcktkd51341loz.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%2Fh9jl4mzcktkd51341loz.png" alt="code snippet image" width="800" height="773"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you read the code closely, you'd realize I knew beforehand the &lt;strong&gt;keys&lt;/strong&gt; of the data I'll be working with, and let's presume in the future, the backend changes and &lt;strong&gt;email&lt;/strong&gt; is taken out, or &lt;strong&gt;phoneNumber&lt;/strong&gt; which in this case, the code will break (crash) or the backend includes a new data we'd love to also be able to search with, like &lt;strong&gt;age&lt;/strong&gt; or &lt;strong&gt;role&lt;/strong&gt;, which would result in us changing the code to cater for &lt;strong&gt;age&lt;/strong&gt; etc.&lt;/p&gt;

&lt;p&gt;You should already start seeing the problem here so... I decide to come up with a simple algorithm that'll eliminate all these problems by : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Making sure you don't even have to know or care about the keys&lt;/li&gt;
&lt;li&gt;Still works, even for changing or dynamic JSON data&lt;/li&gt;
&lt;li&gt;Includes combination settings e.g combining &lt;em&gt;first name&lt;/em&gt;, &lt;em&gt;last name&lt;/em&gt; and &lt;em&gt;middle name&lt;/em&gt; in search inputs.&lt;/li&gt;
&lt;li&gt;Prevent your heart from racing when your company/friend(s) is/are testing your application&lt;/li&gt;
&lt;li&gt;Saves you a lot of time and burnout 😎&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Okay, now let's get to it, we'll start from the basics then improve along the way.&lt;/p&gt;

&lt;h2&gt;
  
  
  Version 1
&lt;/h2&gt;

&lt;p&gt;First, the most basic requirement is your array of data and a function that'll feed on it, so if you have : &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%2F8b2wjzgyt3odp77zt23l.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%2F8b2wjzgyt3odp77zt23l.png" alt="JOSN code snippet image" width="800" height="868"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We'll start the search code by :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Declaring a search function that takes 3-arguments ( the &lt;strong&gt;event&lt;/strong&gt; (in this case, its the user input), the &lt;strong&gt;JSON array&lt;/strong&gt;, and the &lt;strong&gt;function&lt;/strong&gt; (or variable) that'll receive the result.&lt;/li&gt;
&lt;/ul&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%2F9cgo7oll6ujeayu33wvs.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%2F9cgo7oll6ujeayu33wvs.png" alt="code snippet image" width="800" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After that, we'll fix the code below to prevent the page from refreshing and getting the user input (typed search value)&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%2Fnbhrxyx0xu3xjmaqdwi2.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%2Fnbhrxyx0xu3xjmaqdwi2.png" alt="code snippet image" width="800" height="373"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The second step here would be to loop over the array and get the search result using &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter" rel="noopener noreferrer"&gt;Array.filter&lt;/a&gt;, and what this simply does is loop through the array and do some conditional checks that we'll write, and if the check passes, it'll return the specific data that passes the test. Check the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter" rel="noopener noreferrer"&gt;MDN docs&lt;/a&gt; for an in-depth information.&lt;/p&gt;

&lt;p&gt;So we'll have something like :&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%2F2rt5yn18ghidaycfmmmf.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%2F2rt5yn18ghidaycfmmmf.png" alt="code snippet image" width="800" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, it's all starting to look a lot like the old code I complained about, but here comes the trick of this whole saga.&lt;/p&gt;

&lt;p&gt;If you remember I said you won't have to worry about knowing the &lt;strong&gt;Keys&lt;/strong&gt; of the JSON data? (`{"Key" : "value"}), well... we're in luck because there's a function for getting the &lt;strong&gt;keys&lt;/strong&gt; (even values) of an object in JavaScript.&lt;/p&gt;

&lt;p&gt;We'll be using the &lt;code&gt;Object.keys(yourJSONArray)&lt;/code&gt; function, which returns an array of &lt;strong&gt;Keys&lt;/strong&gt; we can loop over. Check the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys" rel="noopener noreferrer"&gt;MDN Docs&lt;/a&gt; for an in-depth explanation. Then we can perform a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach" rel="noopener noreferrer"&gt;forEach&lt;/a&gt; on the returned array (as you might have guessed), but in our case, &lt;code&gt;forEach&lt;/code&gt; (or even a &lt;code&gt;for-loop&lt;/code&gt;) is not an option as we'll be using &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some" rel="noopener noreferrer"&gt;Array.some&lt;/a&gt; and I'll explain why (because I think it's important to note), but first, take a look at the code at this stage.&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%2Fk0xa5h2kxv00tnldrmvo.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%2Fk0xa5h2kxv00tnldrmvo.png" alt="code snippet image" width="800" height="654"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you look through the code again, you'll notice that &lt;code&gt;Array.filter&lt;/code&gt; returns the data that passes our conditional check, and we're doing the checks on the &lt;code&gt;Object.keys&lt;/code&gt; but in this case, we want to &lt;strong&gt;stop/terminate&lt;/strong&gt; the loop immediately we find a matching value. What I mean is, if you type &lt;strong&gt;Dev&lt;/strong&gt; in your search field and the code is currently looping over the first data in the Object: &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%2Fzzgcvud6y3jzq0mnpz3o.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%2Fzzgcvud6y3jzq0mnpz3o.png" alt="code snippet image" width="800" height="504"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The checks we'll do here is computing if the current &lt;strong&gt;Object Value&lt;/strong&gt;  e.g &lt;code&gt;{"key": "value", "key": "value"}&lt;/code&gt; includes the search input, so if the user types &lt;strong&gt;Dev&lt;/strong&gt; in the search box, it'll match &lt;strong&gt;firstName&lt;/strong&gt; and &lt;strong&gt;emailAddress&lt;/strong&gt; and if we have any other &lt;strong&gt;value&lt;/strong&gt; with the word "&lt;strong&gt;Dev&lt;/strong&gt;" it'll match that too, but here's the thing about &lt;code&gt;Array.some&lt;/code&gt;, it'll stop looping once we find the first matching value (&lt;strong&gt;firstName&lt;/strong&gt;) and that's why we're not using &lt;strong&gt;forEach&lt;/strong&gt; because we'd have to manually write more code to make it work and &lt;em&gt;we lowkey can't stop a forEach loop&lt;/em&gt; (let me know if am wrong). &lt;/p&gt;

&lt;p&gt;Let's move forward. The code and conditions we'll write in the &lt;strong&gt;Array.some()&lt;/strong&gt; will : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Get the current value&lt;/strong&gt; of the Object, and since we don't know the keys beforehand, we'll use &lt;code&gt;data[key]&lt;/code&gt; which allows us to get the values of objects with dynamic keys (applies in our case).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Convert the value to a string&lt;/strong&gt; using &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify" rel="noopener noreferrer"&gt;JSON.stringify&lt;/a&gt;, and it'll look something like : &lt;code&gt;JSON.stringify(data[key])&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Convert the value to lower-case&lt;/strong&gt; because we've also converted the user input to lowercase &lt;code&gt;const input = event.target.value.toLowerCase();&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: "A" is not equal to "a" and that's why we're comparing both the input and the value at a lower-case level&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Trim out any trailing white spaces&lt;/strong&gt; using &lt;code&gt;.trim()&lt;/code&gt;. This will eliminate white spaces at the start or end. For example, " name" or "name " is not equal to "name" and that's why we remove any trailing whitespace. And lastly&lt;/li&gt;
&lt;li&gt;Check if it includes the &lt;strong&gt;search input value&lt;/strong&gt; using &lt;code&gt;.includes(inputValue)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;pass the result to a function/variable&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's take a look at the code to get more clear.&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%2Fz1e2riyty0rqwuds6ybu.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%2Fz1e2riyty0rqwuds6ybu.png" alt="code snippet image" width="800" height="686"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this point, this code is almost ready to ship because right now it works but we can make it better.&lt;/p&gt;

&lt;h2&gt;
  
  
  Version 2
&lt;/h2&gt;

&lt;p&gt;Why version 2? I'll explain why, if you take a look at the data again, you'll notice that we have "firstName" and "lastname", we could even have "middleName" later in the future. But currently, our code cannot search in combinations of first-and-last-name, it can only match one at a time.&lt;/p&gt;

&lt;p&gt;So... what if we could find a way to get around this? Well... there is a way, and we'll do that by including a fourth argument called "combinations" (or you could call it anything you want), so we'll have something like : &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%2F8wj1cam4dzhzf65pq1kn.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%2F8wj1cam4dzhzf65pq1kn.png" alt="code snippet image" width="800" height="184"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code I wrote at work to combine searching with "firstName" and "lastname" looks 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%2Fuploads%2Farticles%2Fwobhgf6ay3szbfog9r1y.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%2Fwobhgf6ay3szbfog9r1y.png" alt="code snippet image" width="800" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and you can see that it looks ugly, and I had to also know the keys of the object.&lt;/p&gt;

&lt;p&gt;Here, we'll allow the user or caller of our function to decide what combinations they want and in what order they want it because think about it, what if they want it in the order: "lastName"-"firstName" or "middleName"-"firstName" or "firstName"-"lastName"-"middleName"? Exactly!&lt;/p&gt;

&lt;p&gt;Our implementations will be slightly different and we'll begin by looping over the combinations passed by the caller or user of our function/algorithm.&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;.filter()&lt;/code&gt; function we'll fix in our combination logic&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%2Ffkekprrh5sqz783y04j8.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%2Ffkekprrh5sqz783y04j8.png" alt="code snippet image" width="800" height="204"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we'll loop over the combinations and add them in the order that the user of our algorithm wants.&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%2Fd13zl7nms1e6d2xi1ots.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%2Fd13zl7nms1e6d2xi1ots.png" alt="code snippet image" width="800" height="332"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our current code altogether looks 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%2Fuploads%2Farticles%2F0ias4boatd1za4l5ec3z.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%2F0ias4boatd1za4l5ec3z.png" alt="universal search algorithm code image" width="800" height="936"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Good, we made it this far, but... wait a min, something's not quite right about this code 🤔. What's wrong with it? Well... it's full of bugs at the moment, lol. And we'll fix them, but first, what are the obvious bugs am talking about? Here's a list&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bug NO.1&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;First, I said we don't have to know the key's right? But then am giving the user of our algorithm the ability to provide &lt;strong&gt;Keys&lt;/strong&gt; of the data they want to combine, and what's wrong with this? Well... what if they supplied a key that's not even existent in the JSON data? Bugs! We'll fix it.&lt;/p&gt;

&lt;p&gt;In JavaScript, we can check if a &lt;strong&gt;key&lt;/strong&gt; exists in an object by using &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty" rel="noopener noreferrer"&gt;Object.hasOwnProperty("someKey")&lt;/a&gt;. In other words, &lt;code&gt;data.hasOwnProperty("firstName")&lt;/code&gt; will return &lt;code&gt;true&lt;/code&gt; and &lt;code&gt;data.hasOwnProperty("non-existent-key")&lt;/code&gt; will return &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Our improved code should look 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%2Fuploads%2Farticles%2Fkijesbjbn2uzwxirbfrr.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%2Fkijesbjbn2uzwxirbfrr.png" alt="universal search algorithm code image" width="800" height="984"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Are we done? Nope! Am sorry but we ain't.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bug NO.2&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;let's take a moment to think about what would happen if the user never passes a value for &lt;strong&gt;objectData&lt;/strong&gt; and &lt;strong&gt;combinations&lt;/strong&gt;. There's going to be a problem because we're always trying to perform some actions on these arguments, and we can fix the code by providing a default value.&lt;/p&gt;

&lt;p&gt;So if we forget to pass a value for these arguments, we'll still be fine, but how do we do that? We do that by providing an empty array as a default value: &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%2Fpg5s8seh592fk8q53co4.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%2Fpg5s8seh592fk8q53co4.png" alt="code snippet image" width="800" height="403"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Great! We made it even further, are we done? Yea, we are, but... Maybe we ain't 😎.&lt;/p&gt;

&lt;p&gt;There's one more thing I'd like to point out about this algorithm. In JSON data, sometimes, values can come back as &lt;strong&gt;null&lt;/strong&gt;, &lt;strong&gt;undefined&lt;/strong&gt;, &lt;strong&gt;true&lt;/strong&gt; or &lt;strong&gt;false&lt;/strong&gt;, you might have seen this a lot if you've consumed some backend data in the past or current.&lt;/p&gt;

&lt;p&gt;So, if a user search the word &lt;strong&gt;null&lt;/strong&gt;, &lt;strong&gt;undefined&lt;/strong&gt;, &lt;strong&gt;true&lt;/strong&gt; or &lt;strong&gt;false&lt;/strong&gt; every object/data that has a the value &lt;strong&gt;null&lt;/strong&gt; or &lt;strong&gt;undefined&lt;/strong&gt; etc will show up.&lt;/p&gt;

&lt;p&gt;At my workplace, I allowed the search of &lt;strong&gt;false&lt;/strong&gt; and &lt;strong&gt;true&lt;/strong&gt; but not &lt;strong&gt;null&lt;/strong&gt; or &lt;strong&gt;undefined&lt;/strong&gt; because the API I was working with mostly had an &lt;code&gt;{isActive: true}&lt;/code&gt; or &lt;code&gt;{isActive: false}&lt;/code&gt; key-values, which allows me to search users that are currently activated/deactivated.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I just type "true" or "false" and that does the magic&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Version 3
&lt;/h2&gt;

&lt;p&gt;My current code at the time of writing this blog is: &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%2F83lg6rw560bnhf8lao79.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%2F83lg6rw560bnhf8lao79.png" alt="universal search algorithm code image" width="800" height="1056"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For someone that might want to use the code in a search input will do something like: &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%2Fey8vb60q31kzdm9c7w83.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%2Fey8vb60q31kzdm9c7w83.png" alt="code snippet image" width="800" height="538"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And they won't have to worry about what changes about the student data in the future.&lt;br&gt;
Plus even if you're consuming an API with random JSON data (Never seen this happen though) like say, data of persons, and robots, and cat names etc... you get the gist?&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%2Fzrvk9ace2lcpjknl2d7u.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%2Fzrvk9ace2lcpjknl2d7u.png" alt="random JSON data image" width="800" height="978"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;you won't have to worry, the search still stands.&lt;/p&gt;

&lt;p&gt;The only new thing in my previous snippet (Version 3) is the &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; (and) &lt;code&gt;||&lt;/code&gt; operator and what &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; simply means is, execute the code on the right if the code to the left (before the &amp;amp;&amp;amp;) is true.&lt;br&gt;
&lt;code&gt;||&lt;/code&gt; simply means, do what's on the left if the condition is true &lt;strong&gt;Or&lt;/strong&gt; do what's on the right if what's on the left is false. I don't feel I should talk much about these operators, if you're not familiar with it, you can look them up, it's no big deal but... it really does save you a lot of typing.&lt;/p&gt;

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

&lt;p&gt;There's no denying the fact that every code can be made better, and if you ever feel you want to improve on the code, or would like to create a say... some React or JS library specifically for "searching" that does more than the 1-thing we learnt here. Feel free to &lt;a href="https://github.com/Emmaccen/search-algorithm" rel="noopener noreferrer"&gt;Clone OR Contribute&lt;/a&gt; to the GitHub repo. &lt;/p&gt;

&lt;p&gt;If you do make a library that gives people that super-power, I'd like to feature you on this blog.&lt;/p&gt;

&lt;p&gt;Cheers 🥂 and thanks for reading 😎.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>How To Know If An Element Is Visible In Viewport.</title>
      <dc:creator>Lucius Emmanuel Emmaccen</dc:creator>
      <pubDate>Tue, 16 Feb 2021 21:57:54 +0000</pubDate>
      <link>https://forem.com/emmaccen/how-to-know-if-an-element-is-visible-in-viewport-c45</link>
      <guid>https://forem.com/emmaccen/how-to-know-if-an-element-is-visible-in-viewport-c45</guid>
      <description>&lt;p&gt;In this article, we're going to learn how to know/detect if an element is visible in the browser's viewport.&lt;/p&gt;

&lt;p&gt;Before we start, I'd like to clarify what a &lt;strong&gt;viewport&lt;/strong&gt; is, relative to our browser engine.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A &lt;strong&gt;Viewport&lt;/strong&gt; is the area (ordinarily rectangular) of our computer graphics (Screen) that is currently being viewed. In other words, it's the area of your computer screen that is currently visible to you (physically). &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Check the &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Viewport" rel="noopener noreferrer"&gt;MDN docs&lt;/a&gt; for an in-depth explanation, if mine is not clear enough.&lt;/p&gt;

&lt;p&gt;Now, why would this be useful to you? Why would you want to know if an element is currently visible in the browser's viewport? &lt;/p&gt;

&lt;p&gt;You might find it useful in situations like :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want to show an overlay asking your customers to subscribe to your newsletter when they scroll to the footer of your website (e.g If its a blog site, this might indicate they just finished reading and you want them to subscribe)&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You want to increase counter values that read when an element becomes visible to users&lt;br&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%2F7lenbal8ef1suc7ta8ia.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%2F7lenbal8ef1suc7ta8ia.png" alt="counter image by emmaccen" width="800" height="204"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Trigger animations when e.g "section A" on your webpage comes to view, fadeIn animations, etc&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As a progress bar at the top of the screen that tells you how much content is left to view on a page (You might have seen it used on blog sites or any site that involves reading through long text content).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Do some Javascript magic, like play a video, show some short popup ads, toggle a help "BOT" 🤖 etc.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Am sure by now, you're seeing useful things that can be done with this in your mind too and at the end of this article, you'll get even more insight and ideas. So... let's get to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Walkthrough
&lt;/h2&gt;

&lt;p&gt;We can achieve this by using the &lt;strong&gt;getBoundingClientRect()&lt;/strong&gt; function on an element which returns a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/DOMRect" rel="noopener noreferrer"&gt;DOMRect&lt;/a&gt; object providing information about the size of an element and its position relative to the viewport.&lt;br&gt;
so we have something like &lt;code&gt;yourElement.getBoundingClientRect()&lt;/code&gt; or &lt;code&gt;elementInfo = yourElement.getBoundingClientRect()&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A &lt;strong&gt;DOMRect&lt;/strong&gt; describes the size and position of a rectangle.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The &lt;strong&gt;DOMRect&lt;/strong&gt; Object returned from &lt;code&gt;getBoundingClientRect()&lt;/code&gt; are key-values &lt;em&gt;(in pixels)&lt;/em&gt; that can be used to compute our goal and is the smallest rectangle which contains the entire element, including its padding and border-width.&lt;br&gt;
The Object returned looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; {
      x: 20,
      y: 5.5,
      width: 882,
      height: 198.890625,
      top: 5.5,
      right: 902,
      bottom: 204.390625,
      left: 20,
    };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's go through the explanation in more detail. I've separated the visual presentation in order to avoid confusion.&lt;/p&gt;

&lt;h2&gt;
  
  
  DOMRect Key-Values (in pixels)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;X and Left&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Represents the distance from the &lt;strong&gt;left&lt;/strong&gt; between the viewport (browser screen) and the &lt;strong&gt;top-left&lt;/strong&gt; area of the DOMRect (yourElement).&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%2F6ars41gsgehj3rzicww0.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%2F6ars41gsgehj3rzicww0.png" alt="getBoundingClient-X and Left" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Y and Top&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Represents the distance from the &lt;strong&gt;top&lt;/strong&gt; of the viewport (browser screen) and the &lt;strong&gt;top&lt;/strong&gt; of the DOMRect (yourElement).&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%2Fjc1rw8m1yaw1szhjsytn.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%2Fjc1rw8m1yaw1szhjsytn.png" alt="getBoundingClient-Y and Top" width="592" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Width&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Represents the width of the DOMRect&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Height&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Represents the height of the DOMRect&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The width and height properties of the &lt;strong&gt;DOMRect object&lt;/strong&gt; returned by the method include the &lt;strong&gt;padding&lt;/strong&gt; and &lt;strong&gt;border-width&lt;/strong&gt;, not only the content &lt;strong&gt;width/height&lt;/strong&gt;. In the standard box model, this would be equal to the &lt;strong&gt;width&lt;/strong&gt; or &lt;strong&gt;height&lt;/strong&gt; property of the element + padding + border-width. But if &lt;strong&gt;box-sizing: border-box&lt;/strong&gt; is set for the element this would be directly equal to its width or height.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can check the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing" rel="noopener noreferrer"&gt;MDN Docs&lt;/a&gt; on box-sizing.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bottom&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Represents the distance from the &lt;strong&gt;top&lt;/strong&gt; of the viewport (browser screen) and the &lt;strong&gt;bottom&lt;/strong&gt; of the DOMRect (yourElement).&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%2Fjf58kd3ye9bayedskpmr.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%2Fjf58kd3ye9bayedskpmr.png" alt="getBoundingClient-bottom" width="593" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Right&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Represents the distance from the &lt;strong&gt;left&lt;/strong&gt; of the viewport (browser screen) and the &lt;strong&gt;right&lt;/strong&gt; (bottom-right) of the DOMRect (yourElement). It has the same value as &lt;strong&gt;x + width&lt;/strong&gt;, or &lt;strong&gt;x&lt;/strong&gt; if &lt;strong&gt;width&lt;/strong&gt; is negative.&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%2F275u0uqwgsiji2qj29a2.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%2F275u0uqwgsiji2qj29a2.png" alt="getBoundingClient-right" width="635" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Full Diagram
&lt;/h3&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%2Fm4iodvr8ofgu705qzyxg.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%2Fm4iodvr8ofgu705qzyxg.png" alt="getBoundingClient value/angles" width="684" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you're wondering where I got all these diagrams from, I designed them in Figma&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Some Useful Tips
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Calculating Partial Visibility &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's say we want to know if an element is partially visible in the viewport, and we've assigned an evenListner that triggers each time we scroll through the page e.g something like :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;window.addEventListener("scroll", () =&amp;gt; {
        //Some javascript magic here...
      });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we can achieve this by simply subtracting the &lt;strong&gt;top/y&lt;/strong&gt; value from the viewport height (screen) and also doing a check to make sure the &lt;strong&gt;bottom&lt;/strong&gt; value is greater than &lt;strong&gt;0&lt;/strong&gt;.&lt;br&gt;
The viewport height can be gotten using &lt;code&gt;window.innerHeight&lt;/code&gt; or &lt;code&gt;document.documentElement.clientHeight&lt;/code&gt; but usually, it's safer to combine them due to the browser compatibility of &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/innerHeight#browser_compatibility" rel="noopener noreferrer"&gt;innerHeight&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/documentElement#browser_compatibility" rel="noopener noreferrer"&gt;documentElement&lt;/a&gt;&lt;br&gt;
So you might use something like :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const height = 
window.innerHeight || document.documentElement.clientHeight;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So partial visibility would pass for the condition :&lt;br&gt;
&lt;strong&gt;viewportHeight - top&lt;/strong&gt; is greater than &lt;strong&gt;0&lt;/strong&gt; and &lt;strong&gt;bottom&lt;/strong&gt; is also greater than &lt;strong&gt;0&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const viewportHeight =
            window.innerHeight || document.documentElement.clientHeight;
// condition 
(viewportHeight - top &amp;gt; 0 &amp;amp;&amp;amp; bottom &amp;gt; 0)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;If this is getting a little rough, it might be helpful to use the diagram and a pen and paper (I definitely did).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Calculating Full Visibility&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, this part is almost as easy. The conditions required for full visibility are: &lt;br&gt;
&lt;strong&gt;bottom&lt;/strong&gt; is greater than &lt;strong&gt;0&lt;/strong&gt; and &lt;strong&gt;bottom&lt;/strong&gt; is less than or equal to &lt;strong&gt;viewportHeight&lt;/strong&gt; and &lt;strong&gt;top&lt;/strong&gt; is greater than or equal to &lt;strong&gt;0&lt;/strong&gt;&lt;br&gt;
So it looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bottom &amp;gt; 0 &amp;amp;&amp;amp; bottom &amp;lt;= viewportHeight &amp;amp;&amp;amp; top &amp;gt;= 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, I think it would be nice to have us view a &lt;a href="https://emmaccen.github.io/isElementInView/" rel="noopener noreferrer"&gt;live website&lt;/a&gt; that computes the values of &lt;code&gt;getBoundingClientRect()&lt;/code&gt; in real-time.&lt;/p&gt;

&lt;p&gt;It'll also help you understand how all the conditions/checks we did earlier pass the visibility test. Just scroll through the page and watch the magic.&lt;br&gt;
It's a super simple webpage with nicely cooked and understandable code 😎.&lt;br&gt;
Feel free to clone/fork the &lt;a href="https://github.com/Emmaccen/isElementInView" rel="noopener noreferrer"&gt;gitHub repo&lt;/a&gt; if you want to get familiar with the code.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Now, it's evident that everything we've done so far accounts for the vertically scrollable element (scroll-top-bottom &amp;amp; scroll-bottom-top), but what about horizontally scrollable elements (scroll-left-right &amp;amp; scroll-right-left)?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We'll have to pair the condition with the browser width using :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(window.innerWidth || document.documentElement.clientWidth) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So we'll have something that looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(right &amp;gt; 0 &amp;amp;&amp;amp; right &amp;lt;= width)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/DOMRect#browser_compatibility" rel="noopener noreferrer"&gt;Browser Compatibility&lt;/a&gt;
&lt;/h2&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%2Flhbaepxny9rbraswiu76.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%2Flhbaepxny9rbraswiu76.png" alt="Browser Compatibility of getBoundingClientRect()" width="800" height="583"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it and we've come to the end of this tutorial. I hope you found it useful. If you'd like to revisit/keep this post for reference, please, do bookmark it and leave a like/unicorn 🙂. Let me know what you think in the comment/discussion section below (improvements, your thoughts, etc). Cheers 🥂.&lt;/p&gt;

&lt;h3&gt;
  
  
  Update
&lt;/h3&gt;

&lt;p&gt;While &lt;code&gt;getBoundingClientRect()&lt;/code&gt; can help you achieve a lot of things, it's important to know the cost of using it as it fires very rapidly if used in an event listener like 'scroll listener'.&lt;/p&gt;

&lt;p&gt;I'd recommend pairing it with a &lt;code&gt;debounce()&lt;/code&gt; function, however, in most cases, the &lt;code&gt;IntersectionObserver&lt;/code&gt; API does this quite efficiently. It observes changes in the visibility of an element relative to its parent or the top-level document's viewport. It can be used to trigger an action when an element becomes visible or hidden.&lt;/p&gt;

&lt;p&gt;So, while &lt;code&gt;getBoundingClientRect()&lt;/code&gt; can be used for positioning and sizing, &lt;code&gt;IntersectionObserver&lt;/code&gt; is used for observing the visibility of an element. They serve different purposes and cannot be compared in terms of what one can do that the other can't. Read more about &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver" rel="noopener noreferrer"&gt;IntersectionObserver&lt;/a&gt; on MDN&lt;/p&gt;

</description>
      <category>html</category>
      <category>javascript</category>
      <category>css</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How To Create A "Glassmorphic" Template In Pure HTML &amp; CSS.</title>
      <dc:creator>Lucius Emmanuel Emmaccen</dc:creator>
      <pubDate>Mon, 21 Dec 2020 17:02:32 +0000</pubDate>
      <link>https://forem.com/emmaccen/how-to-create-a-glassmorphic-template-in-pure-html-css-3jo4</link>
      <guid>https://forem.com/emmaccen/how-to-create-a-glassmorphic-template-in-pure-html-css-3jo4</guid>
      <description>&lt;h1&gt;
  
  
  What Is Glassmorphism?
&lt;/h1&gt;

&lt;p&gt;If you're hearing the term &lt;strong&gt;"Glassmorpism"&lt;/strong&gt; for the first time, well... It only just got my attention a few hours before this post so, &lt;strong&gt;What is glassmorphism?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Glassmorphism is a new trend which is getting more traction on websites like &lt;a href="https://dribbble.com/" rel="noopener noreferrer"&gt;Dribble&lt;/a&gt;, &lt;a href="https://www.behance.net/" rel="noopener noreferrer"&gt;Behance&lt;/a&gt; etc and I've seen a couple of awesome designs made using this trendy UI.&lt;/p&gt;

&lt;p&gt;Here's an example by &lt;a href="https://dribbble.com/rish_designs" rel="noopener noreferrer"&gt;Rishabh Saxena&lt;/a&gt;&lt;br&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%2Fypnom22fdtrzohl2ga5x.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%2Fypnom22fdtrzohl2ga5x.png" alt="Alt Text" width="760" height="567"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It is important to note that as of the time of writing this blog, glassmorphism is not widely used on the web yet. So we're going to be exploring the power of our creativity.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  Attributes/Characteristics
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Translucency (frosted-glass)&lt;/li&gt;
&lt;li&gt;Detailed Colors (becomes cloud-like)&lt;/li&gt;
&lt;li&gt;Shadows&lt;/li&gt;
&lt;li&gt;Everything else...&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  prerequisites
&lt;/h2&gt;

&lt;p&gt;To follow up with this tutorial, Since it might require we copy-paste some code to test things out, we'll:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create an &lt;strong&gt;HTML&lt;/strong&gt; and &lt;strong&gt;CSS&lt;/strong&gt; file ( &lt;em&gt;index.html&lt;/em&gt; and &lt;em&gt;index.css&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;Link to the full working code on &lt;a href="https://github.com/Emmaccen/glass-morphism" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; if you ever get stuck.&lt;/li&gt;
&lt;li&gt;Link to &lt;a href="https://emmaccen.github.io/glass-morphism/" rel="noopener noreferrer"&gt;Live website&lt;/a&gt; for reference.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The main &lt;strong&gt;CSS property&lt;/strong&gt; to watch out for is the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/backdrop-filter" rel="noopener noreferrer"&gt;backdrop-filter&lt;/a&gt;. &lt;em&gt;Feel free to get documentations to any CSS or HTML properties on &lt;a href="https://developer.mozilla.org/" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;&lt;/em&gt;. The &lt;code&gt;backdrop-filter : blur(_px)&lt;/code&gt; is what gives it the &lt;strong&gt;frosty-like glass effect&lt;/strong&gt;.&lt;br&gt;
The backdrop-filter does more than just blur a background. Again, check the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/backdrop-filter" rel="noopener noreferrer"&gt;MDN&lt;/a&gt; for the full documentation.&lt;/p&gt;

&lt;p&gt;In order for this to work effectively, the element has to be partly translucent (mimicking a glass-effect).&lt;/p&gt;

&lt;p&gt;Now, in our &lt;strong&gt;index.html&lt;/strong&gt; let's paste the code block below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;link rel="stylesheet" href="./index.css" /&amp;gt;
    &amp;lt;meta charset="UTF-8" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&amp;gt;
    &amp;lt;meta name="description" content="Glassmorphism" /&amp;gt;
    &amp;lt;meta
      name="keywords"
      content="glassmorphism,UIUX"
    /&amp;gt;
    &amp;lt;meta name="author" content="emmaccen" /&amp;gt;
    &amp;lt;title&amp;gt;Glass Morphism&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div class="landingContainer"&amp;gt;
      &amp;lt;div class="centered"&amp;gt;
        &amp;lt;h1 class="title"&amp;gt;Changing The World&amp;lt;/h1&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div class="glassContainer"&amp;gt;
        &amp;lt;div class="cover"&amp;gt;&amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;I won't be doing any explanation on the &lt;em&gt;HTML&lt;/em&gt; code snippet since its pretty basic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;index.css&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body {
  margin: 0;
  padding: 0;
}

* {
  box-sizing: border-box;
}

.landingContainer {
  /* span the entire desktop height : height: 100vh;*/
  height: 100vh;
  font-family: helvetica;
  /* set a gradient background with 3 colours https://coolors.co/ */
  background: linear-gradient(
    to right,
    rgba(32, 191, 85),
    rgba(32, 164, 243),
    rgba(11, 79, 108)
  );
}

.centered {
  /* center content */
  display: flex;
  justify-content: center;
  align-items: center;
  /* so it takes up its containers height (landingContainer)*/
  height: inherit;
}

.title {
  color: whitesmoke;
  /* cover the entire page width : font-size: 10vw;*/
  font-size: 10vw;
  text-align: center;
}

/* The real deal  starts here*/
.glassContainer {
  position: absolute;
  /* center content */
  display: flex;
  justify-content: center;
  align-items: center;
  top: 0;
  width: 100%;
  height: 100%;
}
.cover {
  transition: 0.5s all ease;
  height: 70%;
  width: 70%;
  background-color: rgba(255, 255, 255, 0.25);
  /* box-shadow: none|h-offset v-offset blur spread color |inset|initial|inherit; */
  box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
  /* For the fog-like glass effect */
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-radius: 10px;
}

/* responsiveness */

@media (max-width: 700px) {
  .cover {
    height: 30%;
  }
}

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

&lt;/div&gt;



&lt;p&gt;Now for the &lt;strong&gt;CSS&lt;/strong&gt; code above. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I got my colour combo from &lt;a href="https://coolors.co/" rel="noopener noreferrer"&gt;Coolors.co&lt;/a&gt; so, you can mix and match to replace mine.&lt;/li&gt;
&lt;li&gt;I've included comments in the code, so I won't have to explain here again. You can Check &lt;a href="https://developer.mozilla.org/" rel="noopener noreferrer"&gt;MDN&lt;/a&gt; for full documentation if any &lt;strong&gt;CSS&lt;/strong&gt; property isn't clear.
The result should look something like this:&lt;/li&gt;
&lt;/ul&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%2Fq4t0u0gefjb5jfjlfhj2.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%2Fq4t0u0gefjb5jfjlfhj2.png" alt="emmaccen, Oriola Emmanuel, glassmorphism" width="800" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So that's it. This tutorial is pretty basic and I wanted it to be something we can go through in 5-10Mins. I hope this wasn't a waste of your precious time.&lt;/p&gt;

&lt;h3&gt;
  
  
  My Thoughts
&lt;/h3&gt;

&lt;p&gt;Am really looking forward to 2021 and the awesome real-world application of people's creativity with &lt;strong&gt;Glassmorphism&lt;/strong&gt;. I have a feeling it'll trend for quite a while if done right.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pro Tips
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;You can save a lot of time by checking out &lt;a href="https://glassmorphism.com/" rel="noopener noreferrer"&gt;glassmorphism.com&lt;/a&gt;. It's a website that helps you generate glassmorpic &lt;strong&gt;CSS&lt;/strong&gt; styles on the fly. Also, you can modify as you wish (it comes with visual representations too)&lt;/li&gt;
&lt;li&gt;Glassmorphism is not limited to the web alone if you build/design native apps, you might want to implement these designs too.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;I'm always happy when I get feedback about my blogs, so don't hesitate to play with the comment/discussion area, like and bookmark this blog if you love it or share with others.&lt;/p&gt;

&lt;p&gt;You can follow me on &lt;a href="https://twitter.com/emmaccen" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;, or send me a sample of what you've created.&lt;br&gt;
You can also fork/clone the repo on &lt;a href="https://github.com/Emmaccen/glass-morphism" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. I have two branches created. The &lt;a href="https://github.com/Emmaccen/glass-morphism" rel="noopener noreferrer"&gt;Master/Main&lt;/a&gt; branch is what we practised in this tutorial. The &lt;a href="https://github.com/Emmaccen/glass-morphism/tree/glass-morphism-v2" rel="noopener noreferrer"&gt;Second branch&lt;/a&gt; is what we have as the cover image of the article.&lt;/p&gt;

&lt;p&gt;If you read up to this point, &lt;strong&gt;thank you&lt;/strong&gt; I appreciate your will to learn and am happy to have you reading this.&lt;br&gt;
Check out other &lt;a href="https://dribbble.com/tags/glassmorphism" rel="noopener noreferrer"&gt;Glassmorphic designs&lt;/a&gt; on &lt;a href="https://dribbble.com/" rel="noopener noreferrer"&gt;dribble.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;More Design Inspiration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Design by &lt;a href="https://dribbble.com/AkashRajDahal" rel="noopener noreferrer"&gt;Aakash Raj Dahal&lt;/a&gt;&lt;br&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%2F4cjdpc4vfgnmpui942ju.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%2F4cjdpc4vfgnmpui942ju.png" alt="Alt Text" width="757" height="564"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Mobile design by &lt;a href="https://dribbble.com/Brightlab" rel="noopener noreferrer"&gt;Brightlab&lt;/a&gt;&lt;br&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%2Fud231ui5aukay8kqes0g.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%2Fud231ui5aukay8kqes0g.png" alt="Alt Text" width="739" height="565"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>ux</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How To Integrate A Rich Text Editor (WYSIWYG) In Your React.Js Project.</title>
      <dc:creator>Lucius Emmanuel Emmaccen</dc:creator>
      <pubDate>Fri, 10 Jul 2020 01:41:41 +0000</pubDate>
      <link>https://forem.com/emmaccen/how-to-integrate-a-rich-text-editor-wysiwyg-in-your-react-js-project-1i4o</link>
      <guid>https://forem.com/emmaccen/how-to-integrate-a-rich-text-editor-wysiwyg-in-your-react-js-project-1i4o</guid>
      <description>&lt;p&gt;In this article, we're going to learn how to "Integrate A Rich Text Editor" in your react.Js project using &lt;a href="https://www.tiny.cloud/docs/integrations/react/" rel="noopener noreferrer"&gt;TinyMCE&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Before we begin, let's do a quick summary of what a "Rich Text Editor" also commonly known as (WYSIWYG) what-you-see-is-what-you-get means, &lt;em&gt;just in case you found this article out of curiosity&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In simple terms: A Rich Text Editor is an interface for editing rich text within browsers, which could also include images, links, audio and videos in a what-you-see-is-what-you-get fashion. These editors aim to reduce the effort for users trying to express their formatting directly as valid HTML markup.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;These editors (There're quite a number of them) can particularly be useful if you're creating your very own blog website 😎.&lt;br&gt;
Now that we have a clear understanding of what a Rich Text Editor is, let's get right into it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://nodejs.org/en/download/" rel="noopener noreferrer"&gt;Node.js (and npm)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Access to tinymce.min.js on either : &lt;a href="https://www.tiny.cloud/docs/cloud-deployment-guide/editor-and-features/" rel="noopener noreferrer"&gt;Tinycloud&lt;/a&gt; or TinyMCE Self-hosted (what we'll be using) See &lt;a href="https://www.tiny.cloud/docs/general-configuration-guide/advanced-install/" rel="noopener noreferrer"&gt;Installing TinyMCE&lt;/a&gt; for details on self-hosting TinyMCE.&lt;/li&gt;
&lt;li&gt;Basic &lt;a href="https://reactjs.org/docs/getting-started.html" rel="noopener noreferrer"&gt;React&lt;/a&gt; Knowledge. Don't worry if you're a beginner, you can do this !.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Procedures | Processes
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;If you don't already have React installed on your machine, open your command line or command prompt and install the &lt;a href="https://github.com/facebook/create-react-app" rel="noopener noreferrer"&gt;Create React App package&lt;/a&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ npm install -g create-react-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create a new React project and &lt;em&gt;"name it anything you want"&lt;/em&gt;. I named mine &lt;a href="https://github.com/Emmaccen/WYSIWYG" rel="noopener noreferrer"&gt;WYSIWYG&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ create-react-app WYSIWYG
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Change into the newly-created directory.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ cd WYSIWYG
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Install the TinyMCE-react package and save it to your &lt;strong&gt;package.json&lt;/strong&gt; with --save.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ npm install --save @tinymce/tinymce-react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Open the project using any editor of choice. I use &lt;a href="https://code.visualstudio.com/download" rel="noopener noreferrer"&gt;VScode&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&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%2Fqhg3imav1urae2vz64cf.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%2Fqhg3imav1urae2vz64cf.png" alt="Code Image" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Inside the Public folder, let's open the &lt;strong&gt;Index.html&lt;/strong&gt; file and paste this code at the head section ( some paste at the bottom... your choice 😎)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="/path/to/tinymce.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have a project all set up for our Rich Text Editor, let's start with the &lt;em&gt;INTEGRATION&lt;/em&gt; so we can all be happy.&lt;/p&gt;

&lt;h3&gt;
  
  
  Navigate to your &lt;em&gt;"src"&lt;/em&gt; directory and :
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create a "components" folder inside the &lt;em&gt;"src"&lt;/em&gt; directory&lt;/li&gt;
&lt;li&gt;Inside the "components" folder, create a "RichText.js" file.&lt;/li&gt;
&lt;/ul&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%2F9k3oxcwwp2rqluosclgh.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%2F9k3oxcwwp2rqluosclgh.png" alt="project hierarchy" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;After you've done that, paste the code below into your RichText.js file
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import React from 'react';
import { Editor } from '@tinymce/tinymce-react';

class RichText extends React.Component {
  handleEditorChange = (e) =&amp;gt; {
    console.log(
      'Content was updated:',
      e.target.getContent()
    );
  }

  render() {
    return (
      &amp;lt;Editor
        initialValue="&amp;lt;p&amp;gt;Wow ! ... It Works !!!&amp;lt;/p&amp;gt;"
        init={{
          height: 500,
          menubar: false,
          plugins: [
            'advlist autolink lists link image',
            'charmap print preview anchor help',
            'searchreplace visualblocks code',
            'insertdatetime media table paste wordcount'
          ],
          toolbar:
            'undo redo | formatselect | bold italic | \
            alignleft aligncenter alignright | \
            bullist numlist outdent indent | help'
        }}
        onChange={this.handleEditorChange}
      /&amp;gt;
    );
  }
}

export default RichText;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pasting the above code will create a react component containing the &lt;strong&gt;TinyMCE editor&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now let's navigate to our App.js folder and import the RichText component so we can have it rendered in the browser.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import RichText from './component/RichText'
function App() {
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;RichText /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To run the app lets open the terminal and run this code (make sure you've checked into your project directory in the terminal. e.g cd pathToProject ) :
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  $ npm run start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you should see the application up and running in the browser (usually localhost:3000)&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%2Fh1wlyurf49qe6q1l7kjh.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%2Fh1wlyurf49qe6q1l7kjh.png" alt="Rich Text Editor" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;That was easy ? wasn't it ??&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But we're not done just yet !. Did you notice a warning that pops up in the editor when you try to type anything ( Warning: This domain is not registered with Tiny Cloud ) ??. That's because we've not created an &lt;strong&gt;API key&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Don't worry&lt;/strong&gt; We've completed the &lt;strong&gt;easy&lt;/strong&gt; part, now for the &lt;strong&gt;easier&lt;/strong&gt; part, all that's left is to get rid of that scary warning, but... &lt;em&gt;How do we do that ?&lt;/em&gt; well... It's easy 😎.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's Follow These Steps
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;To get an &lt;strong&gt;API Key&lt;/strong&gt; Let's go to the &lt;a href="https://www.tiny.cloud/" rel="noopener noreferrer"&gt;tinycloud&lt;/a&gt; page and create an account.&lt;/li&gt;
&lt;li&gt;fill in the basic Infos they'll ask (Nothing Personal)&lt;/li&gt;
&lt;li&gt;They'll send a confirmation email, so we'd have to open our mail and confirm by clicking the link provide (this redirects to a page where we'll do basic setups)&lt;/li&gt;
&lt;li&gt;On the redirect page, we'll add our domain (if we have one e.g ...mycooldomain.com), localhost is by default and we don't have to explicitly include that.&lt;/li&gt;
&lt;li&gt;Next, we scroll to the bottom of the page and click on &lt;em&gt;Continue to dashboard&lt;/em&gt;. This is where we'll see our &lt;strong&gt;API KEY&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Copy the &lt;strong&gt;API KEY&lt;/strong&gt; and navigate to the RichText.js file. Inside the &lt;code&gt;&amp;lt;Editor /&amp;gt;&lt;/code&gt; component, include the &lt;em&gt;apiKey&lt;/em&gt; option in the editor element and paste your TinyMCE &lt;strong&gt;API key&lt;/strong&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Editor
  apiKey="your-api-key-goes-here"
  init={{ /* your other settings */ }}
/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the project and watch the magic happen. Voila! We don't have errors anymore !!!.&lt;/p&gt;

&lt;p&gt;Check out the working code on my &lt;a href="https://github.com/Emmaccen/WYSIWYG" rel="noopener noreferrer"&gt;Git repository&lt;/a&gt;. Please feel free to fork the project.&lt;br&gt;
There's a lot that can be done with TinyMCE, to explore some more goodies there is, go check out the &lt;a href="https://www.tiny.cloud/docs/integrations/react/" rel="noopener noreferrer"&gt;TinyMCE docs&lt;/a&gt;. Also, it can be integrated with other technologies too, such as &lt;strong&gt;Angular&lt;/strong&gt;, &lt;strong&gt;Vue&lt;/strong&gt; etc.&lt;br&gt;
TinyMCE can be customised to include a lot &lt;a href="https://www.tiny.cloud/docs/plugins/" rel="noopener noreferrer"&gt;more plugins&lt;/a&gt; and &lt;a href="https://www.tiny.cloud/docs/integrations/react/#eventbinding" rel="noopener noreferrer"&gt;Event bindings&lt;/a&gt; than we currently have in our project.&lt;/p&gt;

&lt;h2&gt;
  
  
  PRO TIPS
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;If you wish to add some spacing (margins or padding) outside the &lt;code&gt;&amp;lt;Editor /&amp;gt;&lt;/code&gt;, just wrap a &lt;code&gt;&amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt; around it and style accordingly.&lt;/li&gt;
&lt;li&gt;To make this project more fun, create a git Repo and push all you've learnt in this post.&lt;/li&gt;
&lt;li&gt;Teach someone else 😎&lt;/li&gt;
&lt;li&gt;Don't forget to give a &lt;em&gt;thumbs Up&lt;/em&gt; and leave comments (please, I love feedbacks)&lt;/li&gt;
&lt;li&gt;last but not least, &lt;strong&gt;This is my first ever blog post&lt;/strong&gt; so, don't hesitate to point out errors to help me improve.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks to everyone that took the time out to read this blog and once again, be sure to check out the working code on my &lt;a href="https://github.com/Emmaccen/WYSIWYG" rel="noopener noreferrer"&gt;Git repository&lt;/a&gt;, if you so wish.&lt;br&gt;
Please, feel free to fork and star the project. I wish you all the best.&lt;/p&gt;

</description>
      <category>react</category>
      <category>wysiwyg</category>
      <category>blogging</category>
      <category>tinymce</category>
    </item>
  </channel>
</rss>
