<?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: Mary Okafor</title>
    <description>The latest articles on DEV Community by Mary Okafor (@okafor__mary).</description>
    <link>https://dev.to/okafor__mary</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%2F1067944%2F473529ae-92b4-4e72-9c5d-53b37f69a134.jpg</url>
      <title>DEV Community: Mary Okafor</title>
      <link>https://dev.to/okafor__mary</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/okafor__mary"/>
    <language>en</language>
    <item>
      <title>How to Dynamically Add Input Fields on Button Click in ReactJs</title>
      <dc:creator>Mary Okafor</dc:creator>
      <pubDate>Tue, 12 Sep 2023 14:17:01 +0000</pubDate>
      <link>https://dev.to/okafor__mary/how-to-dynamically-add-input-fields-on-button-click-in-reactjs-5298</link>
      <guid>https://dev.to/okafor__mary/how-to-dynamically-add-input-fields-on-button-click-in-reactjs-5298</guid>
      <description>&lt;p&gt;This article focuses on the topic of dynamically adding and removing input fields with a button click. This feature allows users to add more input fields as needed, enhancing the flexibility and usability of forms and data collection processes. This tutorial will guide you on how to successfully add and remove dynamic input fields from your applications.&lt;/p&gt;

&lt;p&gt;We will be displaying two input fields and also adding two buttons to dynamically add or delete the fields.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Create A React Component&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let's start by creating a react component that will contain the input fields. You can create a new component or edit an existing one by adding 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;import { useState } from "react";

