<?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: Balamurugan D</title>
    <description>The latest articles on DEV Community by Balamurugan D (@balamurugan16).</description>
    <link>https://dev.to/balamurugan16</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%2F1116384%2F76713afc-4f83-4410-b12f-26f3905781da.png</url>
      <title>DEV Community: Balamurugan D</title>
      <link>https://dev.to/balamurugan16</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/balamurugan16"/>
    <language>en</language>
    <item>
      <title>JavaScript Array methods Explained</title>
      <dc:creator>Balamurugan D</dc:creator>
      <pubDate>Tue, 14 Nov 2023 12:30:09 +0000</pubDate>
      <link>https://dev.to/balamurugan16/javascript-array-methods-explained-342d</link>
      <guid>https://dev.to/balamurugan16/javascript-array-methods-explained-342d</guid>
      <description>&lt;p&gt;Arrays are a fundamental data structure that is used almost every day, unlike other data structures like a Tree or graph. JavaScript has some good methods that can be used on an array which is so easy to implement when compared to the traditional for-loop approach. In this blog, we will look at 6 JavaScript array Higher order methods, and when and how to use them with examples.&lt;/p&gt;

&lt;p&gt;💡&lt;/p&gt;

&lt;p&gt;Before that, If you want to know about Higher-order functions in JavaScript, make sure you read &lt;a href="https://dev.to/balamurugan16/higher-order-functions-in-javascript-2d6j"&gt;this blog&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There are a few things to note before starting,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;All these array methods take an arrow function as one of the parameters.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This arrow function will get executed for each element of the array&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;ForEach&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;forEach&lt;/code&gt; method is the simplest method of all, It is similar to a for loop implemented for an array. It takes in an arrow function and executes that arrow function for each element of the loop as the name says. The function also does not return anything.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fruits = ['apple', 'banana', 'orange'];

fruits.forEach((fruit, index) =&amp;gt; {
  console.log(`Fruit at index ${index}: ${fruit}`);
});

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

&lt;/div&gt;



&lt;p&gt;The arrow function can take in 3 optional parameters.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The first parameter is the current element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The second parameter is the current elements index.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Third parameter is the array itself.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The above parameter list will be similar in most of the array methods.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Map
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;map&lt;/code&gt; method takes in an array and transforms it into another array. This method is very popular in the React world where an array is transformed into a JSX element. T&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4, 5];

const squaredNumbers = numbers.map((num) =&amp;gt; {
  return num ** 2;
});

console.log(squaredNumbers); // [1, 4, 9, 16, 25]

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;map&lt;/code&gt; method returns the transformed array so there is a return value. Also, the callback function should return the transformed value for each element. This method also has similar parameters passed into the callback function like the &lt;code&gt;forEach&lt;/code&gt; method.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Filter&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;filter&lt;/code&gt; method provides an easy solution to selectively extract elements from an array based on a condition. It takes an arrow function that evaluates the condition for each element, creating a new array with only the elements that pass the test.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4, 5, 6];

const evens = numbers.filter((num) =&amp;gt; {
  return num % 2 === 0;
});

console.log(evens); // [2, 4, 6]

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

&lt;/div&gt;



&lt;p&gt;The arrow function can utilize the standard parameterscurrent element, index, and the array itselfjust like in many other array methods.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Reduce&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;reduce&lt;/code&gt; method is a powerhouse for transforming an array into a single value, often used for summing up or accumulating values. It takes an arrow function and an initial value for the accumulator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4, 5];

const sum = numbers.reduce((accumulator, current) =&amp;gt; {
  return accumulator + current;
}, 0);

console.log(sum); // 15

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

&lt;/div&gt;



&lt;p&gt;The arrow function receives the accumulator and the current element, and it should return the updated value of the accumulator. Here, the sum of all numbers is calculated.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Every&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;every&lt;/code&gt; method checks if every element in an array satisfies a given condition. It returns &lt;code&gt;true&lt;/code&gt; if all elements pass the test; otherwise, it returns &lt;code&gt;false&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ages = [25, 30, 22, 28];

const isAdult = ages.every((age) =&amp;gt; {
  return age &amp;gt;= 18;
});

console.log(isAdult); // true

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

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;every&lt;/code&gt; method ensures that all ages are 18 or older.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Some&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Conversely, the &lt;code&gt;some&lt;/code&gt; method checks if at least one element in an array meets a specified condition. It returns &lt;code&gt;true&lt;/code&gt; if any element passes the test.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const temperatures = [20, 25, 18, 22];

const hasHighTemperature = temperatures.some((temp) =&amp;gt; {
  return temp &amp;gt; 25;
});

console.log(hasHighTemperature); // true

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

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;some&lt;/code&gt; checks if there is at least one temperature higher than 25.&lt;/p&gt;

&lt;p&gt;So that's it, Those are the 6 different JavaScript array methods that can be used in different scenarios based on your use case. I have used all these methods extensively. I hope this blog was helpful, leave a like and comment if you liked it. Until next time!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Demystifying JSX 🚀</title>
      <dc:creator>Balamurugan D</dc:creator>
      <pubDate>Mon, 13 Nov 2023 18:09:52 +0000</pubDate>
      <link>https://dev.to/balamurugan16/demystifying-jsx-3jjm</link>
      <guid>https://dev.to/balamurugan16/demystifying-jsx-3jjm</guid>
      <description>&lt;p&gt;React is popular because of its declarative approach to building UI components. This has led to a rise in the library's popularity, making it the de-facto standard for modern web development. The declarative approach comes from various factors like functional components and JSX. Don't get confusedJSX and React are two separate things but are used together. Some other frameworks like Vue.js and Preact also use JSX. In this blog post, we will learn more about JSX and how it makes our lives easier while coding in React.&lt;/p&gt;

&lt;p&gt;approach doesnt scale well, and it is too verbose. Just imagine how an already complex application will look if written in the previous approach. This is what JSX brings to the table. With that example, we have reached the end of this blog post. This blog is a part of my React series, and if you like this series, let me know by leaving a like and comment. Until next time!&lt;/p&gt;

