<?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: Manpreet Singh</title>
    <description>The latest articles on DEV Community by Manpreet Singh (@rathoremanpreet).</description>
    <link>https://dev.to/rathoremanpreet</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%2F596445%2Fd50e31da-894e-4a2d-a2da-ff42a879884a.jpeg</url>
      <title>DEV Community: Manpreet Singh</title>
      <link>https://dev.to/rathoremanpreet</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rathoremanpreet"/>
    <language>en</language>
    <item>
      <title>How to render the lists in ReactJs</title>
      <dc:creator>Manpreet Singh</dc:creator>
      <pubDate>Sun, 14 May 2023 05:48:44 +0000</pubDate>
      <link>https://dev.to/rathoremanpreet/how-to-render-the-lists-in-reactjs-2b9e</link>
      <guid>https://dev.to/rathoremanpreet/how-to-render-the-lists-in-reactjs-2b9e</guid>
      <description>&lt;p&gt;Rendering lists of data is one of the most common tasks in web development. In ReactJS, rendering lists can be done using various approaches. In this blog post, we will explore how to render lists in ReactJS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Method 1: Using for loop
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fruits = ["Apple", "Banana", "Orange"];

const fruitList = [];

for (let i = 0; i &amp;lt; fruits.length; i++) {
  fruitList.push(&amp;lt;li&amp;gt;{fruits[i]}&amp;lt;/li&amp;gt;);
}

return &amp;lt;ul&amp;gt;{fruitList}&amp;lt;/ul&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Method 2: Using Map
&lt;/h2&gt;

&lt;p&gt;Another way to render lists in ReactJS is by using the map method. In this method, we create an array of elements using the map method and then render them on the page.&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"];

return (
  &amp;lt;ul&amp;gt;
    {fruits.map((fruit) =&amp;gt; (
      &amp;lt;li&amp;gt;{fruit}&amp;lt;/li&amp;gt;
    ))}
  &amp;lt;/ul&amp;gt;
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Method 3: Using Array.prototype.reduce()
&lt;/h2&gt;

&lt;p&gt;The reduce method is a powerful tool that can be used to render lists in ReactJS. In this method, we create an array of elements using the reduce method and then render them on the page.&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"];

return (
  &amp;lt;ul&amp;gt;
    {fruits.reduce((accumulator, fruit) =&amp;gt; (
      accumulator.push(&amp;lt;li&amp;gt;{fruit}&amp;lt;/li&amp;gt;), accumulator
    ), [])}
  &amp;lt;/ul&amp;gt;
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this blog post, we have explored the different ways to render lists in ReactJS. Although there are several approaches to achieving this, using a map is the most common and recommended way. Using a map not only simplifies the code but also improves its readability. It is essential to choose the right approach depending on the requirements of your project.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>html</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What is react?</title>
      <dc:creator>Manpreet Singh</dc:creator>
      <pubDate>Fri, 10 Jun 2022 12:30:42 +0000</pubDate>
      <link>https://dev.to/rathoremanpreet/what-is-react-151l</link>
      <guid>https://dev.to/rathoremanpreet/what-is-react-151l</guid>
      <description>&lt;p&gt;Simplest meaning&lt;br&gt;
&lt;strong&gt;A JavaScript library for building user interfaces&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React is a javascript library which is used for building user interfaces. 😎&lt;br&gt;
It contains three important things&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Declarative&lt;/li&gt;
&lt;li&gt;Component-Based&lt;/li&gt;
&lt;li&gt;Learn Once, Write Anywhere&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. Declarative
&lt;/h2&gt;

&lt;p&gt;React makes it painless to create interactive UIs.&lt;/p&gt;

&lt;p&gt;For example: If we want to add a tag to the other tag so we have to write code like this in javascript&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;first, get the id or class name of another tag&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;then put the tag in it with the help of innerHTML&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DpodWWNK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xkbwmnv97qky7ocb3iqp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DpodWWNK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xkbwmnv97qky7ocb3iqp.png" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;but in react we don't need this kind of stuff&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Just create a function like a javascript function&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And return the tag that's it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And everything is maintained by the react.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GGLey3gS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j74a2n0oagv1qk7ln1ar.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GGLey3gS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j74a2n0oagv1qk7ln1ar.png" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you have created the component.&lt;br&gt;
what is a component? we will talk about it in the component section&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Component-Based
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Component means dividing the big UI code into the small UI block of code&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;let's say we have a home page where have put all the code in it like buttons, navbar, sidebar, body and so on right.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Suppose we created a new page like about us where we want to add a button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;So what we do is just copy the button code from the home page and past it on the about us page&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;But there is a problem if we change the colour of the button so we have to change the button colour on every page&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yFBXDm33--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lvktzl9oke8g9elz3ym2.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yFBXDm33--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lvktzl9oke8g9elz3ym2.gif" alt="Image description" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So this problem is resolved by &lt;strong&gt;COMPONENT&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Let's take the previous example, how does the component help us to solve this problem?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;First, it creates a separate file like button.js (Component) for the button code Ok&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then it just links the button.js file with a home page and about us page&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So if any changes occur in the button so we just need to change the button file and then all the files which import it. their button will change&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PiszjfNW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/62du5esnjman8d37g2tz.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PiszjfNW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/62du5esnjman8d37g2tz.gif" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Learn Once, Write Anywhere
&lt;/h2&gt;

&lt;p&gt;this one means reusability&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Right, Now code is more reusable&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;we can take the button example create a new button component and put the button code into it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And use this component in every file where we want to add button code this is reusable&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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