export default function AddDynamicInputFields() {
  const [inputs, setInputs] = useState([{ firstName: "", lastName: "" }]);

  const handleAddInput = () =&amp;gt; {
    setInputs([...inputs, { firstName: "", lastName: "" }]);
  };

  const handleChange = (event, index) =&amp;gt; {
    let { name, value } = event.target;
    let onChangeValue = [...inputs];
    onChangeValue[index][name] = value;
    setInputs(onChangeValue);
  };

  const handleDeleteInput = (index) =&amp;gt; {
    const newArray = [...inputs];
    newArray.splice(index, 1);
    setInputs(newArray);
  };


  return (
    &amp;lt;div className="container"&amp;gt;
      {inputs.map((item, index) =&amp;gt; (
        &amp;lt;div className="input_container" key={index}&amp;gt;
          &amp;lt;input
            name="firstName"
            type="text"
            value={item.firstName}
            onChange={(event) =&amp;gt; handleChange(event, index)}
          /&amp;gt;
          &amp;lt;input
            name="lastName"
            type="text"
            value={item.lastName}
            onChange={(event) =&amp;gt; handleChange(event, index)}
          /&amp;gt;
          {inputs.length &amp;gt; 1 &amp;amp;&amp;amp; (
            &amp;lt;button onClick={() =&amp;gt; handleDeleteInput(index)}&amp;gt;Delete&amp;lt;/button&amp;gt;
          )}
          {index === inputs.length - 1 &amp;amp;&amp;amp; (
            &amp;lt;button onClick={() =&amp;gt; handleAddInput()}&amp;gt;Add&amp;lt;/button&amp;gt;
          )}
        &amp;lt;/div&amp;gt;
      ))}

      &amp;lt;div className="body"&amp;gt; {JSON.stringify(inputs)} &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;First, we initialized the &lt;code&gt;inputs&lt;/code&gt; state variable as an array containing an object that has “firstName” and “lastName” properties, both initially set to an empty string. We would be using this state to update and manage our input field values.&lt;/p&gt;

&lt;p&gt;We used the &lt;code&gt;setInputs&lt;/code&gt; function to update the inputs state variable. &lt;code&gt;...inputs&lt;/code&gt; we used the spread operator to make a shallow copy of the inputs array, which creates a new array with the same values as the previous ones.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;handleChange&lt;/code&gt; function is used to update the value of a specific input field in an array of input fields based on the user’s input. It makes use of the &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;value&lt;/code&gt; properties of the event object to identify which input fields to update and what values to assign to them.  This function takes in two parameters;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Event :  an event object that is triggered by a change in the input fields.&lt;/li&gt;
&lt;li&gt;Index: An index value that represents the position of the input field in an array of input fields.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code&gt;handleDeleteInput&lt;/code&gt; function receives one parameter &lt;code&gt;index&lt;/code&gt;, which represents the index of the input field to be deleted from a copy of the &lt;code&gt;inputs&lt;/code&gt; array. Afterwards, it updates the state with the modified array.&lt;/p&gt;

&lt;p&gt;We use the map function to iterate over the &lt;code&gt;inputs&lt;/code&gt; array and render elements for each input field and its associated buttons.  For each item in the inputs array, we create a &lt;code&gt;&amp;lt;div className="input_container"&amp;gt;&lt;/code&gt; element containing two input fields for firstName and lastName.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; {inputs.length &amp;gt; 1 &amp;amp;&amp;amp; (
   &amp;lt;button onClick={() =&amp;gt; handleDeleteInput(index)}&amp;gt;Delete&amp;lt;/button&amp;gt;
 )}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The conditional rendering from the code block above checks if the &lt;code&gt;inputs&lt;/code&gt; array contains more than one input field; if it does, it displays the delete button.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{index === inputs.length - 1 &amp;amp;&amp;amp; (
    &amp;lt;button onClick={() =&amp;gt; handleAddInput()}&amp;gt;Add&amp;lt;/button&amp;gt;
)}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the code block above, the conditional rendering checks if the current “index” matches the last input field in the “inputs” array, and if it does, it displays the “add” button.&lt;/p&gt;

&lt;h2&gt;
  
  
  Render The Component
&lt;/h2&gt;

&lt;p&gt;Next, we can render the component we created earlier, AddDynamicInputFields, in our main application file (App.js).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import AddDynamicInputFields from "./AddInputFields";
import "./styles.css";

export default function App() {
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h1&amp;gt;Dynamically add input fields&amp;lt;/h1&amp;gt;
      &amp;lt;AddDynamicInputFields /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Styling
&lt;/h2&gt;

&lt;p&gt;Your input fields and buttons can be styled using CSS or a UI framework like Tailwind CSS. Feel free to modify your styling to fit your application’s designs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test Your Application
&lt;/h2&gt;

&lt;p&gt;Thats it! You can use “npm start” or your preferred way to start your React application. Now you can add and delete input fields dynamically.&lt;/p&gt;

&lt;p&gt;You can find the tutorial repo in this &lt;a href="https://codesandbox.io/s/how-to-dynamically-add-input-fields-by-button-clicl-3jqtww"&gt;codesandbox&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please let me know if this post was helpful by leaving a comment or reaction.&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>react</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Simplifying Code with Event Delegation in Your Javascript Applications</title>
      <dc:creator>Mary Okafor</dc:creator>
      <pubDate>Tue, 25 Apr 2023 21:02:34 +0000</pubDate>
      <link>https://dev.to/okafor__mary/simplifying-code-with-event-delegation-in-your-javascript-applications-204n</link>
      <guid>https://dev.to/okafor__mary/simplifying-code-with-event-delegation-in-your-javascript-applications-204n</guid>
      <description>&lt;p&gt;One of the important features of Javascript is event handling, which allows for user interaction with web pages. As web applications become more complex, event handling can become nerve-racking. This is where event delegation comes into play as a technique to optimize event handling. In this article, we will explore the concept of event delegation, its benefits, and how to implement it in your code.&lt;/p&gt;

&lt;p&gt;Event delegation is simply a method of handling multiple elements' events with a single event listener. Instead of adding an event listener to each element, the event listener is added to the parent element, which listens for events that are triggered by the child element.&lt;/p&gt;

&lt;p&gt;Let's look at an example with and without event delegation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"buttons"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"button_sub"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Subtract&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"button_reset"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Reset&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"button_add"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Add&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above, we have three &lt;code&gt;button&lt;/code&gt; elements. You may add the necessary &lt;code&gt;click&lt;/code&gt; event handlers for each button to handle the &lt;code&gt;click&lt;/code&gt; event:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;addButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(.&lt;/span&gt;&lt;span class="nx"&gt;button_add&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;addButton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Add button was clicked&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;subtractButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(.&lt;/span&gt;&lt;span class="nx"&gt;button_sub&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;addButton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Subtract button was clicked&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;resetButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(.&lt;/span&gt;&lt;span class="nx"&gt;button_reset&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;addButton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Reset button was clicked&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Having numerous event handlers on a page can have a negative effect on the application, which includes: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each event listener is a function, which is also an object that takes up memory, and having too many objects in memory can lead to increased memory usage, which can in turn slow down the application's performance.&lt;/li&gt;
&lt;li&gt;Can make it more challenging to manage and debug your code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;with event delegation&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;buttons&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;button_add&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Add button was clicked&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;button_sub&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Subtract button was clicked&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;button_reset&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Reset button was clicked&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;target&lt;/code&gt; property of the &lt;code&gt;event&lt;/code&gt; object contains information about the actual element receiving the event. On &lt;code&gt;event.target.classList.contains&lt;/code&gt;, we are checking if a specific CSS class is present on the HTML element that triggered the event. &lt;/p&gt;

&lt;p&gt;When you click the &lt;code&gt;button&lt;/code&gt;, the event bubbles up to the &lt;code&gt;div&lt;/code&gt;(parent element), which handles the event.&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefits of Event Delegation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You are able to write cleaner code, and create less event listeners with similar logic.&lt;/li&gt;
&lt;li&gt;Less memory space, better performance.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;To sum it all up, event delegation is an effective method that can significantly improve the performance of your web applications. While it may require some initial effort to set-up, the benefits can be substantial in the long run, especially for complex web applications. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>frontend</category>
      <category>learning</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>The Pros and Cons of Monorepos</title>
      <dc:creator>Mary Okafor</dc:creator>
      <pubDate>Wed, 19 Apr 2023 17:35:16 +0000</pubDate>
      <link>https://dev.to/okafor__mary/the-pros-and-cons-of-monorepos-591e</link>
      <guid>https://dev.to/okafor__mary/the-pros-and-cons-of-monorepos-591e</guid>
      <description>&lt;h6&gt;
  
  
  Since I started as a software developer, I have always worked with polyrepos, which used to be the standard way for me to write code. If you want to create a new project, just create a new repository, configure your CI/CD pipelines, and you are done. It is simple to manage, but not until I worked on a contract job and was introduced to a new way to organize codebases: monorepos.
&lt;/h6&gt;




&lt;h6&gt;
  
  
  Monorepo contains multiple projects in a single repository. All projects share the same codebases, dependencies and versioning system.
&lt;/h6&gt;




&lt;h6&gt;
  
  
  A polyrepo is simply the opposite of a monorepo; in a polyrepo, each project has its own repository.
&lt;/h6&gt;

&lt;h6&gt;
  
  
  Let's take a look at some advantages and disadvantages of monorepos;
&lt;/h6&gt;




&lt;h3&gt;
  
  
  Advantages of Monorepos
&lt;/h3&gt;

&lt;h6&gt;
  
  
  1. Better code sharing and reuse: With a monorepo, all code is stored in a single repository, making it easier to share and reuse code across different projects and teams. This can help reduce code duplication and improve development efficiency.
&lt;/h6&gt;

&lt;h6&gt;
  
  
  2. Simplified dependency management: Monorepos provide a centralized location for managing dependencies and versioning across different projects. This can help ensure that all code is using the same versions of dependencies and reduce conflicts.
&lt;/h6&gt;

&lt;h6&gt;
  
  
  3. Improved code consistency: With all code in a single repository, it's easier to enforce coding standards and best practices across different teams and projects. This can help ensure that code is consistent and maintainable over time.
&lt;/h6&gt;

&lt;h6&gt;
  
  
  4. Easier refactoring: Refactoring is simpler when all the code is in one repository, making it simpler to rework and restructure the code as necessary. This can aid in lowering technical debt and enhancing code quality.
&lt;/h6&gt;




&lt;h3&gt;
  
  
  Disadvantages of Monorepos
&lt;/h3&gt;

&lt;h6&gt;
  
  
  1. Git performs poorly while working on complex projects: This challenge begins to show up on large applications with more commits and numerous developers working concurrently every day over the same repository. Given that Git uses a directed acyclic graph (DAG) to describe a project's history, this becomes particularly problematic. Git performance degrades as the history gets longer and more commits are made.
&lt;/h6&gt;

&lt;h6&gt;
  
  
  2. increased learning curve and challenges of inclusivity for newer developers: for a software project to be successful, the inclusion of all developers on the team is crucial. A monorepo structure could seem intimidating to newer developers. They may be unfamiliar with a list of separate projects housed in the same repository and may not know how to make a meaningful contribution. It can also be challenging for newer developers to understand the git history in a monorepo setup.
&lt;/h6&gt;

&lt;h6&gt;
  
  
  3. Access cannot be restricted: Giving fine-grained access control to external contributors or remote teams can be difficult. You must either offer access to the entire codebase or none at all.
&lt;/h6&gt;

&lt;h6&gt;
  
  
  4. Increased build time: The build process takes significantly longer than it would if many projects were built independently since there is so much code in one place.
&lt;/h6&gt;




&lt;h6&gt;
  
  
  By having multiple projects in a single repository, monorepos can simplify code sharing, promote collaboration, and ensure consistency across development environments. However, monorepos also present challenges, such as longer build times and increased complexity, which should be carefully considered when deciding whether to adopt this approach. Understanding the pros and cons of monorepo is crucial to making an informed decision about whether it is the right approach for your software development needs.
&lt;/h6&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>frontend</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