&lt;p&gt;JSX is an XML-like syntax that is often used to express UI components. It was developed by Facebook. You can learn more about JSX &lt;a href="https://facebook.github.io/jsx/"&gt;here&lt;/a&gt;. JSX looks similar to HTML but is different in many ways concerning the syntax and features like:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;A JSX element should have only a single root element. This should be obvious if you are using the fragment in React (&lt;code&gt;&amp;lt;&amp;gt;&amp;lt;/&amp;gt;&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It requires tags to be closed explicitly. For example, in JSX, the image tag should be autoclosed (&lt;code&gt;&amp;lt;img /&amp;gt;&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Most of the HTML attributes are in camel casing. For example, &lt;code&gt;onClick&lt;/code&gt;, &lt;code&gt;onChange&lt;/code&gt;, etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JSX allows the injection of JavaScript using curly braces. This allows the full power of JavaScript to create a dynamic UI.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now let's try to create a simple React component without using JSX and JSX and compare to see the benefits and simplicity that JSX is bringing.&lt;/p&gt;

&lt;p&gt;Lets start by creating an &lt;code&gt;h1&lt;/code&gt; tag containing Hi Mom!&lt;br&gt;
&lt;/p&gt;

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

export default function Component() {
  return (
    React.createElement('h1', {id: "heading"}, "Hi Mom!")
  );
}

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

&lt;/div&gt;



&lt;p&gt;Okay, so here you can see some new weirdness going on. Let me demystify it.&lt;/p&gt;

&lt;p&gt;React exports a function &lt;code&gt;createElement&lt;/code&gt; that lets us create any HTML element. It takes in three parameters:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The first parameter takes in the name of the HTML element, in our case, the &lt;code&gt;h1&lt;/code&gt; element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The second parameter will take in all the valid HTML attributes like &lt;code&gt;id&lt;/code&gt;, &lt;code&gt;className&lt;/code&gt;, &lt;code&gt;onClick&lt;/code&gt;, etc. In our case, the &lt;code&gt;id&lt;/code&gt; attribute.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The third parameter will take in the children for the current element. In our case, just the text &lt;strong&gt;Hi Mom!&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now React will take all these and convert them into HTML behind the scenes. Lets go the extra mile by wrapping the &lt;code&gt;h1&lt;/code&gt; element in an &lt;code&gt;header&lt;/code&gt; element.&lt;br&gt;
&lt;/p&gt;

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

export default function Component() {
  return (
    React.createElement(
      'header',
      {},
      React.createElement(
        "h1",
        {id: "heading"},
        "Hi Mom!"
      )
    )
  );
}

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

&lt;/div&gt;



&lt;p&gt;Here you can see the use of the third parameter. We have wrapped the previously created element into a new &lt;code&gt;header&lt;/code&gt; element. This is how React elements can be created without using JSX 🤯.&lt;/p&gt;

&lt;p&gt;Now lets use JSX and recreate the UI that we have written so far.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function Component() {
  return (
    &amp;lt;header&amp;gt;
      &amp;lt;h1 id="heading"&amp;gt;Hi Mom!&amp;lt;/h1&amp;gt;
    &amp;lt;/header&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;The syntax with JSX is far more readable and familiar as well. The previous approach doesnt scale well, and it is too verbose. Just imagine how an already complex application will look if written in the previous approach. This is what JSX brings to the table.&lt;/p&gt;

&lt;p&gt;With that example, we have reached the end of this blog post. This blog is a part of my React series, and if you like this series, let me know by leaving a like and comment. Until next time! 👋&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Building an Overengineered React Ecosystem 🚀</title>
      <dc:creator>Balamurugan D</dc:creator>
      <pubDate>Thu, 02 Nov 2023 17:34:47 +0000</pubDate>
      <link>https://dev.to/balamurugan16/building-an-overengineered-react-ecosystem-471f</link>
      <guid>https://dev.to/balamurugan16/building-an-overengineered-react-ecosystem-471f</guid>
      <description>&lt;p&gt;In the world of web development, React has been a standout library for creating user interfaces. However, when it comes to building complex applications, it often leans on various third-party packages to get the job done. What if we took these dependencies and mixed them into a single ecosystem? This would transform React into a full-fledged framework, with a dash of humor, of course! In this blog, we'll craft the ultimate overengineered React ecosystem by combining several powerful libraries and tools.&lt;/p&gt;

&lt;h2&gt;
  
  
  React 18:
&lt;/h2&gt;

&lt;p&gt;React 18 brings impressive features like concurrent rendering and server components, making your app feel like it's on a rollercoaster of performance improvements. 🎢&lt;/p&gt;

&lt;h2&gt;
  
  
  TypeScript:
&lt;/h2&gt;

&lt;p&gt;TypeScript is like the grammar police for your code. It's like having a spell checker that makes sure your variables, functions, and data structures are used correctly.&lt;br&gt;
&lt;/p&gt;

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

interface MyComponentProps {
  name: string;
  age: number;
  email: string;
}

const MyComponent: React.FC&amp;lt;MyComponentProps&amp;gt; = (props) =&amp;gt; {
  const { name, age, email } = props;

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;Name: {name}&amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;Age: {age}&amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;Email: {email}&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default MyComponent;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Vite:
&lt;/h2&gt;

&lt;p&gt;Vite is the speedster of the build tool world. It's like your favorite race car, offering an instant development server and optimized build output.&lt;/p&gt;

&lt;h2&gt;
  
  
  React Router Dom:
&lt;/h2&gt;

&lt;p&gt;If your app is like a city, React Router Dom is the GPS. It helps users navigate around your app smoothly and find what they're looking for.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { BrowserRouter as Router, Route, Link } from 'react-router-dom';

&amp;lt;Route path="/about" component={About} /&amp;gt;
&amp;lt;Link to="/about"&amp;gt;About&amp;lt;/Link&amp;gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Axios:
&lt;/h2&gt;

&lt;p&gt;Axios is your trusty messenger for sending and receiving data from the internet. It's like the postman of the digital world, delivering HTTP requests.&lt;/p&gt;

&lt;h2&gt;
  
  
  React Query:
&lt;/h2&gt;

&lt;p&gt;React Query is your data-fetching sidekick. It keeps your app snappy by handling data fetching and caching, making your life easier.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useQuery } from 'react-query';

const { data, isLoading } = useQuery('userData', fetchUserData);

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Redux Toolkit:
&lt;/h2&gt;

&lt;p&gt;Redux Toolkit is the magic wand for managing the state of your app. It simplifies complex state management and keeps your app's data in line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { configureStore, createSlice } from '@reduxjs/toolkit';

const counterSlice = createSlice({
  name: 'counter',
  initialState: 0,
  reducers: {
    increment: (state) =&amp;gt; state + 1,
  },
});

const store = configureStore({
  reducer: {
    counter: counterSlice.reducer,
  },
});

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Tailwind CSS:
&lt;/h2&gt;

&lt;p&gt;Tailwind CSS is like having a personal stylist for your app's design. It makes your app look trendy and stylish without breaking a sweat.&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;div className="bg-blue-500 text-white p-4"&amp;gt;
  This is a Tailwind CSS component.
&amp;lt;/div&amp;gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  ESLint and Prettier:
&lt;/h2&gt;

&lt;p&gt;ESLint and Prettier are your code buddies. They nag you when your code is messy and help you clean it up, just like a neat freak friend.&lt;/p&gt;

&lt;h2&gt;
  
  
  Vitest:
&lt;/h2&gt;

&lt;p&gt;Vitest is your app's health checkup. It ensures your components are in top shape and ready to conquer the digital world. 🩺&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { test, runTests } from 'vitest';

test('My React Component', async (context) =&amp;gt; {
  const { queryByText } = render(MyComponent);
  await context.is(queryByText('Hello, World!'), 'Hello, World!');
});

runTests();

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Playwright:
&lt;/h2&gt;

&lt;p&gt;Playwright is your app's bodyguard. It tests your app's every move, making sure it's ready to face the real world. 🕵&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { chromium } = require('playwright');

(async () =&amp;gt; {
  const browser = await chromium.launch();
  const page = await browser.newPage();
  await page.goto('&amp;lt;https://example.com&amp;gt;');
  await page.click('a');
  await browser close();
})();

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

&lt;/div&gt;



&lt;p&gt;By combining these libraries and tools into one ecosystem, we've created an over-the-top React framework. It's like adding rocket boosters to your React development. Whether it's routing, data fetching, state management, styling, testing, or end-to-end testing, our overengineered ecosystem has got you covered. If you're looking for a complete solution to turbocharge your React projects, give this ecosystem a spin. It's like adding nitro to your coding journey. Happy coding! 🚀🎉&lt;/p&gt;

</description>
    </item>
    <item>
      <title>React with Typescript, Tips and Tricks that you should know!</title>
      <dc:creator>Balamurugan D</dc:creator>
      <pubDate>Mon, 30 Oct 2023 18:15:13 +0000</pubDate>
      <link>https://dev.to/balamurugan16/react-with-typescript-tips-and-tricks-that-you-should-know-2ikn</link>
      <guid>https://dev.to/balamurugan16/react-with-typescript-tips-and-tricks-that-you-should-know-2ikn</guid>
      <description>&lt;p&gt;React is a popular JavaScript library for building user interfaces, and TypeScript is a statically typed superset of JavaScript. Together, they make for a powerful combination, allowing developers to write safer and more maintainable code. In this guide, we'll explore various aspects of using TypeScript with React, from typing props to taking advantage of TypeScript's advanced features for a more productive development experience. Additionally, we will refer to the &lt;a href="https://react-typescript-cheatsheet.netlify.app/"&gt;React TypeScript cheat sheet&lt;/a&gt; to help you deepen your understanding.&lt;/p&gt;

&lt;h2&gt;
  
  
  Typing Props
&lt;/h2&gt;

&lt;p&gt;One of the fundamental aspects of React development with TypeScript is typing the props passed to your components. You can define prop types directly within the parameters, enhancing code readability and maintainability:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Props = {
    prop1: string;
    prop2: string;
}
const MyComponent = ({ prop1, prop2 }: Props) =&amp;gt; {
  return &amp;lt;div&amp;gt;{prop1} - {prop2}&amp;lt;/div&amp;gt;;
};

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

&lt;/div&gt;



&lt;p&gt;This ensures that &lt;code&gt;MyComponent&lt;/code&gt; receives the expected props and provides type safety during development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Generic Types for Hooks and Functions
&lt;/h2&gt;

&lt;p&gt;You can use TypeScript's generic types to provide type information to React hooks and functions like &lt;code&gt;useState&lt;/code&gt;, &lt;code&gt;useRef&lt;/code&gt;, &lt;code&gt;useMemo&lt;/code&gt;, and more. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [count, setCount] = useState&amp;lt;number&amp;gt;(0);
const myRef = useRef&amp;lt;HTMLDivElement | null&amp;gt;(null);
const memoizedValue = useMemo&amp;lt;number&amp;gt;(() =&amp;gt; computeExpensiveValue(), [deps]);

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

&lt;/div&gt;



&lt;p&gt;These generic types help prevent type-related bugs and make your code more self-explanatory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Typing onClick Functions
&lt;/h2&gt;

&lt;p&gt;When defining onClick event handlers that are used in JSX elements, it's a good practice to specify their types, especially if they are defined separately. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type MouseEventHandler = (event: React.MouseEvent&amp;lt;HTMLButtonElement&amp;gt;) =&amp;gt; void;

const handleButtonClick: MouseEventHandler = (event) =&amp;gt; {
  // Handle button click event
};

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

&lt;/div&gt;



&lt;p&gt;Typing the &lt;code&gt;handleButtonClick&lt;/code&gt; function ensures that it correctly handles the &lt;code&gt;onClick&lt;/code&gt; event.&lt;/p&gt;

&lt;h2&gt;
  
  
  VS Code Tooltip for React Components
&lt;/h2&gt;

&lt;p&gt;Visual Studio Code provides excellent TypeScript support, and you can take advantage of it to get tooltips and autocompletions for React components. By hovering over an HTML element or its attribute, you can infer the return type or the type of the element/attribute. This feature makes it easier to understand how to use it correctly and define types for your components.&lt;/p&gt;

&lt;h2&gt;
  
  
  PropsWithChildren
&lt;/h2&gt;

&lt;p&gt;React components often receive children as props. The &lt;code&gt;PropsWithChildren&lt;/code&gt; utility type is helpful for this scenario. It allows you to specify that a component accepts children and other props:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { PropsWithChildren } from 'react';

type Props = {
    title: string;
} &amp;amp; PropsWithChildren;

const Card = ({ title, children }: Props) =&amp;gt; {
  return (
    &amp;lt;div className="card"&amp;gt;
      &amp;lt;h2&amp;gt;{title}&amp;lt;/h2&amp;gt;
      &amp;lt;div className="content"&amp;gt;{children}&amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  ComponentPropsWithoutRef and ComponentPropsWithRef
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;ComponentPropsWithoutRef&lt;/code&gt; and &lt;code&gt;ComponentPropsWithRef&lt;/code&gt; utility types are helpful when you're working with component props. They help in maintaining a clear separation between props and ref types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ComponentPropsWithoutRef&lt;/code&gt; allows you to specify component props without including the &lt;code&gt;ref&lt;/code&gt; prop.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ComponentPropsWithRef&lt;/code&gt; includes the &lt;code&gt;ref&lt;/code&gt; prop.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { ComponentPropsWithoutRef } from 'react';

type InputProps = ComponentPropsWithoutRef&amp;lt;'input'&amp;gt;;

const MyInput = (props: InputProps) =&amp;gt; {
  return &amp;lt;input {...props} /&amp;gt;;
};

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

&lt;/div&gt;



&lt;p&gt;By using these utility types, you can ensure that your components handle props and refs appropriately.&lt;/p&gt;

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

&lt;p&gt;Using React with TypeScript provides a strong foundation for building robust and maintainable applications. Typing props, using generic types for hooks, and understanding advanced TypeScript utility types like &lt;code&gt;PropsWithChildren&lt;/code&gt;, &lt;code&gt;ComponentPropsWithoutRef&lt;/code&gt;, and &lt;code&gt;ComponentPropsWithRef&lt;/code&gt; are key steps in mastering this powerful combination. Make sure to refer to the &lt;a href="https://react-typescript-cheatsheet.netlify.app/"&gt;React TypeScript cheat sheet&lt;/a&gt; for additional tips and best practices to enhance your React TypeScript development skills. Happy coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>🚀 A Fun Journey to Cleaner Git History: Rebase and Interactive Rebase</title>
      <dc:creator>Balamurugan D</dc:creator>
      <pubDate>Thu, 26 Oct 2023 18:33:58 +0000</pubDate>
      <link>https://dev.to/balamurugan16/a-fun-journey-to-cleaner-git-history-rebase-and-interactive-rebase-1c03</link>
      <guid>https://dev.to/balamurugan16/a-fun-journey-to-cleaner-git-history-rebase-and-interactive-rebase-1c03</guid>
      <description>&lt;p&gt;Git is an awesome tool for managing code, but sometimes our commit history can get a little messy. 🙈 You might have experienced those awkward-looking merge commits when bringing changes from one branch into another. Fear not, my fellow developers! Git comes to the rescue with a nifty feature called "Rebase." Let's dive into this magical journey of git history cleaning using rebase!&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;🤔 The Merge tantrum&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Picture this: you have a feature branch that's a few commits behind the master branch. In the below message, the blue-colored commits are in the master branch and the cyan-colored messages are in the feature branch. In this case, the added helper methods commit is created after the feature branch is created. So now to update your feature branch with your master branch, if you merge, you get a merge commit that, quite frankly, looks like a tangled ball of yarn. 🐱🧶 Merging is cool, but it can clutter your commit history with all those merge commits, creating a jungle of complexity, and your git history looks like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UetkXXE7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1698345120481/fd48d405-e5a7-41db-bb0a-3fff0464f0e9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UetkXXE7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1698345120481/fd48d405-e5a7-41db-bb0a-3fff0464f0e9.png" alt="" width="800" height="339"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;🧹 The Rebase Magic&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Enter "Rebase"! It's like having a magical broom to sweep away those messy merge commits. 🧙 What Rebase does is take your feature branch and neatly replant all your hard-earned commits on top of the main branch. 🌱 It's like transplanting your garden without anyone noticing. This process keeps your changes but gives you a cleaner history.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8dNE6cQ7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1698345140203/e6e5907c-fe3b-491f-9498-9406f5873181.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8dNE6cQ7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1698345140203/e6e5907c-fe3b-491f-9498-9406f5873181.png" alt="" width="800" height="373"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;When Not to Rebase&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Hold your magical brooms, folks! Rebase should be used with caution. If your branch is already on a remote repository, and others have access to its commits, things can get a bit tricky. When you rebase, Git essentially creates new versions of your commits with different IDs, which can lead to confusion. 🤯 It's like a magical identity crisis for your commits!&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;The Interactive Rebase Adventure&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;But wait, there's more! Git's Rebase isn't just about tidying up. It can also be your storytelling tool! Enter "Interactive Rebase." 🎬 With this feature, you can rewrite, delete, rename, or even reorder your commits before you share them with the world. It's like being the director of your own commit history movie. 🎥&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To start this adventure, use the command:&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;git rebase -i &amp;lt;commit_id in the current branch&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;-i&lt;/code&gt; stands for "interactive." 🎭&lt;/p&gt;

&lt;p&gt;Choose your characters wisely! The commit ID you pick should be from your current branch. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git rebase -i HEAD~5

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

&lt;/div&gt;



&lt;p&gt;In this command, we're taking the last 5 commits into account for our rebase extravaganza. 🕺💃&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;🎭 The Rebase Theater&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Here, you get to play the director. You have different roles to cast for your commits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;PICK:&lt;/strong&gt; Keep the commit it's like saying, "You're the chosen one!"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;REWORD:&lt;/strong&gt; Edit the commit message fix typos, clarify, or make it more informative.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DROP:&lt;/strong&gt; Delete the commit sometimes, you've got to trim the excess.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;FIXUP:&lt;/strong&gt; Combine commits merge them into one for a cleaner story.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's like shaping your commit history to be an Oscar-winning blockbuster. 🏆&lt;/p&gt;




&lt;p&gt;And there you have it, the magical world of Rebase and Interactive Rebase in Git! 🌟 Clean up your history, make your commit messages more dramatic, and create a commit history worth showing off to your fellow developers. Remember, version control can be fun and empowering! Happy coding and history-tidying, my friends! 🚀🌈👨💻📜&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Don't be a Frameworker, Be an Engineer</title>
      <dc:creator>Balamurugan D</dc:creator>
      <pubDate>Mon, 23 Oct 2023 18:22:54 +0000</pubDate>
      <link>https://dev.to/balamurugan16/dont-be-a-frameworker-be-an-engineer-ce8</link>
      <guid>https://dev.to/balamurugan16/dont-be-a-frameworker-be-an-engineer-ce8</guid>
      <description>&lt;p&gt;📣 Hey everyone! I came across some interesting advice on the internet a few months back, and I've been trying to follow it ever since. Today, I want to share it with all of you. The advice is simple: &lt;strong&gt;"Don't be a Frameworker, Be an Engineer."&lt;/strong&gt; 🛠👩💻&lt;/p&gt;

&lt;p&gt;But what does that really mean? Let me explain using my own experience. In my day job, I work with JavaScript frameworks like React and NestJS, which is cool. 🚀 However, because I spend most of my time in these frameworks, I started calling myself a "React Developer" on LinkedIn. 📋 But here's the thing: a software engineer should be open to learning and technology as needed. 🌐 It's all about having the right mindset.&lt;/p&gt;

&lt;p&gt;There are a couple of reasons why some people get stuck in the "Frameworker" mindset. First, folks don't want to invest time in learning something new when they're already getting the job done with what they know. 🕒 Second, job titles often specify things like "Full Stack Java Developer" or ".Net Developer," which can make you feel locked into a specific technology. 🧱 But remember, the basics of programming are pretty much the same across the board.&lt;/p&gt;

&lt;p&gt;Imagine your organization decides to switch from TypeScript to Go for microservices (a great move for better performance). If you have the right mindset, you'd gladly say YES! Learning a new language isn't as hard as you might think. 🧠 The fundamental programming concepts like conditionals, loops, and functions remain constant. Adapting to a new syntax is a piece of 🍰.&lt;/p&gt;

&lt;p&gt;If you firmly believe you're only a "React Developer" or an "Angular Developer" and can't step out of that box, well, good luck! 🍀 What if the framework you've mastered becomes obsolete one day? The main goal of a software engineer is to solve problems effectively using the right tools. While React is fantastic for building user interfaces, there are more performance-focused alternatives out there. For instance, when building a blog site, choosing a framework like Astro or Gatsby might make more sense. 🚀📝&lt;/p&gt;

&lt;p&gt;I got this amazing advice from a YouTuber named ThePrimeagen, and it's been a game-changer for me. I've started learning Go and coding in it outside of my day job where I mainly use TypeScript. It's a fun and rewarding practice, and I wish I'd understood this mindset earlier in my career. 🚀🧡&lt;/p&gt;

&lt;p&gt;So, I encourage all of you to be open to working with any technology and focus on problem-solving rather than getting too attached to a particular language or framework. 🌟🚀&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to 🙈 Screw up as a Programmer?</title>
      <dc:creator>Balamurugan D</dc:creator>
      <pubDate>Thu, 19 Oct 2023 18:20:17 +0000</pubDate>
      <link>https://dev.to/balamurugan16/how-to-screw-up-as-a-programmer-1655</link>
      <guid>https://dev.to/balamurugan16/how-to-screw-up-as-a-programmer-1655</guid>
      <description>&lt;p&gt;We learn anything by trial and error, at least I learned anything that way. But making mistakes will have its own cost, If you make a syntax error that gives a runtime error, you can simply correct the syntax by seeing the error message, But what if you make a mistake that brings down production or something similar which could lead to escalation and other corporate dramas? Those are human errors that are bound to happen and programmers do make these mistakes. There are a lot of horror stories where a faulty algorithm turned out to be looping infinitely to generate a bill of $72,000 from GCP! This is a real story and to know about this &lt;a href="https://blog.tomilkieway.com/72k-1/"&gt;read this article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So what I mean is programmers do make mistakes, of course, I am not encouraging you to go write bad code that will make catastrophic things, but the experiences of these mistakes will help you to be more cautious. I will share some of these experiences that I had that took the soul out of my body for a few hours. 😱&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Huge bill from AWS! 💸&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Even I got a hefty bill of $40 from AWS. This was when I was in my final year of college where I hosted one Flask API in an AWS EC2 instance for my final year project. Everything was fine until I got the bill. Turns out I have to shut down and deallocate the instance once my job is done! Actually, that statement is so lame to say today but at that time, I had that realization the hard way. I didnt have the money, what do you expect from a student, 40 dollars? are you kidding me? My parents let me stay in their home for free and I was grateful for that. So anyway I went and deactivated my AWS account so that I could avoid the fee. 😅&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5dANdW78--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1697739413027/af8b09a2-7a70-4454-96df-6f569164367b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5dANdW78--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1697739413027/af8b09a2-7a70-4454-96df-6f569164367b.png" alt="" width="800" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Kaboom! The code is gone 🙀&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;So this happened very recently, I was in a new team as a frontend developer and had a task to work on. So I created a branch, worked on it created a PR myself and self-approved it. I self-approved it because 1. I cant directly push to the branch because of the branch protection rules, and 2. I was not informed that the code review activity had started because the project was new and those setups were not in place yet. So my newly appointed team lead asked me to revert my PR and get it reviewed. So I did that, in that process, I accidentally reverted one particular merge commit which contained the code of 7 other developers! Yes, SEVEN! I casually reverted the PR and submitted it for review and within 30 minutes, I received escalation emails, and multiple calls from my scrum master, leads and members saying that my recent revert had created chaos. I cant frame this as an honest mistake because in git, reverting changes is always a tricky task in a collaborative space where other people also push code. So I took the blame and reverted the commit that reverted my merge! Git was a blessing and a curse here, It put me through a nightmare and helped me to come out of it. 😬&lt;/p&gt;

&lt;p&gt;So those are 2 among a lot of incidents where I screwed up. I dont feel the shy in sharing my failures because It is part. I will share this post on LinkedIn where most people will only post their successes. For me, these failures shaped me as a programmer. And actually, I didnt come up with any content so posted this article to fill the gap. Until next time! 😅👍&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Styling React Components</title>
      <dc:creator>Balamurugan D</dc:creator>
      <pubDate>Mon, 16 Oct 2023 17:35:27 +0000</pubDate>
      <link>https://dev.to/balamurugan16/styling-react-components-i2</link>
      <guid>https://dev.to/balamurugan16/styling-react-components-i2</guid>
      <description>&lt;p&gt;Personally, for me, I dont like to style. I mean, I dont hate CSS and styling but I hate when I give styling a try and It looks bad.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s9MbWDK8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://programmerhumor.io/wp-content/uploads/2021/06/programmerhumor-io-programming-memes-frontend-memes-8ec7b8ad89d906d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s9MbWDK8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://programmerhumor.io/wp-content/uploads/2021/06/programmerhumor-io-programming-memes-frontend-memes-8ec7b8ad89d906d.png" alt="CSS SUCKS | programming-memes, css-memes, program-memes, cs-memes | ProgrammerHumor.io" width="568" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Anyway, I dont have to emphasize the importance of styling, If your users need to stay in your app, then the app should look good. Unlike the dating culture, in web development &lt;strong&gt;Looks do matter!&lt;/strong&gt; (Just Kidding, Looks matter in dating as well! 😂).&lt;/p&gt;

&lt;p&gt;In this article, I will share 5 different ways to style react components so that you can choose the approach that suits you when you develop your application.&lt;/p&gt;

&lt;p&gt;But first of all, why should you know all the different ways to style, you may ask! Isnt knowing one approach enough? Yeah but No. First of all, it is easy to take consistency for granted. Because in a large codebase, developers should be aware of the styling approaches, and should not go with the approach that they are familiar with. So knowing the other approaches exist will keep you ready to tackle any situation.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The &lt;code&gt;style&lt;/code&gt; attribute
&lt;/h2&gt;

&lt;p&gt;In react, you either write the inline styles using the &lt;code&gt;style&lt;/code&gt; attribute.&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;div 
  style={{
    display: "flex", 
    justifyContent: "center", 
    alignItems: "center" 
  }}&amp;gt;
  &amp;lt;h1&amp;gt;Hi Mom!&amp;lt;/h1&amp;gt;
&amp;lt;/div&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;As you can see, this approach has a few problems, if the CSS properties count increases, then the component will be bloated with a bunch of CSS. Reusability is not an option and for inline CSS the specificity is also high so If you already have some styles, the inline styles will most probably take precedence!&lt;/p&gt;

&lt;h2&gt;
  
  
  2. CSS or Sass
&lt;/h2&gt;

&lt;p&gt;You can also have your styles in a separate stylesheet and import that into the component. This provides the benefits of using either the CSS or Sasss features like nesting, variables, mixins and so on. I like this approach and I will never be against this one, the only thing is there are more modern approaches that solve the problem better. But if you prefer this approach then you can very well go with this.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. CSS in JS
&lt;/h2&gt;

&lt;p&gt;Initially, I didnt like this approach but when I started to use this, this was a game changer. Essentially there are libraries like styled-components that let us write styles in a normal CSS way and also give additional features like nesting, conditional styling and so on, and produce a react wrapper component out of the styles that we define. This approach is really useful because you can organize your styled react components better. Look at the following example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const App = () =&amp;gt; {
  return (
    &amp;lt;Wrapper&amp;gt;
      &amp;lt;h1&amp;gt;Hi Mom!&amp;lt;/h1&amp;gt;
    &amp;lt;/Wrapper&amp;gt;
  );
};

const Wrapper = styled.div`
  display: flex;
  justify-content: center;
  align-items: center
`

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

&lt;/div&gt;



&lt;p&gt;So here, notice the way I have written the CSS. Yes the API that this library gives is a bit weird but you will get used to it in no time. This is a better way to write CSS directly in a JavaScript file. If you are using VS Code, install the styled-components extension, this gives better syntax highlighting and auto-complete support which will be handy!&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Tailwind CSS
&lt;/h2&gt;

&lt;p&gt;Tailwind is by far the best and most modern approach for styling. Tailwinds approach is to provide utility classes for your known CSS properties like &lt;code&gt;flex&lt;/code&gt; means &lt;code&gt;display:flex&lt;/code&gt; and so on. This will let you quickly style your components and not worry about naming the class or id to style your components. Sometimes your class names can become a nightmare but there are ways to come around that as well. Tailwind provides customization as well with the &lt;code&gt;tailwind.config.js&lt;/code&gt; file where essentially you can configure your typography, colors and so on. Look at the following example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const App = () =&amp;gt; {
  return (
    &amp;lt;div className="flex justify-center items-center"&amp;gt;
      &amp;lt;h1&amp;gt;Hi Mom!&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;p&gt;As you can see, it is intuitive and easy. Developers can quickly style the components. If you are using VS Code install the tailwind extension for auto-complete support. It will be very useful.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Component Library
&lt;/h2&gt;

&lt;p&gt;The final approach is going with a component library. Component libraries come with pre-styled components reducing our work. There are several libraries out there like MUI, Daisy UI, Chakra UI and so on. Usually, component libraries come with a built-in opinionated way of styling, for example, MUI comes with styled-components for styling and Daisy UI is built on top of Tailwind CSS. This way, you get pre-styled components and a way to add styles on top of them.&lt;/p&gt;

&lt;p&gt;To conclude, now you know 5 different ways to style react components. Next time you can pitch the approach to your seniors which will give you a good impression with your colleagues. Trust me, you can pick up girls if you know CSS! (Just kidding, programming nerds can never get girls by exposing that they are programmers!)&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Singleton Pattern</title>
      <dc:creator>Balamurugan D</dc:creator>
      <pubDate>Thu, 12 Oct 2023 17:29:51 +0000</pubDate>
      <link>https://dev.to/balamurugan16/singleton-pattern-4jjj</link>
      <guid>https://dev.to/balamurugan16/singleton-pattern-4jjj</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tFc0ubj1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://programmerhumor.io/wp-content/uploads/2021/07/programmerhumor-io-programming-memes-f98afcf6e4b8b5b-608x344.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tFc0ubj1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://programmerhumor.io/wp-content/uploads/2021/07/programmerhumor-io-programming-memes-f98afcf6e4b8b5b-608x344.jpg" alt="Factory produced more than one instance of Singleton | ProgrammerHumor.io" width="608" height="361"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;People who understood the above picture dont need to read this article, you already understood the pattern but those who didnt get it, stay tuned to where I will explain it at the end.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The most popular pattern, and usually the pattern that is covered first when the topic of design patterns comes is the &lt;strong&gt;Singleton pattern&lt;/strong&gt;. The idea here is to share a single global instance throughout the application. I will first explain how this pattern works and will share my thoughts on this pattern because I feel that this pattern should be an anti-pattern rather than a design pattern.&lt;/p&gt;

&lt;h3&gt;
  
  
  Overview
&lt;/h3&gt;

&lt;p&gt;So with the Singleton pattern, basically we restrict the information of certain classes to one single immutable object that can be accessed globally throughout the application. For example, we can have a counter instance with methods like &lt;code&gt;increment&lt;/code&gt;, &lt;code&gt;decrement&lt;/code&gt; and &lt;code&gt;currentCount&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The increment method increments the value of the counter by 1. Any time this method is called anywhere in the application, it affects the single instance of the counter that has been created. This makes sure that there is only a Single source of truth.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mo1h2oz3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1697131612739/613a12c6-1357-41fe-b0a1-49bc94a13346.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mo1h2oz3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1697131612739/613a12c6-1357-41fe-b0a1-49bc94a13346.png" alt="" width="800" height="493"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Implementation:
&lt;/h3&gt;



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

class Counter {
  constructor() {
    if (instance) {
      throw new Error("You can only create one instance!");
    }
    this.counter = counter;
    instance = this;
  }

  getCount() {
    return this.counter;
  }

  increment() {
    return ++this.counter;
  }

  decrement() {
    return --this.counter;
  }
}

const singletonCounter = Object.freeze(new Counter());

export default singletonCounter;

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

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Creating the &lt;code&gt;Counter&lt;/code&gt; class, which contains a &lt;code&gt;constructor&lt;/code&gt;, &lt;code&gt;getInstance&lt;/code&gt;, &lt;code&gt;getCount&lt;/code&gt;, &lt;code&gt;increment&lt;/code&gt; and &lt;code&gt;decrement&lt;/code&gt; method. Within the constructor, we check to make sure the class hasn't already been instantiated.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Setting a variable equal to the frozen newly instantiated object, by using the built-in &lt;code&gt;Object.freeze&lt;/code&gt; method. This ensures that the newly created instance is not modifiable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Exporting the variable as the &lt;code&gt;default&lt;/code&gt; value within the file to make it globally accessible.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Is it an Anti Pattern?
&lt;/h3&gt;

&lt;p&gt;One of the most overused patterns in the programming industry is the singleton pattern. This is my opinion and always anyone can have any opinions. I couldnt think of any use case for this pattern because of the hidden tradeoffs that it has. What do I mean by it? This pattern surely gives an advantage by restricting the instantiation of multiple instances and saving memory but at the same time, This pattern gives short-term simplicity by giving up long-term scalability and maintainability. When It comes to unit testing, since we cant create new instances each time, all tests rely on the modification to the global instance of the previous test. The order of the test matters in this case, and one small modification can lead to an entire test suite failing. In JavaScript, ES modules are by default singletons, meaning we not need to create singleton to achieve this behavior.&lt;/p&gt;

&lt;p&gt;Sure it has a great use case, for example, for state management, the Redux library has a store that follows the singleton pattern, one instance of the store is available throughout the runtime of the application which makes an excellent use case of the singleton pattern. Redux also uses the observer pattern by allowing to subscribe to the store to get the values. To know more about observer patterns, &lt;a href="https://dev.to/balamurugan16/observer-pattern-1eii"&gt;read this article&lt;/a&gt;.&lt;/p&gt;

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

&lt;p&gt;The motive of this article is not to trash talk about the Singleton pattern, but to explain the pattern itself and to analyze whether a particular pattern is useful. My opinions are totally against the singleton pattern but you may find some good use case for it. Singleton pattern can be a great tool for some libraries like Redux but not in a real-world application.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The image above has multiple instances of singletons!&lt;/p&gt;
&lt;/blockquote&gt;

</description>
    </item>
    <item>
      <title>Smart and Dumb React components</title>
      <dc:creator>Balamurugan D</dc:creator>
      <pubDate>Mon, 09 Oct 2023 17:49:09 +0000</pubDate>
      <link>https://dev.to/balamurugan16/smart-and-dumb-react-components-4mnn</link>
      <guid>https://dev.to/balamurugan16/smart-and-dumb-react-components-4mnn</guid>
      <description>&lt;p&gt;React is the popular choice in the web development community to build UI. It leverages the concept of components where the UI will be broken down into individual, reusable chunks. When this idea came out, it was revolutionary, and still it is. React is unopinionated as well, meaning that there are no enforcements like Angular. Unopinionated approaches often tend to be exploited rather than leveraged. In React, the component hierarchy is very important because it ensures readability and the code base can be easily scaled, managed and unit-tested. Keeping that point in mind, In this article we will cover one of the underrated approaches to architecture components in React.&lt;/p&gt;

&lt;p&gt;Smart and Dumb components (also known as container/presentation pattern) is an approach where the Dumb components take care of how the data is shown (UI) and the Smart components take care of the business logic and handle external dependencies and side effects like API requests etc.&lt;/p&gt;

&lt;p&gt;So we will build a basic Todo App in this example to explain this pattern. Here the &lt;code&gt;TodoList.js&lt;/code&gt; and &lt;code&gt;TodoForm.js&lt;/code&gt; are Dumb components and the &lt;code&gt;App.js&lt;/code&gt; is the smart component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// TodoList.js
import React from 'react';
import { Todo } from '../store/todo.slice';

function TodoList({ todos, deleteTodo }) {
  return (
    &amp;lt;ul&amp;gt;
      {todos.map((todo) =&amp;gt; (
        &amp;lt;li key={todo.id}&amp;gt;
          &amp;lt;p&amp;gt;{todo.text}&amp;lt;/p&amp;gt;
          &amp;lt;button
            onClick={() =&amp;gt; deleteTodo(todo.id)}
            data-testid={`todo-${todo.id}`}
          &amp;gt;
            Delete
          &amp;lt;/button&amp;gt;
        &amp;lt;/li&amp;gt;
      ))}
    &amp;lt;/ul&amp;gt;
  );
}

export default TodoList;


// TodoForm.js
import React, { useState } from 'react';

function TodoForm({ addTodo }) {
  const [inputText, setInputText] = useState('');

  const handleSubmit = (e) =&amp;gt; {
    e.preventDefault();
    if (inputText.trim() !== '') {
      addTodo(inputText);
      setInputText('');
    }
  };

  return (
    &amp;lt;form onSubmit={handleSubmit} className="flex gap-2"&amp;gt;
      &amp;lt;input
        placeholder="Add a To-Do"
        value={inputText}
        onChange={(e) =&amp;gt; setInputText(e.target.value)}
      /&amp;gt;
      &amp;lt;button type="submit"&amp;gt;Add&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  );
}

export default TodoForm;


import React from 'react';
import { useDispatch, useSelector } from './store';
import { addTodo, deleteTodo } from './todo.slice';
import TodoForm from './TodoForm';
import TodoList from './TodoList';

function TodoApp() {
  const todos = useSelector((state) =&amp;gt; state.todoSlice);
  const dispatch = useDispatch();

  const handleAddTodo = (text: string) =&amp;gt; {
    dispatch(addTodo(text));
  };

  const handleDeleteTodo = (id: number) =&amp;gt; {
    dispatch(deleteTodo(id));
  };

  return (
    &amp;lt;div className="w-full flex justify-center flex-col h-full items-center"&amp;gt;
      &amp;lt;TodoForm addTodo={handleAddTodo} /&amp;gt;
      &amp;lt;TodoList todos={todos} deleteTodo={handleDeleteTodo} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default TodoApp;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iyW5UUG5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1696873610651/278b9498-4fef-4ffd-b822-9e85c65b84de.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iyW5UUG5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1696873610651/278b9498-4fef-4ffd-b822-9e85c65b84de.png" alt="" width="800" height="421"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you look closely, The &lt;code&gt;TodoList.js&lt;/code&gt; and the &lt;code&gt;TodoForm.js&lt;/code&gt; components are called pure functions, which means that given an input, the component will only render one output, which usually can be achieved when there are no external dependencies for the component. In the &lt;code&gt;App.js&lt;/code&gt;, takes care of dealing with the Redux store and provides the functionality to the dumb components via props. As you can see, the &lt;code&gt;addTodo&lt;/code&gt; and &lt;code&gt;deleteTodo&lt;/code&gt; functions are defined in the smart component and passed to the dumb components.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The dumb components can be &lt;strong&gt;reused&lt;/strong&gt; throughout the application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Easily enforcing separations of concern like the UI will be handled in the dumb components and the business logic will be handled in the Smart components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Testing dumb components will be very easy as they are pure functions and there will be no need to mock any libraries or external dependencies which reduces a lot of effort.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the above example, considering that you have implemented unit testing for &lt;code&gt;TodoList.js&lt;/code&gt;, &lt;code&gt;TodoForm.js&lt;/code&gt;, and the &lt;code&gt;todo.slice.js&lt;/code&gt;, the main &lt;code&gt;App.js&lt;/code&gt; technically doesnt need to be unit tested because if you look closely, all the parts of the code are already tested individually, so ultimately you will get the confidence that your application will work.&lt;/p&gt;

&lt;h3&gt;
  
  
  Disadvantages:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The same approach can also be implemented using Hooks. The business logic can be wrapped in a custom hook and all the components can be kept as dumb components. For me, a mix of both approaches will work fine.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This approach can be an overkill for a smaller application.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Higher order components in React</title>
      <dc:creator>Balamurugan D</dc:creator>
      <pubDate>Thu, 05 Oct 2023 18:09:30 +0000</pubDate>
      <link>https://dev.to/balamurugan16/higher-order-components-in-react-5e4e</link>
      <guid>https://dev.to/balamurugan16/higher-order-components-in-react-5e4e</guid>
      <description>&lt;p&gt;Any developer trying to attend a React interview will come across the question What are HOCs? from their interviewer, and this question will give the notion to the interviewer whether you are a good front-end engineer specializing in React. Following my previous article on Higher-order functions, we will look at Higher-order Component patterns in React with some examples.&lt;/p&gt;

&lt;p&gt;Lets say you have some reusable logic that you want to use across all your components, there are several patterns to achieve that and one such pattern is the HOC pattern. Look at the following example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function withCenterStyling(Element) {
    return (props) =&amp;gt; {
        const styles = {
            display: "flex",
            alignItems: "center",
            justifyContent: "center"
        }
        return &amp;lt;Element {...props} styles={styles} /&amp;gt;;
    }
}

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

&lt;/div&gt;



&lt;p&gt;Here, the &lt;code&gt;withCenterStyling&lt;/code&gt; is a HOC, what it does is that it takes another React Functional component and returns a new overridden functional component.&lt;/p&gt;

&lt;p&gt;💡&lt;/p&gt;

&lt;p&gt;A functional component is nothing but a function that returns some HTML which is referred to as JSX.&lt;/p&gt;

&lt;p&gt;So the &lt;code&gt;withCenterStyling&lt;/code&gt; component can be reused for any component that requires a center alignment, which promotes code reusability. This is Higher order Components, Simple!&lt;/p&gt;

&lt;p&gt;But that example is very basic, lets take another example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// imagine there is a loading spinner component existing
import Loading from "./Loading.tsx";

function withLoader({ Element, url }) {
    return (props) =&amp;gt; {
        const [data, setData] = useState(null);

        async function loadData() {
            const jsonData = await fetch(url);
            const response = await jsonData.json();
            setData(response);
        }

        useEffect(() =&amp;gt; {
            loadData();
        }, [])

        if (!data) return &amp;lt;Loading /&amp;gt;;

        return &amp;lt;Element {...props} data={data} /&amp;gt;;
    }
}

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

&lt;/div&gt;



&lt;p&gt;Uff! That is a lot of code but lets break it down. As you know by now, a HOC will take in a react component and return another react component. So here, the &lt;code&gt;withLoader&lt;/code&gt; will take in a component and a URL. So the idea here is that the data will be fetched from the provided URL and the fetched data will be passed to the component. During the fetching time, a small loading spinner should be displayed. This will be very useful because showing Loading progress while fetching data is such a common activity.&lt;/p&gt;

&lt;p&gt;So here the higher-order component is doing the data fetching and conditionally shows the loading spinner if the data is not yet received! See, Its that simple.&lt;/p&gt;

&lt;p&gt;So this is HOC in React. It will be really useful when the React Component Architecture is well maintained. HOCs can also be incrementally added to an existing codebase so If you want to impress your team lead or colleagues, explain this concept, take up the refactoring task, implement HOCs and break the UI in the production! All the best!!!!!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Higher-order functions in JavaScript</title>
      <dc:creator>Balamurugan D</dc:creator>
      <pubDate>Mon, 02 Oct 2023 16:31:30 +0000</pubDate>
      <link>https://dev.to/balamurugan16/higher-order-functions-in-javascript-2d6j</link>
      <guid>https://dev.to/balamurugan16/higher-order-functions-in-javascript-2d6j</guid>
      <description>&lt;p&gt;This blog focuses on Higher-order functions, what problem it solves, and how to use them in your daily life as a JavaScript developer. JavaScript already has a lot of built-in higher-order functions like &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;forEach&lt;/code&gt;, &lt;code&gt;reduce&lt;/code&gt;, etc. But how they work internally is fun to know and learn and this is a pretty common interview question, (Trust me! It is). This is not that graph data structure that you learned for your interview and never used anywhere in the real world, HOF (higher-order functions) are the foundation for the higher-order components that you see in React!&lt;/p&gt;

&lt;p&gt;So lets dive in!&lt;/p&gt;

&lt;p&gt;Before dealing with HOF, In JavaScript a function is like any other value, it can be stored in a variable, passed as an argument, and so on. See the below example!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const onClick = (e) =&amp;gt; {
    console.log(e.target.value);
}

let array = [1,2,3];
array.forEach((value) =&amp;gt; {
    console.log(value);
})

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

&lt;/div&gt;



&lt;p&gt;In the above example, notice that I am declaring the function as a variable, with the const keyword. The second example &lt;code&gt;forEach&lt;/code&gt; is a function that is receiving another function as an argument! This knowledge is key to understanding HOF!&lt;/p&gt;

&lt;p&gt;So we will start with a function and try to optimize it until we understand HOF! See the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function doubleTheArray(input: number[]) {
    const output = [];
    for (let i = 0; i &amp;lt; input.length; i++) {
        output.push(input[i] * 2)
    }
    return output;
}

function tripleTheArray(input: number[]) {
    const output = [];
    for (let i = 0; i &amp;lt; input.length; i++) {
        output.push(input[i] * 3)
    }
    return output;
}

function quadrupleTheArray(input: number[]) {
    const output = [];
    for (let i = 0; i &amp;lt; input.length; i++) {
        output.push(input[i] * 4)
    }
    return output;
}

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

&lt;/div&gt;



&lt;p&gt;So here, I have 3 functions that receive an array, do a manipulation to the array, and return a new array. The outputs of all these functions will look like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jJhQb_aD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1696264182744/a6115454-8302-41f4-9073-9d9e89f01951.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jJhQb_aD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1696264182744/a6115454-8302-41f4-9073-9d9e89f01951.png" alt="" width="800" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you look closely, all the functions are basically having the same code except the logic that we use inside the &lt;code&gt;output.push()&lt;/code&gt; function. So now lets optimize this code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function manipulateArray(input: number[], callback: (value: number) =&amp;gt; number) {
    const output = [];
    for (let i = 0; i &amp;lt; input.length; i++) {
        output.push(callback(input[i]))
    }
    return output;
}

const output1 = manipulateTheArray([1,2,3], (a) =&amp;gt; a * 2)
const output2 = manipulateTheArray([1,2,3], (a) =&amp;gt; a * 3)
const output3 = manipulateTheArray([1,2,3], (a) =&amp;gt; a * 4)

console.log(output1, output2, output3)

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

&lt;/div&gt;



&lt;p&gt;If you see here in this example, The code that is varying in all three functions is replaced with a function call. Now the user can decide what to do with the array elements rather than having 3 different functions for a particular use case. In this example, I am passing a function that takes a number and manipulates it. Now If I want the array elements to be multiplied by 5 I can use the same &lt;code&gt;manipulateArray&lt;/code&gt; function instead of writing a whole new function. This follows the DRY principle (Dont repeat yourself).&lt;/p&gt;

&lt;p&gt;If you look closely, the &lt;code&gt;.map&lt;/code&gt; function does exactly the same. Let me rewrite the above example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array = [1,2,3]

const output = array.map((a) =&amp;gt; a * 3)

console.log(output);

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

&lt;/div&gt;



&lt;p&gt;Whatever we wrote previously is already available in JavaScript as a higher-order function. &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;forEach&lt;/code&gt;, and &lt;code&gt;reduce&lt;/code&gt; are methods that are used quite frequently and now you can use them without any confusion as you know how they work under the hood.&lt;/p&gt;

&lt;p&gt;This is called a higher-order function. A higher-order function is a function that accepts functions as parameters and/or returns a function. We didnt cover the returning a function part which will be covered when we deal with Higher order components in React (A react component is basically a function!). Until then, Tata!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
