<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Emmanuel Akinyemi</title>
    <description>The latest articles on DEV Community by Emmanuel Akinyemi (@akinolu52).</description>
    <link>https://dev.to/akinolu52</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%2F761484%2F13084255-0d9c-4e14-989a-a3d53343f887.jpeg</url>
      <title>DEV Community: Emmanuel Akinyemi</title>
      <link>https://dev.to/akinolu52</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akinolu52"/>
    <language>en</language>
    <item>
      <title>How to create a simple progress bar in react native</title>
      <dc:creator>Emmanuel Akinyemi</dc:creator>
      <pubDate>Sat, 23 Jul 2022 21:55:37 +0000</pubDate>
      <link>https://dev.to/akinolu52/how-to-create-a-simple-progress-bar-in-react-native-3foe</link>
      <guid>https://dev.to/akinolu52/how-to-create-a-simple-progress-bar-in-react-native-3foe</guid>
      <description>&lt;p&gt;Hello everyone &lt;/p&gt;

&lt;p&gt;Recently I was tasked with creating some components for a mobile app and one of the component is a progress bar, after looking at the designed component i decided to come up with a simple implementation instead of installing package to handle the progress bar for me.&lt;/p&gt;

&lt;p&gt;you can skip the step by step implementation by checking out the  &lt;a href="https://snack.expo.dev/@akinolu52/63d860" rel="noopener noreferrer"&gt;sample implementation on expo&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;This is a picture of what I will be implementing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkfmqjgwv83yevdnqcvut.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkfmqjgwv83yevdnqcvut.png" alt="Screenshot 2021-09-18 at 10.54.56.png" width="660" height="268"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Building the progress bar&lt;/p&gt;

&lt;p&gt;Tech stack: React-native &amp;amp; Styled-components&lt;/p&gt;

&lt;p&gt;Looking at the image above the progress bar contains 2 element &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;the outer container &lt;/li&gt;
&lt;li&gt;a line to indicate the progress&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;implementing the progress-bar component&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ProgressBar = (props) =&amp;gt;{
  const { 
       progress, 
       height = 8, 
       outerBackgroundColor, 
       innerBackgroundColor, 
       padded = true
  } = props;

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

&lt;/div&gt;



&lt;p&gt;Implementing the progress container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import styled from 'styled-components/native';

&amp;lt;Container
    height={height}
    padded={padded}
    outerBackgroundColor={outerBackgroundColor}
   &amp;gt;
 {/* the line indicator goes here */}
&amp;lt;/Container&amp;gt;

const Container = styled.View`
  width: "100%";
  borderRadius: 16;
  alignItems: flex-start;
  justifyContent: center;
  height: ${props =&amp;gt; props.height};
  backgroundColor: ${props =&amp;gt; props.outerBackgroundColor};
  paddingHorizontal: ${props =&amp;gt; props.padded ? 3 : 0};
`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;The outer container is a line with a configuarable height, this will act as a container for the inner line which is the actual progress; the props passed to the container includes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;height: this is the height of the progress bar&lt;/li&gt;
&lt;li&gt;padded: a props to show if the progress bar should be padded or not&lt;/li&gt;
&lt;li&gt;outerBackgroundColor: this is the color of the progressbar container.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Implementing the progress content&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import styled from 'styled-components/native';

&amp;lt;Content 
      height={height}
      padded={padded}
      progress={progress} 
      innerBackgroundColor={innerBackgroundColor}
/&amp;gt;

const Content = styled.View`
  borderRadius: 16;
  height: ${props =&amp;gt; props.padded ? (props.height / 2) : props.height};
  backgroundColor: ${props =&amp;gt; props.innerBackgroundColor};
  width: ${props =&amp;gt; props.progress}%;
`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;The inner content is the progress indicator that takes in several props&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;height: this is the height of the progress indicator, (if the progress is padded then the displayed height is half of the height passed into the content)&lt;/li&gt;
&lt;li&gt;padded: a props to show if the progress bar should be padded or not&lt;/li&gt;
&lt;li&gt;progress: this is the progress width (0 - 100%)&lt;/li&gt;
&lt;li&gt;innerBackgroundColor: this is the progress color.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Full Code:  &lt;a href="https://snack.expo.dev/@akinolu52/63d860" rel="noopener noreferrer"&gt;link&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import styled from 'styled-components/native';

const ProgressBar = ({progress, height = 8, outerBackgroundColor, innerBackgroundColor, padded = true}) =&amp;gt;(
  &amp;lt;Container
    height={height}
    padded={padded}
    outerBackgroundColor={outerBackgroundColor}
   &amp;gt;
    &amp;lt;Content 
      height={height}
      padded={padded}
      progress={progress} 
      innerBackgroundColor={innerBackgroundColor}
    /&amp;gt;
  &amp;lt;/Container&amp;gt;
);

const Container = styled.View`
  width: "100%";
  borderRadius: 16;
  alignItems: flex-start;
  justifyContent: center;
  height: ${props =&amp;gt; props.height};
  backgroundColor: ${props =&amp;gt; props.outerBackgroundColor};
  paddingHorizontal: ${props =&amp;gt; props.padded ? 3 : 0};
`;

const Content = styled.View`
  borderRadius: 16;
  height: ${props =&amp;gt; props.padded ? (props.height / 2) : props.height};
  backgroundColor: ${props =&amp;gt; props.innerBackgroundColor};
  width: ${props =&amp;gt; props.progress}%;
`;

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

&lt;/div&gt;



&lt;p&gt;Thanks, for checking out this tutorial.&lt;/p&gt;

&lt;p&gt;If you have any questions, feedback or  comments, please let me know. &lt;/p&gt;

&lt;p&gt;You can connect with me on&lt;br&gt;
&lt;a href="https://twitter.com/akinolu52" rel="noopener noreferrer"&gt;twitter&lt;/a&gt;  &lt;a href="//mailto://akinolu52@gmail.com"&gt;email&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>reactnative</category>
      <category>mobile</category>
      <category>styledcomponents</category>
    </item>
    <item>
      <title>Supercharged Visual Studio Code - Part 1</title>
      <dc:creator>Emmanuel Akinyemi</dc:creator>
      <pubDate>Tue, 19 Jul 2022 15:41:36 +0000</pubDate>
      <link>https://dev.to/akinolu52/supercharged-visual-studio-code-part-1-5ffi</link>
      <guid>https://dev.to/akinolu52/supercharged-visual-studio-code-part-1-5ffi</guid>
      <description>&lt;p&gt;Hello everyone 😄&lt;/p&gt;

&lt;p&gt;Do you want to get work done faster without switching applications?&lt;br&gt;
There are alot of packages on vs-code that helps with important tasks.&lt;/p&gt;

&lt;p&gt;(1). Why use postman etc to test endpoints when you can do it from your vs-code&lt;br&gt;
Download &lt;strong&gt;thunder client&lt;/strong&gt; on vs-code extenstion tab&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--W3663rGI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637318285590/x-KO4bP2r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--W3663rGI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637318285590/x-KO4bP2r.png" alt="Screenshot 2021-11-19 at 11.37.58.png" width="880" height="651"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AYG0rZ86--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637319731193/peedOGKy-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AYG0rZ86--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637319731193/peedOGKy-.png" alt="Screenshot 2021-11-19 at 12.02.01.png" width="880" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(2). When you have your project setup in Typescript and you want to import function, components etc from any file without writing the import statement then use &lt;strong&gt;Auto Import&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8Jgx3Dgz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637318471652/CDIU8aamV.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8Jgx3Dgz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637318471652/CDIU8aamV.png" alt="Screenshot 2021-11-19 at 11.41.05.png" width="880" height="567"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(3). I am cautious about the package I use while developing, on NPM package repository there are alot of packages that do one thing or the other but most of these packages are HEAVY and it will affect building time and also visual rendering, so what I do is: I minimize the use of external packages and I check the cost of importing a package. The extension I used to check the cost is called &lt;strong&gt;Import Cost&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vgb2BNpG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637318900441/nWbr7Si_i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vgb2BNpG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637318900441/nWbr7Si_i.png" alt="Screenshot 2021-11-19 at 11.47.19.png" width="880" height="663"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gQq2ju7R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637318881372/PlxY5fDjm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gQq2ju7R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637318881372/PlxY5fDjm.png" alt="Screenshot 2021-11-19 at 11.47.54.png" width="880" height="234"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(4). Sharing code snippet is Nice, it enhances collaboration. to do this you don't need to leave your vs-code editor, download &lt;strong&gt;Polacode&lt;/strong&gt; and share that code with a fellow engineer 😊 😊&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M_dsh_QN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637319095650/tTVw82key.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M_dsh_QN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637319095650/tTVw82key.png" alt="Screenshot 2021-11-19 at 11.51.12.png" width="880" height="574"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bJsyK1Ma--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637319275940/53U351IGi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bJsyK1Ma--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637319275940/53U351IGi.png" alt="Screenshot 2021-11-19 at 11.54.25.png" width="880" height="706"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(5). For Javascript or Typescript engineers that wants to test a concept or implement an algrorithm outside their project, you DON'T need to google -js online editor- like the former me, just download &lt;strong&gt;Quokka.js&lt;/strong&gt; on vs-code extensions&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IqRoBYS3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637319422058/Vyn7QHNSj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IqRoBYS3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637319422058/Vyn7QHNSj.png" alt="Screenshot 2021-11-19 at 11.56.56.png" width="880" height="618"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I mean check my terminal 😊 😊 - so cool(you get to see the result ASAP)&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aBoXIBlQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637319451283/SYqzVaJoB.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aBoXIBlQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637319451283/SYqzVaJoB.png" alt="Screenshot 2021-11-19 at 11.57.24.png" width="880" height="585"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks, for checking out this tutorial. (please like and add your comments)&lt;br&gt;
You can also check out my other tutorials on my  &lt;a href="https://akinolu52.hashnode.dev/"&gt;blog&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If you have any questions, feedback or comments, please let me know.&lt;/p&gt;

&lt;p&gt;You can connect with me on &lt;a href="https://twitter.com/akinolu52"&gt;twitter&lt;/a&gt; &lt;a href="//mailto://akinolu52@gmail.com"&gt;email&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also reach out to me if you have a project,&lt;br&gt;
gig or role for me(I do React-Native &amp;amp; React Js)  &lt;a href="https://twitter.com/akinolu52"&gt;twitter&lt;/a&gt; &lt;a href="//mailto://akinolu52@gmail.com"&gt;email&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>vscode</category>
      <category>typescript</category>
      <category>react</category>
    </item>
    <item>
      <title>Memoization in JavaScript and React</title>
      <dc:creator>Emmanuel Akinyemi</dc:creator>
      <pubDate>Mon, 18 Jul 2022 18:49:33 +0000</pubDate>
      <link>https://dev.to/akinolu52/memoization-in-javascript-and-react-4ni7</link>
      <guid>https://dev.to/akinolu52/memoization-in-javascript-and-react-4ni7</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Memoization is a concept that's interesting and I believe all Javascript developer should be fascinated and familiar with it.&lt;/p&gt;

&lt;p&gt;I will be going through this subject by in the following way: WHAT, WHY and HOW&lt;/p&gt;

&lt;h2&gt;
  
  
  1. What is Memoization?
&lt;/h2&gt;

&lt;p&gt;When I first saw the word memoization what came to my mind was memorize, and I was confused! like how is JavaScript supposed to memorize and remember something on my behalf(I was thinking, is there some form of machine learning in JavaScript by default), but going deep into the concept of memoization I understood that it is all about helping JavaScript to memorize previous computation.&lt;/p&gt;

&lt;p&gt;In-order words, memoization is a optimization technique that helps to speed-up repetitive, expensive computation by remembering the result of the previous computation.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Why Memoization?
&lt;/h2&gt;

&lt;p&gt;The technique is revolved about making computation efficient and faster; If an expensive computation is done, with Memoization the result can be stored in eg. cache and retrieved when it's needed, hence there's no need to re-compute.&lt;/p&gt;

&lt;p&gt;You have the all this with memoization, and in-addition you get efficient computation, optimization and faster computation (since it skips what has been done before).&lt;/p&gt;

&lt;h2&gt;
  
  
  3. How to implement Memoization?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  In JavaScript?
&lt;/h3&gt;

&lt;p&gt;Implementing memoization is about passing a function to a memoized callback&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const multiplyBy10 = (num: number) =&amp;gt; num * 10;
console.log('Simple call', multiplyBy10(3));

/**
 * 
 * Explanation: a simple memoize function that takes in a function
 * 
 * @param fn a function to be memoized or used to perform computation
 * @returns a memoized function
 */

const memoize = (fn: Function) =&amp;gt; {
  let cache = {};

  return (...args) =&amp;gt; {
    let num = args[0];  // just taking one argument here

    if (num in cache) {
      console.log('Fetching from cache');
      return cache[num];
    } else {
      console.log('Calculating result');
      let result = fn(num);
      cache[num] = result;
      return result;
    }
  }

}

// creating a memoized function for the 'multiplyBy10' pure function

const memoizedAdd = memoize(multiplyBy10);
console.log(memoizedAdd(3));  // calculated
console.log(memoizedAdd(3));  // cached
console.log(memoizedAdd(4));  // calculated
console.log(memoizedAdd(4));  // cached

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;thanks to Codegrepper &amp;amp; &lt;a href="https://www.codegrepper.com/profile/agreeable-armadillo-r83981x69s29"&gt;Agreeable Armadillo&lt;/a&gt; for the code reference&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nlBhHXZi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tscwiz6apuit6s3p6fcy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nlBhHXZi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tscwiz6apuit6s3p6fcy.png" alt="Thanks to Denigma for the explanation; you can read more about it [here](https://akinolu52.hashnode.dev/supercharged-visual-studio-code-part-2)" width="880" height="1114"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  In React
&lt;/h3&gt;

&lt;p&gt;There are several ways of implementing memoization and this is based on what is needed to be done&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;for &lt;em&gt;component&lt;/em&gt; use React.memo()&lt;/li&gt;
&lt;li&gt;If you want to &lt;em&gt;memoize a function&lt;/em&gt; then use React.useCallback();&lt;/li&gt;
&lt;li&gt;If you want to &lt;em&gt;memoize the result of an expensive function&lt;/em&gt; then use React.useMemo();&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These methods prevent un-neccessary re-rendering in react if used the right way&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding React.memo()
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * Explanation: 
 *  this function accept a name and render a styled version of it
 * 
 * @param name
 * @returns JSX.Element (styled version of the name)
 **/
import React from 'react';

function RenderName({ name }: string) {
    return &amp;lt;span className="text-red-500"&amp;gt;{name}&amp;lt;/span&amp;gt;
}

export default React.memo(RenderName);

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Consider the component above(child-component) without the React.memo() higher order component (HOC) we'll have issues with re-rendering when the name passed to the &lt;em&gt;RenderName&lt;/em&gt; component are the same; but React.memo() HOC helps to prevent this unnecessary re-renders&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;NB: memo does not optimize a function being passed to child component, that's why we need React.useCallback()&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding React.useCallback()
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * Explanation:
 * a password field that handles users password 
 * and provides a toggle for the password
 *  
 * @returns JSX.Element (a styled password field)
 */
import React from 'react';
import eye from 'images/eye.svg';
import eyeClose from 'images/eye-close.svg';

function PasswordInput() {
  const [show, setShow] = React.useState&amp;lt;boolean&amp;gt;(false);
  const toggleSecret = React.useCallback(() =&amp;gt; setShow(x =&amp;gt; !x), []);

  return (
    &amp;lt;div className="h-8 flex items-center"&amp;gt;
      &amp;lt;input type="password" className="..." placeholder="Enter Password" /&amp;gt;

      &amp;lt;button onClick={toggleSecret}&amp;gt;
        &amp;lt;img src={show ? eyeClose : eye} alt="toggle secret" /&amp;gt;
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default PasswordInput;

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;with React.useCallback() the toggleSecret() function is memoized and whenever you click this the toggle button it doesn't cause a re-render there by increasing optimization.&lt;br&gt;
Note: we passed the arrow function to the React.useCallback(). the arrow function is: &lt;br&gt;
() =&amp;gt; setShow((x) =&amp;gt; !x)&lt;br&gt;
React.useCallback() also helps to prevent re-rendering when a function is being passed down to a child component, This is done by 'keeping' the function passed to the child component while the parent component re-render.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Understanding React.useMemo()
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * Explanation:
 * The code demonstrates how to create a DynamicTable using React's useMemo() function.
 * The DynamicTable component is a wrapper around the Table component.
 * The DynamicTable component is responsible for creating the columns and data for the Table component.
 * 
 * @param {values: Record&amp;lt;string, string&amp;gt;[] | null}
 * @returns returns a JSX.Element(Table)
 */

import React, { useMemo } from 'react';
import Table, { ColumnsProps } from './Table';

interface DynamicTableType {
  values: Record&amp;lt;string, string&amp;gt;[] | null;
}

const DynamicTable = ({ values }: DynamicTableType): JSX.Element =&amp;gt; {
  const columns: ColumnsProps[] = useMemo(() =&amp;gt; {
    if (!values) return [];
    const keys = Object.keys(values?.[0]);

    const result = [];

    for (let index = 0; index &amp;lt; keys.length; index++) {
      const element = keys[index];
      result.push({
        Header: element?.replace('_', ' '),
        accessor: element,
      });
    }

    return result;
  }, [values]);

  const data: Record&amp;lt;string, string&amp;gt;[] = useMemo(() =&amp;gt; {
    if (!values) return [];
    const result: Record&amp;lt;string, string&amp;gt;[] = [];

    for (let index = 0; index &amp;lt; values.length; index++) {
      const element = values[index];
      result.push(element);
    }
    return result;
  }, [values]);

  return &amp;lt;Table columns={columns} data={data} showSearch={false} /&amp;gt;;
};

export default DynamicTable;

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Extract from an open-source project I'm currently working on, check it out on &lt;a href="https://github.com/re-data/re-data"&gt;github&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The whole idea behind React.useMemo() is similar to that of React.useCallback(); but in React.useMemo() the result returned from the function calculation is being cached, so you dont have to repeat such expensive calculation (provided that your dependent array of the useMemo does not change). In the above example, &lt;em&gt;columns &amp;amp; data&lt;/em&gt; are the memoized value.&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;p&gt;In all, Optimization is something we should care about as Engineers and simple techniques like caching can help us prevent re-rendering/optimization issues etc. &lt;strong&gt;Memoization is only needed, when you are handling expensive calculation.&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I am available for technical talks on data-structure, algorithms, javascript, react and react-native; you can reach out to me via &lt;a href="https://twitter.com/akinolu52"&gt;twitter&lt;/a&gt; or &lt;a href="//mailto://akinolu52@gmail.com"&gt;email&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will also start a youtube channel soon to highlight my jouney with data-structure and algorithms, In the channel, I will be solving some leetcode questions and anyother interview materials I lay my hands on. watch out 😊&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Footnotes
&lt;/h2&gt;

&lt;p&gt;Thanks, for checking out this tutorial. (&lt;strong&gt;please like and add your comments&lt;/strong&gt;)&lt;br&gt;
You can also check out my other write-ups on my &lt;a href="https://akinolu52.hashnode.dev/"&gt;blog&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If you have any questions, feedback or comments, please let me know.&lt;/p&gt;

&lt;p&gt;You can connect with me on &lt;a href="https://twitter.com/akinolu52"&gt;twitter&lt;/a&gt; &lt;a href="//mailto://akinolu52@gmail.com"&gt;email&lt;/a&gt; &lt;a href="https://github.com/akinolu52/"&gt;github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also reach out to me(I do React-Native &amp;amp; React Js) &lt;a href="https://twitter.com/akinolu52"&gt;twitter&lt;/a&gt; &lt;a href="//mailto://akinolu52@gmail.com"&gt;email&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>memoization</category>
      <category>react</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
