<?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: Ahmad Mahboob</title>
    <description>The latest articles on DEV Community by Ahmad Mahboob (@ahmad_mahboob).</description>
    <link>https://dev.to/ahmad_mahboob</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%2F2819245%2F0df298e2-36d2-4f5e-a77c-87364ce8452f.jpg</url>
      <title>DEV Community: Ahmad Mahboob</title>
      <link>https://dev.to/ahmad_mahboob</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ahmad_mahboob"/>
    <language>en</language>
    <item>
      <title>Handling Click Events in React: A Beginner’s Guide to onClick</title>
      <dc:creator>Ahmad Mahboob</dc:creator>
      <pubDate>Sun, 28 Dec 2025 15:12:31 +0000</pubDate>
      <link>https://dev.to/ahmad_mahboob/handling-click-events-in-react-a-beginners-guide-to-onclick-2c2f</link>
      <guid>https://dev.to/ahmad_mahboob/handling-click-events-in-react-a-beginners-guide-to-onclick-2c2f</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;When we build a React application, users interact with it by clicking buttons, links, or other elements. These actions are called &lt;strong&gt;events&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
In this blog, we will learn how to handle events in React using the &lt;strong&gt;onClick&lt;/strong&gt; event. We will focus only on &lt;code&gt;onClick&lt;/code&gt; so beginners can understand it clearly without confusion.&lt;/p&gt;


&lt;h2&gt;
  
  
  What Is Event Handling in React?
&lt;/h2&gt;

&lt;p&gt;An &lt;strong&gt;event&lt;/strong&gt; is an action done by the user, like clicking a button or typing in an input field.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Event handling&lt;/strong&gt; means writing code that runs when that action happens.&lt;/p&gt;

&lt;p&gt;React handles events in a way that is similar to JavaScript, but there are some small differences:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Event names use &lt;strong&gt;camelCase&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We pass a &lt;strong&gt;function&lt;/strong&gt;, not function call&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;React uses a synthetic event system for better performance&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;JavaScript: &lt;code&gt;onclick&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;React: &lt;code&gt;onClick&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  Basic onClick Example in React
&lt;/h2&gt;

&lt;p&gt;Let’s start with a simple example.&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;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;handleClick&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Button 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;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleClick&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nx"&gt;Click&lt;/span&gt; &lt;span class="nx"&gt;Me&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What is happening here?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We created a function called &lt;code&gt;handleClick&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We passed that function to &lt;code&gt;onClick&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When the button is clicked, React runs the function&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Important point:&lt;br&gt;&lt;br&gt;
We are &lt;strong&gt;not calling&lt;/strong&gt; the function. We are only passing it.&lt;/p&gt;


&lt;h2&gt;
  
  
  Function Reference vs Arrow Function in onClick
&lt;/h2&gt;

&lt;p&gt;You will often see two ways to use &lt;code&gt;onClick&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Function Reference
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleClick&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Click&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This is best when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;No arguments are needed&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Logic is simple&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;
  
  
  2. Arrow Function
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&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="nf"&gt;handleClick&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nx"&gt;Click&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This is useful when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You want to pass arguments&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You want to add extra logic&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both are correct. The choice depends on your use case.&lt;/p&gt;


&lt;h2&gt;
  
  
  Passing Arguments in onClick
&lt;/h2&gt;

&lt;p&gt;Beginners often make this mistake:&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;handleClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Click&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;❌ This is wrong because the function runs immediately.&lt;/p&gt;

&lt;h3&gt;
  
  
  Correct way:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&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="nf"&gt;handleClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nx"&gt;Click&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the function runs &lt;strong&gt;only when the button is clicked&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Common Beginner Mistakes
&lt;/h2&gt;

&lt;p&gt;Here are some common mistakes beginners make:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Using &lt;code&gt;onclick&lt;/code&gt; instead of &lt;code&gt;onClick&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Calling the function instead of passing it&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Writing too much logic inside JSX&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Expecting page reload like normal HTML&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Forgetting that React events use camelCase&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Avoiding these mistakes will save a lot of time.&lt;/p&gt;




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

&lt;p&gt;Handling events is a core part of React. The &lt;code&gt;onClick&lt;/code&gt; event helps us respond to user actions like button clicks.&lt;br&gt;&lt;br&gt;
Once you understand &lt;code&gt;onClick&lt;/code&gt;, learning other events like &lt;code&gt;onChange&lt;/code&gt; and &lt;code&gt;onSubmit&lt;/code&gt; becomes much easier.&lt;/p&gt;

&lt;p&gt;Start small, practice often, and build confidence step by step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Important Links
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://react.dev/learn" rel="noopener noreferrer"&gt;Quick Start – React&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://react.dev/learn/responding-to-events#recap" rel="noopener noreferrer"&gt;Responding to Events – React&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-add-tailwind-css-to-a-react-app-step-by-step-guide-48a6/"&gt;How to Add Tailwind CSS to a React App (Step-by-Step Guide)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-use-bootstrap-in-a-react-project-beginner-guide-15hi"&gt;How to Use Bootstrap in a React Project (Beginner Guide)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/what-are-props-in-react-a-beginner-friendly-guide-3djp"&gt;What Are Props in React? A Beginner-Friendly Guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/conditional-rendering-in-react-a-practical-guide-for-beginners-3i39"&gt;Conditional Rendering in React: A Practical Guide for Beginners&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-use-map-in-react-with-simple-examples-1d3k"&gt;How to Use map() in React (With Simple Examples)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-create-a-react-app-using-vite-step-by-step-guide-for-beginners-5eif"&gt;How to Create a React App Using Vite (Step-by-Step Guide for Beginners)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/understanding-react-project-structure-created-by-vite-beginners-guide-59ea"&gt;Understanding React Project Structure Created by Vite (Beginner’s Guide)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/react-fragments-explained-how-to-group-elements-without-extra-dom-nodes-378a"&gt;React Fragments Explained: How to Group Elements Without Extra DOM Nodes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/react-components-explained-a-beginner-friendly-guide-with-examples-1l9p"&gt;React Components Explained: A Beginner-Friendly Guide with Examples&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>react</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Passing Children as Props in React (Beginner Friendly Guide)</title>
      <dc:creator>Ahmad Mahboob</dc:creator>
      <pubDate>Sat, 27 Dec 2025 15:54:33 +0000</pubDate>
      <link>https://dev.to/ahmad_mahboob/passing-children-as-props-in-react-beginner-friendly-guide-4h33</link>
      <guid>https://dev.to/ahmad_mahboob/passing-children-as-props-in-react-beginner-friendly-guide-4h33</guid>
      <description>&lt;p&gt;When you start learning React, you often hear about &lt;strong&gt;props&lt;/strong&gt;. Props help us pass data from one component to another.&lt;br&gt;&lt;br&gt;
But there is one special prop in React that beginners usually find confusing — &lt;code&gt;children&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In this blog, we’ll understand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;What &lt;code&gt;children&lt;/code&gt; is in React&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Why we use it&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How to pass children as props&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Simple examples you can understand easily&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No advanced concepts. Just clear basics.&lt;/p&gt;


&lt;h2&gt;
  
  
  What Are Children Props in React?
&lt;/h2&gt;

&lt;p&gt;In React, &lt;code&gt;children&lt;/code&gt; is a special prop that allows you to pass &lt;strong&gt;JSX or content inside a component&lt;/strong&gt;, instead of passing it as a normal prop.&lt;/p&gt;

&lt;p&gt;Simple meaning:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Whatever you write &lt;strong&gt;between the opening and closing tag of a component&lt;/strong&gt; becomes &lt;code&gt;children&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Card&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="nx"&gt;World&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h2&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Card&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here, &lt;code&gt;&amp;lt;h2&amp;gt;Hello World&amp;lt;/h2&amp;gt;&lt;/code&gt; is the &lt;strong&gt;children&lt;/strong&gt; of the &lt;code&gt;Card&lt;/code&gt; component.&lt;/p&gt;


&lt;h2&gt;
  
  
  Why Do We Use Children Props?
&lt;/h2&gt;

&lt;p&gt;Children props are useful when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You want to create &lt;strong&gt;reusable components&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You don’t know in advance what content will go inside a component&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You want to keep components &lt;strong&gt;flexible and clean&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of it like a &lt;strong&gt;container or wrapper&lt;/strong&gt; that can hold different content.&lt;/p&gt;


&lt;h2&gt;
  
  
  Basic Example of Children Props
&lt;/h2&gt;

&lt;p&gt;Let’s start with a very simple example.&lt;/p&gt;
&lt;h3&gt;
  
  
  Parent Component
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Box&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;This&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;inside&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;Box&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Box&lt;/span&gt;&lt;span class="err"&gt;&amp;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;h3&gt;
  
  
  Child Component
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Box&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2px solid black&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;10px&lt;/span&gt;&lt;span class="dl"&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;children&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;h3&gt;
  
  
  What’s Happening Here?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Box&lt;/code&gt; is a component&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Whatever we write inside &lt;code&gt;&amp;lt;Box&amp;gt;...&amp;lt;/Box&amp;gt;&lt;/code&gt; becomes &lt;code&gt;children&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;{children}&lt;/code&gt; renders that content inside the component&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  Children Can Be Anything
&lt;/h2&gt;

&lt;p&gt;Children are not limited to text only. They can be:&lt;/p&gt;
&lt;h3&gt;
  
  
  Text
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Card&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Welcome&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Card&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  HTML / JSX
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Card&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h3&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Title&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h3&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Description&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Card&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Components
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Card&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Card&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;React treats all of this as &lt;code&gt;children&lt;/code&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  Real-World Use Case (Very Common)
&lt;/h2&gt;

&lt;p&gt;Imagine a &lt;strong&gt;Button component&lt;/strong&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;btn&lt;/span&gt;&lt;span class="dl"&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;children&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;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;Usage:&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Login&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Sign&lt;/span&gt; &lt;span class="nx"&gt;Up&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of creating multiple buttons, you reuse one component and pass different text using &lt;code&gt;children&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Children vs Normal Props
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Using Normal Props
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Login&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Using Children
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Login&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why Children Is Better?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;More readable&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;More flexible&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Can pass complex JSX, not just text&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Common Beginner Mistakes
&lt;/h2&gt;

&lt;p&gt;Here are some common mistakes beginners make:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Forgetting to render&lt;/strong&gt; &lt;code&gt;{children}&lt;/code&gt; inside the component&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Thinking &lt;code&gt;children&lt;/code&gt; is a keyword (it’s just a prop)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using self-closing tags when children are needed&lt;br&gt;&lt;br&gt;
❌ &lt;code&gt;&amp;lt;Box /&amp;gt;&lt;/code&gt;&lt;br&gt;&lt;br&gt;
✅ &lt;code&gt;&amp;lt;Box&amp;gt;Content&amp;lt;/Box&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Confusing children with normal props&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  When Should You Use Children?
&lt;/h2&gt;

&lt;p&gt;Use &lt;code&gt;children&lt;/code&gt; when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You are building reusable UI components&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Your component is acting as a wrapper or layout&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Content inside the component can change&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do &lt;strong&gt;not&lt;/strong&gt; use children when the component has a fixed structure.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Children props are one of the &lt;strong&gt;most powerful and simple features of React&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Once you understand them, writing clean and reusable components becomes much easier.&lt;/p&gt;

&lt;p&gt;If you are serious about React, &lt;strong&gt;mastering children is not optional&lt;/strong&gt; — it’s essential.&lt;/p&gt;

&lt;p&gt;Keep practicing small examples. That’s how React really clicks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Important Links
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://react.dev/learn" rel="noopener noreferrer"&gt;Quick Start – React&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/css-modules-in-react-scoped-styling-without-the-headache-24pp"&gt;CSS Modules in React: Scoped Styling Without the Headache&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-add-tailwind-css-to-a-react-app-step-by-step-guide-48a6/"&gt;How to Add Tailwind CSS to a React App (Step-by-Step Guide)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-use-bootstrap-in-a-react-project-beginner-guide-15hi"&gt;How to Use Bootstrap in a React Project (Beginner Guide)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/what-are-props-in-react-a-beginner-friendly-guide-3djp"&gt;What Are Props in React? A Beginner-Friendly Guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/conditional-rendering-in-react-a-practical-guide-for-beginners-3i39"&gt;Conditional Rendering in React: A Practical Guide for Beginners&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-use-map-in-react-with-simple-examples-1d3k"&gt;How to Use map() in React (With Simple Examples)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-create-a-react-app-using-vite-step-by-step-guide-for-beginners-5eif"&gt;How to Create a React App Using Vite (Step-by-Step Guide for Beginners)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/understanding-react-project-structure-created-by-vite-beginners-guide-59ea"&gt;Understanding React Project Structure Created by Vite (Beginner’s Guide)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/react-fragments-explained-how-to-group-elements-without-extra-dom-nodes-378a"&gt;React Fragments Explained: How to Group Elements Without Extra DOM Nodes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/react-components-explained-a-beginner-friendly-guide-with-examples-1l9p"&gt;React Components Explained: A Beginner-Friendly Guide with Examples&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>react</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>CSS Modules in React: Scoped Styling Without the Headache</title>
      <dc:creator>Ahmad Mahboob</dc:creator>
      <pubDate>Fri, 26 Dec 2025 15:59:52 +0000</pubDate>
      <link>https://dev.to/ahmad_mahboob/css-modules-in-react-scoped-styling-without-the-headache-24pp</link>
      <guid>https://dev.to/ahmad_mahboob/css-modules-in-react-scoped-styling-without-the-headache-24pp</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this blog, we’ll discuss what CSS Modules in React are, why we use them, and what problems they solve. We’ll also look at an example to understand the concepts better. CSS Modules provide a modular way of defining CSS styles for a component. Developers can define CSS styles for a component without name clashes. I’ll explain this later in the blog.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Are CSS Modules?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://create-react-app.dev/docs/adding-a-css-modules-stylesheet/" rel="noopener noreferrer"&gt;CSS Modules&lt;/a&gt; allow us to define styles for a component. As these are defined for a specific component, it reduces global CSS conflicts. CSS Modules are local styles by default. When classes are defined in CSS Modules, they are transformed into unique identifiers at build time.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Problems Do CSS Modules Solve?
&lt;/h2&gt;

&lt;p&gt;You have probably faced situations where your desired styles do not work. This issue often arises in projects with multiple developers. For example, you define CSS styles for one component. Another developer defines the same class with different styles. When you use the class in your component, your styles are not working. This is because you both have defined the same class with different styling. That creates unintentional name clashes.&lt;/p&gt;

&lt;p&gt;Also, the developers add CSS styles and classes in CSS files. They do not remove the CSS styles/classes from the codebase, thinking that some other component might be using this styling. That results in the CSS file becoming larger over time. CSS Modules solve these issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use CSS Modules in React?
&lt;/h2&gt;

&lt;p&gt;Developers use CSS Modules because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It avoids global CSS conflicts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It allows component-level styling.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is easier to maintain.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No headache of creating unique class names.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How CSS Modules Work (Concept)
&lt;/h2&gt;

&lt;p&gt;To work with CSS Modules, you should consider the following points. The CSS filename would be like this &lt;code&gt;Component.module.css&lt;/code&gt;. Here &lt;code&gt;Component&lt;/code&gt; is the name of your component. (&lt;code&gt;Component.module.css&lt;/code&gt; is usually named after the component for clarity, but React does not enforce this strictly.) &lt;code&gt;module.css&lt;/code&gt; implies that this is a CSS module. &lt;code&gt;Component.module.css&lt;/code&gt; implies that this CSS module contains the styles for &lt;code&gt;Component&lt;/code&gt;. For example, if a component is named &lt;code&gt;Item&lt;/code&gt;. The CSS module file would be named &lt;code&gt;Item.module.css&lt;/code&gt;. React (via the bundler) transforms CSS Module class names into unique identifiers during development and build time. Like &lt;code&gt;.list-item&lt;/code&gt; would become &lt;code&gt;._list-item_zpzj8_1&lt;/code&gt;. React converts your CSS classes into an object. You can apply the styles using an import statement in the React component. You can access CSS module classes in a React component using &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors" rel="noopener noreferrer"&gt;dot-notation or bracket-notation of the object in JS&lt;/a&gt;. CSS Modules work out of the box in popular React setups like &lt;a href="https://create-react-app.dev/" rel="noopener noreferrer"&gt;Create React App&lt;/a&gt;, &lt;a href="https://vite.dev/guide/" rel="noopener noreferrer"&gt;Vite&lt;/a&gt;, and &lt;a href="https://nextjs.org/" rel="noopener noreferrer"&gt;Next.js.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using CSS Modules in a React Project (Example)
&lt;/h2&gt;

&lt;p&gt;This is my component:&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;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="nx"&gt;World&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h2&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Using&lt;/span&gt; &lt;span class="nx"&gt;CSS&lt;/span&gt; &lt;span class="nx"&gt;Module&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;I want to change the text color and its background color of both the heading and paragraph. My component name is App. So, I would create &lt;code&gt;App.module.css&lt;/code&gt; file for defining styles. In my &lt;code&gt;App.module.css&lt;/code&gt; file, I would define my component’s styling as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.main-heading&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;aqua&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.paragraph&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;chartreuse&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;antiquewhite&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;Now, import this styling into the App.jsx (App component) by adding this line:&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styles&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./App.module.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this, you can apply your defined classes to your component. Use dot-notation or bracket notation to use styles (Because styles/classes are converted into an object). Like:&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styles&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./App.module.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* Using Bracket Notation */&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h2&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;main-heading&lt;/span&gt;&lt;span class="dl"&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="nx"&gt;Hello&lt;/span&gt; &lt;span class="nx"&gt;World&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h2&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* Using Dot-Notation*/&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;paragraph&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Using&lt;/span&gt; &lt;span class="nx"&gt;CSS&lt;/span&gt; &lt;span class="nx"&gt;Module&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this way, your styles are applied.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Transformation of class names:&lt;/strong&gt; In this example, when I inspected the styling of the app in the browser. The &lt;code&gt;.main-heading&lt;/code&gt; is transformed into &lt;code&gt;._main-heading_zpzj8_1&lt;/code&gt; and &lt;code&gt;.paragraph&lt;/code&gt; into &lt;code&gt;._paragraph_zpzj8_9&lt;/code&gt;. (In your case, they might be different.) That’s how CSS Modules avoid global CSS conflicts. You can also use global CSS along with CSS module styling as:&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styles&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./App.module.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* Using Bracket Notation */&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h2&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;main-heading&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="s2"&gt; text-center`&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="nx"&gt;World&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h2&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* Using Dot-Notation*/&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;paragraph&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; text-center`&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Using&lt;/span&gt; &lt;span class="nx"&gt;CSS&lt;/span&gt; &lt;span class="nx"&gt;Module&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Common Mistakes to Avoid
&lt;/h2&gt;

&lt;p&gt;Using &lt;code&gt;class&lt;/code&gt; instead of &lt;code&gt;className&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Forgetting &lt;code&gt;module.css&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Incorrect import syntax&lt;/p&gt;

&lt;p&gt;Trying to use global selectors like &lt;code&gt;body&lt;/code&gt; inside CSS Modules&lt;/p&gt;

&lt;p&gt;Forgetting to import the CSS module file&lt;/p&gt;

&lt;h2&gt;
  
  
  When Should You Use CSS Modules?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Small to medium React projects&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Component-based UI&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Teams where CSS conflicts are common&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;In this blog, we discussed in detail what CSS Modules are, why and how to use them, and what problems they solve. I explained the concepts in a beginner-friendly way and showed the exact process step-by-step. If you feel it is complicated at first, don’t worry. You will master this by practice. I encourage you to practice following along with the blog to develop a better understanding. Feel free to comment below if you need any help. I’ll be happy to help you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Important Links
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://create-react-app.dev/docs/adding-a-css-modules-stylesheet/" rel="noopener noreferrer"&gt;Adding a CSS Modules Stylesheet | Create React App&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors" rel="noopener noreferrer"&gt;Property accessors Object - JavaScript | MDN&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://create-react-app.dev/" rel="noopener noreferrer"&gt;Create React App is deprecated.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://nextjs.org/" rel="noopener noreferrer"&gt;Next.js by Vercel - The React Framework&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://vite.dev/guide/" rel="noopener noreferrer"&gt;Getting Started | Vite&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-add-tailwind-css-to-a-react-app-step-by-step-guide-48a6/"&gt;How to Add Tailwind CSS to a React App (Step-by-Step Guide)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-use-bootstrap-in-a-react-project-beginner-guide-15hi"&gt;How to Use Bootstrap in a React Project (Beginner Guide)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/what-are-props-in-react-a-beginner-friendly-guide-3djp"&gt;What Are Props in React? A Beginner-Friendly Guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/conditional-rendering-in-react-a-practical-guide-for-beginners-3i39"&gt;Conditional Rendering in React: A Practical Guide for Beginners&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-use-map-in-react-with-simple-examples-1d3k"&gt;How to Use map() in React (With Simple Examples)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-create-a-react-app-using-vite-step-by-step-guide-for-beginners-5eif"&gt;How to Create a React App Using Vite (Step-by-Step Guide for Beginners)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/understanding-react-project-structure-created-by-vite-beginners-guide-59ea"&gt;Understanding React Project Structure Created by Vite (Beginner’s Guide)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/react-fragments-explained-how-to-group-elements-without-extra-dom-nodes-378a"&gt;React Fragments Explained: How to Group Elements Without Extra DOM Nodes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/react-components-explained-a-beginner-friendly-guide-with-examples-1l9p"&gt;React Components Explained: A Beginner-Friendly Guide with Examples&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>beginners</category>
      <category>frontend</category>
    </item>
    <item>
      <title>How to Add Tailwind CSS to a React App (Step-by-Step Guide)</title>
      <dc:creator>Ahmad Mahboob</dc:creator>
      <pubDate>Thu, 25 Dec 2025 16:41:36 +0000</pubDate>
      <link>https://dev.to/ahmad_mahboob/how-to-add-tailwind-css-to-a-react-app-step-by-step-guide-48a6</link>
      <guid>https://dev.to/ahmad_mahboob/how-to-add-tailwind-css-to-a-react-app-step-by-step-guide-48a6</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this blog, we’ll discuss what &lt;a href="https://tailwindcss.com/" rel="noopener noreferrer"&gt;Tailwind&lt;/a&gt; CSS is, how to use it in a React project, and why developers use it. First, understand what Tailwind CSS is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A utility-first CSS framework packed with classes like flex, pt-4, text-center, and rotate-90 that can be composed to build any design, directly in your markup. —&lt;/strong&gt;&lt;a href="https://tailwindcss.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;Tailwind CSS official website&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;To follow along, you should have these prerequisites:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You should have Node.js installed on your system. (Visit &lt;a href="https://nodejs.org/en" rel="noopener noreferrer"&gt;Node.js website&lt;/a&gt; to install Node.js, if you haven’t already, for free)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You should have a React project created&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You should have basic knowledge of React&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: If you haven’t already created the React app, don’t worry. I’ll show you how to create a React app in the section below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use Tailwind CSS with React?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Tailwind CSS provides a utility-first approach&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tailwind CSS has many commonly used predefined classes. We use those classes in our project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tailwind CSS helps developers build UI faster.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The developers do not have to write custom CSS for each element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It also allows developers to build UI responsive without leaving the HTML.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It also works perfectly with React components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Many modern websites and tools, such as Shopify and Cursor, use Tailwind. — Source: &lt;a href="https://tailwindcss.com/showcase" rel="noopener noreferrer"&gt;Tailwind CSS official website&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1 - Create React App
&lt;/h2&gt;

&lt;p&gt;You can create a React app using Vite with this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm create vite@latest project-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I am using Vite because it’s the recommended by &lt;strong&gt;React docs&lt;/strong&gt;,. I have a detailed blog on “How to Create a React App”. Visit &lt;a href="https://ahmadcodes.hashnode.dev/how-to-create-a-react-app-using-vite-step-by-step-guide-for-beginners" rel="noopener noreferrer"&gt;this&lt;/a&gt; blog to understand the difference much better.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2 - Install Tailwind CSS
&lt;/h2&gt;

&lt;p&gt;Now, install Tailwind CSS in your project (created by Vite) with this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;tailwindcss @tailwindcss/vite
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;npm will install the dependencies (it might take a few seconds). You can verify the installation from &lt;code&gt;package.json&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvm321zynnj2tqaxyom6h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvm321zynnj2tqaxyom6h.png" alt="package.json verifying the installation of TailwindCSS" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Configure Vite Plugin
&lt;/h3&gt;

&lt;p&gt;To configure Vite plugin, first open the file &lt;code&gt;vite.config.js&lt;/code&gt;. You can find this file in &lt;code&gt;project-name/vite.config.js&lt;/code&gt; (if you created project using Vite). Here, project-name corresponds to the name of your project.&lt;/p&gt;

&lt;p&gt;1- In the top of the &lt;code&gt;vite.config.js&lt;/code&gt; add this line to import &lt;code&gt;tailwindcss&lt;/code&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;tailwindcss&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@tailwindcss/vite&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2- After this, add this in the plugin section in the file (&lt;code&gt;vite.config.js&lt;/code&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="nf"&gt;tailwindcss&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, your &lt;code&gt;vite.config.js&lt;/code&gt; looks like this:&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;defineConfig&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vite&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;react&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@vitejs/plugin-react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;tailwindcss&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@tailwindcss/vite&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// https://vite.dev/config/&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;defineConfig&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;react&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nf"&gt;tailwindcss&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;h3&gt;
  
  
  Import Tailwind CSS
&lt;/h3&gt;

&lt;p&gt;To import Tailwind CSS, locate the &lt;code&gt;index.css&lt;/code&gt; file and open it. You can find index.css in &lt;code&gt;project-name/src/index.css&lt;/code&gt;. Now, replace the content of &lt;code&gt;index.css&lt;/code&gt; with this line:&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="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tailwindcss&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you can start using Tailwind CSS in your project. Like:&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;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h2&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bg-red-400 font-mono text-4xl text-gray-200 m-4 text-center&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="nx"&gt;World&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h2&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, I have styled the background, text-color, font-size, font, text-alignment and added a margin. If you want to learn Tailwind CSS in a beginner friendly way, feel free to comment to let me know.&lt;/p&gt;

&lt;h2&gt;
  
  
  When Should You Use Tailwind CSS (and When Not)?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Good for component-based apps&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Not ideal if someone prefers traditional CSS frameworks&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;In this blog, I explained what Tailwind is, why it is used, and how to install and use it in a React project. I have explained step-by-step process in beginner-friendly way. I did not go too deep to avoid confusing beginners. If you need help regarding any issue while installing or using, feel free to comment below. I’ll be happy to help you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Important Links
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://tailwindcss.com/docs/installation/using-vite" rel="noopener noreferrer"&gt;Installing Tailwind CSS with Vite - Tailwind CSS&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://nodejs.org/en" rel="noopener noreferrer"&gt;Node.js — Run JavaScript Everywhere&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tailwindcss.com/" rel="noopener noreferrer"&gt;Tailwind CSS - Rapidly build modern websites without ever leaving your HTML.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tailwindcss.com/showcase" rel="noopener noreferrer"&gt;Showcase - Tailwind CSS&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-use-bootstrap-in-a-react-project-beginner-guide-15hi"&gt;How to Use Bootstrap in a React Project (Beginner Guide)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/what-are-props-in-react-a-beginner-friendly-guide-3djp"&gt;What Are Props in React? A Beginner-Friendly Guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/conditional-rendering-in-react-a-practical-guide-for-beginners-3i39"&gt;Conditional Rendering in React: A Practical Guide for Beginners&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-use-map-in-react-with-simple-examples-1d3k"&gt;How to Use map() in React (With Simple Examples)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-create-a-react-app-using-vite-step-by-step-guide-for-beginners-5eif"&gt;How to Create a React App Using Vite (Step-by-Step Guide for Beginners)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/understanding-react-project-structure-created-by-vite-beginners-guide-59ea"&gt;Understanding React Project Structure Created by Vite (Beginner’s Guide)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/react-fragments-explained-how-to-group-elements-without-extra-dom-nodes-378a"&gt;React Fragments Explained: How to Group Elements Without Extra DOM Nodes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/react-components-explained-a-beginner-friendly-guide-with-examples-1l9p"&gt;React Components Explained: A Beginner-Friendly Guide with Examples&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>tailwindcss</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to Use Bootstrap in a React Project (Beginner Guide)</title>
      <dc:creator>Ahmad Mahboob</dc:creator>
      <pubDate>Wed, 24 Dec 2025 16:03:28 +0000</pubDate>
      <link>https://dev.to/ahmad_mahboob/how-to-use-bootstrap-in-a-react-project-beginner-guide-15hi</link>
      <guid>https://dev.to/ahmad_mahboob/how-to-use-bootstrap-in-a-react-project-beginner-guide-15hi</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this blog, we’ll discuss what &lt;a href="https://getbootstrap.com/docs/5.3/getting-started/introduction/" rel="noopener noreferrer"&gt;Bootstrap&lt;/a&gt; is, how to use Bootstrap in a React project, and why we use Bootstrap. First, understand what Bootstrap is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://getbootstrap.com/docs/5.3/getting-started/introduction/" rel="noopener noreferrer"&gt;Bootstrap&lt;/a&gt; is a powerful, feature-packed frontend toolkit. Build anything—from prototype to production—in minutes. —- From Bootstrap Official Website&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why Use Bootstrap with React?
&lt;/h2&gt;

&lt;p&gt;Bootstrap helps developers build UI components faster by providing pre-built components that can be customized using utility classes. It is good for beginners who are learning React. This allows beginners to focus on learning React concepts rather than writing CSS. Rather than writing the styles, i.e., CSS of the component. But it comes with its costs. Bootstrap is not ideal for projects with highly custom UIs. From a beginner’s point of view, it’s a great resource that boosts their learning speed by focusing on concepts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;To follow along with this beginner guide, there are some prerequisites. These are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You should have &lt;strong&gt;basic&lt;/strong&gt; &lt;strong&gt;React&lt;/strong&gt; knowledge.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You must have &lt;a href="https://nodejs.org/en" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt; installed on your system.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You should have created a React project. If you haven’t, you can read this guide or run this command in your terminal:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm create vite@latest project-name
&lt;/code&gt;&lt;/pre&gt;

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

&lt;h2&gt;
  
  
  Installing Bootstrap in React
&lt;/h2&gt;

&lt;p&gt;For installing Bootstrap in your React project, follow these steps:&lt;/p&gt;

&lt;h3&gt;
  
  
  1- Install via npm
&lt;/h3&gt;

&lt;p&gt;If you have Node.js installed on your system, then you can run this command in your terminal to install Bootstrap:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;bootstrap@5.3.8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or simply (replacing &lt;code&gt;install&lt;/code&gt; with &lt;code&gt;i&lt;/code&gt; in command):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i bootstrap@5.3.8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will install the Bootstrap version 5.3.8 package in your React project. When you run this command in your terminal, it will install like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjzdfa34hp147xu6ac84k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjzdfa34hp147xu6ac84k.png" alt="Image showing the downloading of Bootstrap" width="800" height="148"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also verify it from &lt;code&gt;package.json&lt;/code&gt;. If the package is installed successfully, it will be listed in the dependencies in &lt;code&gt;package.json&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq1ua5cx6mayn17kq0civ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq1ua5cx6mayn17kq0civ.png" alt="Image showing package.json verifying the installation of Bootstrap" width="800" height="423"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: The version of Bootstrap may be different. At the time of publishing this blog, the latest version is 5.3.8. You can check for the latest version from the &lt;a href="https://getbootstrap.com/" rel="noopener noreferrer"&gt;official Bootstrap website&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  2- Import Bootstrap CSS in &lt;code&gt;main.jsx&lt;/code&gt; or &lt;code&gt;index.js&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Now, to use Bootstrap in a React project, import Bootstrap in &lt;code&gt;main.jsx&lt;/code&gt; or &lt;code&gt;index.js&lt;/code&gt;. Add this line in &lt;code&gt;main.jsx&lt;/code&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="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bootstrap/dist/css/bootstrap.min.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: To use Bootstrap in React, there is no need for jQuery.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Bootstrap Classes in React Components
&lt;/h2&gt;

&lt;p&gt;Now, as we have imported Bootstrap, we can use Bootstrap classes in our projects. I’m showing you a simple example.&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;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h3&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;font-monospace bg-success text-white&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="nx"&gt;World&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;Styled&lt;/span&gt; &lt;span class="nx"&gt;using&lt;/span&gt; &lt;span class="nx"&gt;Bootstrap&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h3&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: I have not used &lt;code&gt;class&lt;/code&gt;, instead, I used &lt;code&gt;className&lt;/code&gt;. The word &lt;code&gt;className&lt;/code&gt; is used to add classes in a React component because &lt;code&gt;class&lt;/code&gt; is a keyword in JavaScript. So, the word &lt;code&gt;class&lt;/code&gt; is not used.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Mistakes to Avoid
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Using &lt;code&gt;class&lt;/code&gt; instead of &lt;code&gt;className&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Importing Bootstrap JS unnecessarily&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mixing Bootstrap with too many other UI libraries&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;In this guide, we learned what Bootstrap is and how to install, import, and use it in a React project. Bootstrap can be a helpful tool for beginners who want to build user interfaces quickly while focusing on core React concepts. While it may not be suitable for highly customized designs, it works well for learning, prototyping, and small to medium projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Important Links
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://getbootstrap.com/docs/5.3/getting-started/introduction/" rel="noopener noreferrer"&gt;Get started with Bootstrap · Bootstrap v5.3&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://nodejs.org/en" rel="noopener noreferrer"&gt;Node.js — Run JavaScript Everywhere&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/what-are-props-in-react-a-beginner-friendly-guide-3djp"&gt;What Are Props in React? A Beginner-Friendly Guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/conditional-rendering-in-react-a-practical-guide-for-beginners-3i39"&gt;Conditional Rendering in React: A Practical Guide for Beginners&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-use-map-in-react-with-simple-examples-1d3k"&gt;How to Use map() in React (With Simple Examples)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-create-a-react-app-using-vite-step-by-step-guide-for-beginners-5eif"&gt;How to Create a React App Using Vite (Step-by-Step Guide for Beginners)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/understanding-react-project-structure-created-by-vite-beginners-guide-59ea"&gt;Understanding React Project Structure Created by Vite (Beginner’s Guide)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/react-fragments-explained-how-to-group-elements-without-extra-dom-nodes-378a"&gt;React Fragments Explained: How to Group Elements Without Extra DOM Nodes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/react-components-explained-a-beginner-friendly-guide-with-examples-1l9p"&gt;React Components Explained: A Beginner-Friendly Guide with Examples&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>bootstrap</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What Are Props in React? A Beginner-Friendly Guide</title>
      <dc:creator>Ahmad Mahboob</dc:creator>
      <pubDate>Tue, 23 Dec 2025 15:24:23 +0000</pubDate>
      <link>https://dev.to/ahmad_mahboob/what-are-props-in-react-a-beginner-friendly-guide-3djp</link>
      <guid>https://dev.to/ahmad_mahboob/what-are-props-in-react-a-beginner-friendly-guide-3djp</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this blog, we’ll discuss what props are in React, why we use them, what problems they solve. Also we’ll see an example of using props. Sometimes, you need to pass data to a React component to make your app dynamic. You may find it difficult to understand how to pass data.. props do this thing for you. They are used to pass data from a parent component to a child component.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Props in React?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Props are inputs passed to a React component to customize its behavior or content.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://react.dev/learn/passing-props-to-a-component" rel="noopener noreferrer"&gt;&lt;strong&gt;Props&lt;/strong&gt;&lt;/a&gt; are the properties. They are a way to communicate data from parent element to child. We design React components to show the required data. We use placeholders for the data in React component. When we use a component multiple times, different data is passed to the component. This data is passed from parent to child using props. This is the advantage of React that we can use a component multiple time. Props make components reusable and dynamic. Props are &lt;strong&gt;read-only.&lt;/strong&gt; They are designed for one-way communication between components i.e., from parent to child.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Props are Important?
&lt;/h2&gt;

&lt;p&gt;Props are one of the most important concepts in the journey of React. They give us flexibility that we can design a component and use it multiple times with different data. Reusability of components reduces the developers’ stress. Props help developers write cleaner code by defining the component only once. We can keep data and UI separate from each other. And then for rendering, we can pass data using props. Props allow us to use the same component with different data. Like we can pass different data to a function in JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Passing Props to a Component
&lt;/h2&gt;

&lt;p&gt;Props are passed as attributes. Any valid JS value can be passed (string, number, object, function) as a prop. You can pass props like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fafjk64pw62gi0k71hzqe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fafjk64pw62gi0k71hzqe.png" alt="Image showing example code how to pass props" width="800" height="267"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You give the attribute a &lt;code&gt;name&lt;/code&gt; which will be used to receive the data in the child component. Like in my case, I have given the attribute the name, &lt;code&gt;skillName&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Receiving Props in a Component
&lt;/h2&gt;

&lt;p&gt;Props are received as an argument to the function i.e., component. When the props are passed, React creates an object of props and pass to the function. We can use the props by using dot notation of an object. Like:&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;const&lt;/span&gt; &lt;span class="nx"&gt;Skill&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&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;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&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;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;skillName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Skill&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Using Object Destructuring
&lt;/h3&gt;

&lt;p&gt;The props can also be used directly using object destructuring. Like:&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;const&lt;/span&gt; &lt;span class="nx"&gt;Skill&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;skillName&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;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&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;skillName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Skill&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: If you haven’t read about object destructuring, you can visit: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring" rel="noopener noreferrer"&gt;Destructuring - JavaScript | MDN&lt;/a&gt;. Or if you want me to explain, feel free to comment below if you want me to explain it..&lt;/p&gt;

&lt;h2&gt;
  
  
  Some Important Points About Props
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Props are &lt;strong&gt;read-only&lt;/strong&gt; and are &lt;strong&gt;immutable&lt;/strong&gt; (cannot be modified)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can pass &lt;strong&gt;multiple props&lt;/strong&gt; to a &lt;strong&gt;single component&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common Beginner Mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Trying to modify props&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Forgetting to pass props&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mismatched prop names&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Assuming props are optional&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring" rel="noopener noreferrer"&gt;Important Links&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring" rel="noopener noreferrer"&gt;Passing Props&lt;/a&gt; &lt;a href="https://react.dev/learn/passing-props-to-a-component" rel="noopener noreferrer"&gt;to a Component – React&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring" rel="noopener noreferrer"&gt;Destructuring - JavaScript | MDN&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/conditional-rendering-in-react-a-practical-guide-for-beginners-3i39"&gt;Conditional Rendering in React: A Practical Guide for Beginners&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-use-map-in-react-with-simple-examples-1d3k"&gt;How to Use map() in React (With Simple Examples)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-create-a-react-app-using-vite-step-by-step-guide-for-beginners-5eif"&gt;How to Create a React App Using Vite (Step-by-Step Guide for Beginners)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/understanding-react-project-structure-created-by-vite-beginners-guide-59ea"&gt;Understanding React Project Structure Created by Vite (Beginner’s Guide)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/react-fragments-explained-how-to-group-elements-without-extra-dom-nodes-378a"&gt;React Fragments Explained: How to Group Elements Without Extra DOM Nodes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/react-components-explained-a-beginner-friendly-guide-with-examples-1l9p"&gt;React Components Explained: A Beginner-Friendly Guide with Examples&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Conditional Rendering in React: A Practical Guide for Beginners</title>
      <dc:creator>Ahmad Mahboob</dc:creator>
      <pubDate>Mon, 22 Dec 2025 14:20:03 +0000</pubDate>
      <link>https://dev.to/ahmad_mahboob/conditional-rendering-in-react-a-practical-guide-for-beginners-3i39</link>
      <guid>https://dev.to/ahmad_mahboob/conditional-rendering-in-react-a-practical-guide-for-beginners-3i39</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Sometimes, we want to render some content in our app based on a certain condition. If a certain condition is not met, we don’t want to render the content. We only want to render the content when a certain condition is met. In this case, we use conditional rendering to render content based on certain conditions.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is &lt;a href="https://react.dev/learn/conditional-rendering" rel="noopener noreferrer"&gt;Conditional Rendering&lt;/a&gt; in React?
&lt;/h2&gt;

&lt;p&gt;Conditional rendering is a technique used to render specific content based on a condition. We use different methods for conditional rendering. Some of these are given below:&lt;/p&gt;

&lt;h2&gt;
  
  
  Conditional Rendering Using if-else
&lt;/h2&gt;

&lt;p&gt;An easy way to render conditionally is the traditional &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else" rel="noopener noreferrer"&gt;if-else&lt;/a&gt; in JavaScript. In this method, an if-else is placed before the JSX (return statement) in a React component. This if-else executes the condition. Based on that condition, the relevant code block is rendered. For example, if I have a list. I want to render ‘No item found’ if the list is empty. I can do this by:&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;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;skills&lt;/span&gt; &lt;span class="o"&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;skills&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h3&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;No&lt;/span&gt; &lt;span class="nx"&gt;Items&lt;/span&gt; &lt;span class="nx"&gt;Found&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h3&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h4&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Skills&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h4&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&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;skills&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;skill&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;skill&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;skill&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="p"&gt;))}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ul&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;skills&lt;/code&gt; array is empty. So, &lt;code&gt;skills.length == 0&lt;/code&gt; is true. So, &lt;code&gt;No Items Found&lt;/code&gt; is displayed. As I am returning the message here, so the list will not render.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why if-else is not Used?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;if-else&lt;/code&gt; is &lt;strong&gt;used&lt;/strong&gt;, but less often for simple UI. This is because we cannot write &lt;code&gt;if-else&lt;/code&gt; in JSX. But for complex conditions, we use if-else for conditional rendering.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Conditional Operator
&lt;/h2&gt;

&lt;p&gt;Another method for &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator" rel="noopener noreferrer"&gt;conditional rendering&lt;/a&gt; is by using &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator" rel="noopener noreferrer"&gt;ternary operator&lt;/a&gt; i.e., conditional operator. We use this for inline conditional rendering. This is the most commonly used method for conditional rendering. For example, if I want to implement the same functionality using ternary operator, I can implement it by:&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;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;skills&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h4&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Skills&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h4&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;skills&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h3&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;No&lt;/span&gt; &lt;span class="nx"&gt;Items&lt;/span&gt; &lt;span class="nx"&gt;Found&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h3&amp;gt; : null&lt;/span&gt;&lt;span class="err"&gt;}
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&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;skills&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;skill&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;skill&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;skill&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="p"&gt;))}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ul&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conditional Rendering Using Logical Operators
&lt;/h2&gt;

&lt;p&gt;We also use &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND" rel="noopener noreferrer"&gt;Logical Operators&lt;/a&gt; for conditional rendering. We use &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND" rel="noopener noreferrer"&gt;AND&lt;/a&gt; &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; operator for conditional rendering. AND operator only returns true if both the values are true. Otherwise, it returns false. Let’s consider the example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fneomw2tvn6k69n7k0vb7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fneomw2tvn6k69n7k0vb7.png" alt="Example code of conditional rendering using Logical AND operator" width="800" height="237"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, if the value (condition) on the left side of &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND" rel="noopener noreferrer"&gt;AND&lt;/a&gt; operator is true, then it will go to the right-side value and renders it. But if the value on left side is false, it will not move to the right-side value. The above example using Conditional Operator is:&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;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;skills&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h4&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Skills&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h4&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;skills&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h3&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;No&lt;/span&gt; &lt;span class="nx"&gt;Items&lt;/span&gt; &lt;span class="nx"&gt;Found&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h3&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;}
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&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;skills&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;skill&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&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;skill&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="p"&gt;))}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ul&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Be careful when the left-side value can be  &lt;code&gt;0&lt;/code&gt;, because React will render  &lt;code&gt;0&lt;/code&gt;  on the screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  Difference between CSS hide/show and Conditional Rendering
&lt;/h2&gt;

&lt;p&gt;When we use CSS to hide or display an element based on a condition or event, this makes the app more complex. Because we are rendering unnecessary elements and then hiding them. This makes DOM more complex. React Conditional Rendering solves this problem. We’ve already seen how Conditional Rendering works.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of Conditional Rendering
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It enhances user experience.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It reduces unnecessary rendering.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It makes our app more interactive and dynamic.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Best Practices for Conditional Rendering
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Keep JSX readable&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Extract complex logic&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Prefer clarity over clever code&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use meaningful variable names&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;In this beginner guide, we have covered what Conditional Rendering is, why we use it, its different methods, its advantages and best practices. If this seems complicated at first, don’t worry. That’s natural. Practice regularly and you’ll master it. Practice makes you better over time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Important Links
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://react.dev/learn/conditional-rendering" rel="noopener noreferrer"&gt;Conditional Rendering – React&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else" rel="noopener noreferrer"&gt;if...else - JavaScript | MDN&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator" rel="noopener noreferrer"&gt;Conditional (ternary) operator - JavaScript | MDN&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND" rel="noopener noreferrer"&gt;Logical AND (&amp;amp;&amp;amp;) - JavaScript | MDN&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://dev.to/ahmad_mahboob/how-to-use-map-in-react-with-simple-examples-1d3k"&gt;&lt;strong&gt;How to Use map() in React (With Simple Examples)&lt;/strong&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-create-a-react-app-using-vite-step-by-step-guide-for-beginners-5eif"&gt;How to Create a React App Using Vite (Step-by-Step Guide for Beginners)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/understanding-react-project-structure-created-by-vite-beginners-guide-59ea"&gt;Understanding React Project Structure Created by Vite (Beginner’s Guide)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/react-fragments-explained-how-to-group-elements-without-extra-dom-nodes-378a"&gt;React Fragments Explained: How to Group Elements Without Extra DOM Nodes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/react-components-explained-a-beginner-friendly-guide-with-examples-1l9p"&gt;React Components Explained: A Beginner-Friendly Guide with Examples&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Use map() in React (With Simple Examples)</title>
      <dc:creator>Ahmad Mahboob</dc:creator>
      <pubDate>Sun, 21 Dec 2025 14:21:26 +0000</pubDate>
      <link>https://dev.to/ahmad_mahboob/how-to-use-map-in-react-with-simple-examples-1d3k</link>
      <guid>https://dev.to/ahmad_mahboob/how-to-use-map-in-react-with-simple-examples-1d3k</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;map() is a very important method to render lists in React. It helps us render the lists dynamically in the app. The map() solves many problems related to rendering repeated UI elements. We’ll discuss what problems does it solve.&lt;/p&gt;

&lt;h2&gt;
  
  
  map() in JavaScript
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map" rel="noopener noreferrer"&gt;&lt;code&gt;map()&lt;/code&gt;&lt;/a&gt; method of &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" rel="noopener noreferrer"&gt;&lt;code&gt;Array&lt;/code&gt;&lt;/a&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" rel="noopener noreferrer"&gt;insta&lt;/a&gt;nces creates a new array populated with the results of calling a provided function on every element in the calling array.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;map() is an array function iterating over each element of the array. It creates a new array after performing the specific operation on each element.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Problems map() Solve?
&lt;/h2&gt;

&lt;p&gt;For better understanding of the map() working and how it is helpful in rendering lists. For example: if I want to render a list of &lt;code&gt;skills&lt;/code&gt; in my app. I can do it by writing an un-ordered list or ordered list in a React component. Just like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa97rztpqrqyd1pn2oomj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa97rztpqrqyd1pn2oomj.png" alt="Image showing rendering list code without map() in React" width="800" height="650"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will work. But here’s the catch. In this case, I already know the exact number of list-items. So, I can just copy-paste with the content different. (That’s not recommended and not a good developer practice). In real world applications, we usually don’t know the number of list-items. Or if we know the number of list-items, we should not be iterating ourselves the list items. In that case, we need an iterating function like &lt;code&gt;map()&lt;/code&gt;. It makes rendering lists easier for us.&lt;/p&gt;

&lt;h2&gt;
  
  
  How map() Solves the Problem?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;map()&lt;/code&gt; allows us to iterate over an array. So, we can first list the items in an array (for this example). For real world applications, you would be fetching the data from a database. And then we can iterate and render each list-item as shown in the code example below:&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;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;skills&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;HTML&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;CSS&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;JS&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h4&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Skills&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h4&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&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;skills&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;skill&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&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;skill&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="p"&gt;))}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ul&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we are using &lt;code&gt;map()&lt;/code&gt; to render our skills list. We are iterating over each skill and then rendering it. This solution would have the same effect as manually rendering list. This is efficient in terms that it takes less time to code and is easier to use. Also, it gives us the flexibility that it can render any number of list items i.e., whether it be 3 or 1000. We don’t need to write for each item manually. That’s the advantage of using &lt;code&gt;map()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;With this solution, there would be an error/warning message in the console: &lt;code&gt;Each child in a list should have a unique "key" prop.&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Fix the Console Error?
&lt;/h2&gt;

&lt;p&gt;React wants us to pass a &lt;a href="https://react.dev/learn/rendering-lists#keeping-list-items-in-order-with-key" rel="noopener noreferrer"&gt;key&lt;/a&gt; (a key should be a number or string that can uniquely identify the list-item) to each list item while rendering the list. It is because React uses this key value to manage the list-items. It keeps track of the changes made in the list-item by its key. For beginners, I am not complicating things. So, I just give you the simple solution to the fix the error. (If you want a detailed explanation of how React works and why key is necessary in rendering lists, just comment below to let me know. I will surely bring this soon).&lt;br&gt;&lt;br&gt;
So, for fixing the error, pass the key attribute to each list item as shown in the given example:&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;skill&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;skill&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will fix the error. And now you can render the list without any hesitation. I’ve explained this concept in a simple and beginner-friendly way without going too deep into internal React mechanics. This should help you understand how &lt;strong&gt;map()&lt;/strong&gt; works without confusion.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: If you’re learning React, follow me for more beginner-friendly guides.&lt;/p&gt;




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

&lt;p&gt;In this blog, you learnt what is &lt;code&gt;map()&lt;/code&gt; in React, how it is useful in rendering lists, what problems exactly the devs face, what is key and how to pass the key value in the list-item.&lt;/p&gt;




&lt;h2&gt;
  
  
  Important Links
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://react.dev/learn/rendering-lists" rel="noopener noreferrer"&gt;Rendering Lists – React Official Docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map" rel="noopener noreferrer"&gt;Array.prototype.map() - JavaScript | MDN&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://react.dev/learn/rendering-lists#keeping-list-items-in-order-with-key" rel="noopener noreferrer"&gt;Keeping List Items in Order with Key – React official Docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ahmadcodes.hashnode.dev/" rel="noopener noreferrer"&gt;AhmadCodes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-create-a-react-app-using-vite-step-by-step-guide-for-beginners-5eif"&gt;How to Create a React App Using Vite (Step-by-Step Guide for Beginners)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/understanding-react-project-structure-created-by-vite-beginners-guide-59ea"&gt;Understanding React Project Structure Created by Vite (Beginner’s Guide)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/react-fragments-explained-how-to-group-elements-without-extra-dom-nodes-378a"&gt;React Fragments Explained: How to Group Elements Without Extra DOM Nodes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/react-components-explained-a-beginner-friendly-guide-with-examples-1l9p"&gt;React Components Explained: A Beginner-Friendly Guide with Examples&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>React Fragments Explained: How to Group Elements Without Extra DOM Nodes</title>
      <dc:creator>Ahmad Mahboob</dc:creator>
      <pubDate>Sat, 20 Dec 2025 14:16:09 +0000</pubDate>
      <link>https://dev.to/ahmad_mahboob/react-fragments-explained-how-to-group-elements-without-extra-dom-nodes-378a</link>
      <guid>https://dev.to/ahmad_mahboob/react-fragments-explained-how-to-group-elements-without-extra-dom-nodes-378a</guid>
      <description>&lt;p&gt;In this blog, we will be discussing what React Fragments are. We also discuss the issues that developers face without React Fragments. Then we will see how React Fragments solve our problem. And how React Fragments help us write cleaner and more efficient code.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are React Fragments?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://react.dev/reference/react/Fragment" rel="noopener noreferrer"&gt;React Fragments&lt;/a&gt; allow the developers to group multiple elements without the need for an extra parent element as a wrapper. We’ll see what it means in the next sections. They were introduced to solve the problem of unnecessary wrapper elements.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Problems do React Fragments Solve?
&lt;/h2&gt;

&lt;p&gt;For better understanding of what React Fragments solve, first you should know that a &lt;code&gt;return&lt;/code&gt; statement in JSX (a React Component) can only return a single parent element. This means that if more than one element is returned, React will throw an error.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;For example&lt;/strong&gt;, if I return two elements as shown in the screenshot below, there occurs an error.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsyq8a5fpcy0rvv3tryti.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsyq8a5fpcy0rvv3tryti.png" alt="Screenshot showing an error display for returning multiple elements" width="800" height="287"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The error says &lt;code&gt;JSX expressions must have one parent element.&lt;/code&gt;  &lt;/p&gt;
&lt;h2&gt;
  
  
  How to Fix?
&lt;/h2&gt;

&lt;p&gt;One way to fix this error is by using a wrapper element that wraps the actual elements to be used. &lt;strong&gt;For example&lt;/strong&gt;, you can use &lt;code&gt;&amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt; to wrap the code to make the single parent element returned by the function (component). Like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvn1exwjzvr32cpuo5kof.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvn1exwjzvr32cpuo5kof.png" alt="Error fix using div method" width="800" height="473"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will work fine. Your code will run without an error. But, this solution creates another problem explained in the next section.&lt;/p&gt;
&lt;h2&gt;
  
  
  What Problems Occur When Using &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; as a Wrapper?
&lt;/h2&gt;

&lt;p&gt;If you look at the code, we are using an extra &lt;code&gt;&amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt; which has no use. This &lt;code&gt;div&lt;/code&gt; has no purpose. You can say that this &lt;code&gt;div&lt;/code&gt; solves our problem. It is true that it solves our problem But this solution comes with its own costs. It is fine to use if you are using 2-3 components. But in real world application, there are a lot of components. And for each component, if we add an extra div, then we are making the whole DOM complicated. This leads to a cluttered DOM, makes debugging harder, and can cause layout and styling issues—especially in large applications. So, this approach makes our app slow which is not intended in real world applications. So, the question arises, how to solve this?&lt;/p&gt;
&lt;h2&gt;
  
  
  How React Fragments Solve This?
&lt;/h2&gt;

&lt;p&gt;Now, you have understood what problems the developers are facing. So, to tackle this issue, the concept of React Fragments was introduced. React Fragments allow developers to wrap multiple JSX elements without adding an extra DOM element. So, using React Fragments prevent the use of extra useless elements which are absolutely unnecessary for the application.&lt;br&gt;&lt;br&gt;
Let’s look how exactly React Fragments solve this. To solve this, wrap the component elements within: &lt;code&gt;&amp;lt;React.Fragment&amp;gt;&amp;lt;/React.Fragment&amp;gt;&lt;/code&gt;. &lt;strong&gt;For example,&lt;/strong&gt; I replaced the &lt;code&gt;div&lt;/code&gt; with &lt;code&gt;React.Fragment&lt;/code&gt; in the above code. Here’s the final code:&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Fragment&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="nx"&gt;World&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nx"&gt;Lorem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ipsum&lt;/span&gt; &lt;span class="nx"&gt;dolor&lt;/span&gt; &lt;span class="nx"&gt;sit&lt;/span&gt; &lt;span class="nx"&gt;amet&lt;/span&gt; &lt;span class="nx"&gt;consectetur&lt;/span&gt; &lt;span class="nx"&gt;adipisicing&lt;/span&gt; &lt;span class="nx"&gt;elit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nx"&gt;Labore&lt;/span&gt; &lt;span class="nx"&gt;atque&lt;/span&gt;
        &lt;span class="nx"&gt;itaque&lt;/span&gt; &lt;span class="nx"&gt;eius&lt;/span&gt; &lt;span class="nx"&gt;quia&lt;/span&gt; &lt;span class="nx"&gt;provident&lt;/span&gt; &lt;span class="nx"&gt;tempora&lt;/span&gt; &lt;span class="nx"&gt;sapiente&lt;/span&gt; &lt;span class="nx"&gt;rerum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;consequuntur&lt;/span&gt; &lt;span class="nx"&gt;veniam&lt;/span&gt;
        &lt;span class="nx"&gt;sit&lt;/span&gt; &lt;span class="nx"&gt;corporis&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;amet&lt;/span&gt; &lt;span class="nx"&gt;quae&lt;/span&gt; &lt;span class="nx"&gt;illo&lt;/span&gt; &lt;span class="nx"&gt;repellendus&lt;/span&gt; &lt;span class="nx"&gt;vitae&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;Libero&lt;/span&gt; &lt;span class="nx"&gt;dolores&lt;/span&gt;
        &lt;span class="nx"&gt;laudantium&lt;/span&gt; &lt;span class="nx"&gt;impedit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/React.Fragment&lt;/span&gt;&lt;span class="err"&gt;&amp;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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; In older React versions or setups without the new JSX transform, you need to import React to use &lt;code&gt;React.Fragment&lt;/code&gt;. In modern React projects (React 17+), this import is often not required. You can import React using this line:&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will solve our problem without adding any unnecessary element.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Short Syntax:
&lt;/h2&gt;

&lt;p&gt;There’s a short syntax available in React for using React Fragments. This shorter syntax does not require importing React. It can be used without importing React. The shorter syntax is just omitting the words &lt;code&gt;React.Fragment&lt;/code&gt; from the wrapper &lt;code&gt;&amp;lt;React.Fragment&amp;gt;&amp;lt;/React.Fragment&lt;/code&gt;. By using shorter syntax, you can use wrap the component in &lt;code&gt;&amp;lt;&amp;gt;&amp;lt;/&amp;gt;&lt;/code&gt;. Here’s the example how to do this:&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;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="nx"&gt;World&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nx"&gt;Lorem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ipsum&lt;/span&gt; &lt;span class="nx"&gt;dolor&lt;/span&gt; &lt;span class="nx"&gt;sit&lt;/span&gt; &lt;span class="nx"&gt;amet&lt;/span&gt; &lt;span class="nx"&gt;consectetur&lt;/span&gt; &lt;span class="nx"&gt;adipisicing&lt;/span&gt; &lt;span class="nx"&gt;elit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nx"&gt;Labore&lt;/span&gt; &lt;span class="nx"&gt;atque&lt;/span&gt;
        &lt;span class="nx"&gt;itaque&lt;/span&gt; &lt;span class="nx"&gt;eius&lt;/span&gt; &lt;span class="nx"&gt;quia&lt;/span&gt; &lt;span class="nx"&gt;provident&lt;/span&gt; &lt;span class="nx"&gt;tempora&lt;/span&gt; &lt;span class="nx"&gt;sapiente&lt;/span&gt; &lt;span class="nx"&gt;rerum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;consequuntur&lt;/span&gt; &lt;span class="nx"&gt;veniam&lt;/span&gt;
        &lt;span class="nx"&gt;sit&lt;/span&gt; &lt;span class="nx"&gt;corporis&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;amet&lt;/span&gt; &lt;span class="nx"&gt;quae&lt;/span&gt; &lt;span class="nx"&gt;illo&lt;/span&gt; &lt;span class="nx"&gt;repellendus&lt;/span&gt; &lt;span class="nx"&gt;vitae&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;Libero&lt;/span&gt; &lt;span class="nx"&gt;dolores&lt;/span&gt;
        &lt;span class="nx"&gt;laudantium&lt;/span&gt; &lt;span class="nx"&gt;impedit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: I have not imported React while using shorter syntax.&lt;/p&gt;




&lt;p&gt;I have tried to cover React Fragments and how to use them in a beginner friendly way by not getting deep into it to avoid confusing beginners. &lt;strong&gt;If you want a dedicated detailed blog on React Fragments, Fragments VS div, and advanced explanation, please comment below. I’ll bring the detailed explanation soon.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Important Links:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://react.dev/reference/react/Fragment" rel="noopener noreferrer"&gt;React - &amp;lt;Fragment&amp;gt; (&amp;lt;&amp;gt;...&amp;lt;/&amp;gt;)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://react.dev/learn" rel="noopener noreferrer"&gt;Quick Start – React&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-create-a-react-app-using-vite-step-by-step-guide-for-beginners-5eif"&gt;How to Create a React App Using Vite Step By Step Guide for Beginners&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/understanding-react-project-structure-created-by-vite-beginners-guide-59ea"&gt;Understanding React Project Structure Created by Vite (Beginner’s Guide)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/react-components-explained-a-beginner-friendly-guide-with-examples-1l9p"&gt;React Components Explained: A Beginner-Friendly Guide with Examples&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>React Components Explained: A Beginner-Friendly Guide with Examples</title>
      <dc:creator>Ahmad Mahboob</dc:creator>
      <pubDate>Fri, 19 Dec 2025 13:37:49 +0000</pubDate>
      <link>https://dev.to/ahmad_mahboob/react-components-explained-a-beginner-friendly-guide-with-examples-1l9p</link>
      <guid>https://dev.to/ahmad_mahboob/react-components-explained-a-beginner-friendly-guide-with-examples-1l9p</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;A React component (functional component) is just a JavaScript function that returns an HTML-like code(JSX — JavaScript XML). It is the core concept in React. It solves many developers’ problems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Components Are Important in React
&lt;/h2&gt;

&lt;p&gt;React component solves the unnecessary repetitions of the same code with a slight change in data. React components are designed to be reused to avoid the unnecessary repetition. Suppose you have to render 4 product cards. The cards are same in design, but the data is different for each product. So, you have to create four cards. That would take a lot of time and energy. That’s boring too. But React understands our worries and makes this easier for us. Now, in the above supposed case, how React solves our problem. With React, you will create only one component as use it for 4 times or any number of times wherever you want to use it in your app. Also, React component ensures UI consistency. Also, by dividing the app into components, the code becomes easy to understand and maintain. For these features, important of React components is not hidden. So, they are absolute necessary and important in our app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of Components in React
&lt;/h2&gt;

&lt;p&gt;There are two main types of React components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Functional Component&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;They are modern and recommended way of writing component. Functional components are easy and mostly used today.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Welcome&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Class Component&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is an older approach of writing components. It is not used much today in modern apps.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Welcome&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt;&lt;/span&gt;&lt;span class="err"&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;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you want a detailed Functional VS Class Component, then comment and I’ll surely bring a detailed comparison soon.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Creating Your First Component
&lt;/h2&gt;

&lt;p&gt;For creating a React component, you follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a file first in the &lt;code&gt;src/&lt;/code&gt; or &lt;code&gt;src/components/&lt;/code&gt; (Mostly. It is recommended).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Write your component.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Export your component to make it available for use.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Import and use it in your app.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, I’ll show how to create your first React component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First Step:&lt;/strong&gt; Create a file with an extension &lt;code&gt;.jsx&lt;/code&gt; in &lt;code&gt;src/&lt;/code&gt;. i.e., create &lt;code&gt;Button.jsx&lt;/code&gt; in &lt;code&gt;src/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwdf61argxlanwodgev4q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwdf61argxlanwodgev4q.png" alt=" " width="496" height="297"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second Step:&lt;/strong&gt; Write your component in the file i.e.,&lt;code&gt;Button.jsx&lt;/code&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Button&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;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John Doe&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="nx"&gt;World&lt;/span&gt; &lt;span class="nx"&gt;by&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Third Step:&lt;/strong&gt; Export the component. You can export the component by writing this line at the end of the file (in which you have written your component).&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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, your component file would become:&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;function&lt;/span&gt; &lt;span class="nf"&gt;Button&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;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John Doe&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="nx"&gt;World&lt;/span&gt; &lt;span class="nx"&gt;by&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Fourth Step&lt;/strong&gt;: Import the component and use it in your app. To import add this line (recommended at the top) of the file where you want to use it:&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./Button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;code&gt;./Button&lt;/code&gt; is the relative path of the component file from the file where you are importing.&lt;/p&gt;

&lt;p&gt;To use the component, you can use one of these syntax. You can either use this:&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or:&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final code of the file where I used this component is:&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="nx"&gt;World&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, when you run the React app, your app will have a button as I shown in mine case:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpabi6nizk9gh61eekf6q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpabi6nizk9gh61eekf6q.png" alt=" " width="800" height="410"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Component Naming Rules
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Start the component name with Uppercase letter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use one component per file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use clear names for the components&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common Mistakes to Avoid
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Don’t use lowercase component names.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Don’t forget the &lt;code&gt;export&lt;/code&gt; statement&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Don’t return multiple elements without wrapper&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Important Links:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://react.dev/learn" rel="noopener noreferrer"&gt;Quick Start – React&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://react.dev/learn/your-first-component" rel="noopener noreferrer"&gt;Your First Component – React&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://vite.dev/guide/" rel="noopener noreferrer"&gt;Getting Started | Vite&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/understanding-react-project-structure-created-by-vite-beginners-guide-59ea"&gt;Understanding React Project Structure Created by Vite&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ahmad_mahboob/how-to-create-a-react-app-using-vite-step-by-step-guide-for-beginners-5eif"&gt;How to Create a React App Using Vite(Step-by-Step Guide for Beginners)&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>react</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Understanding React Project Structure Created by Vite (Beginner’s Guide)</title>
      <dc:creator>Ahmad Mahboob</dc:creator>
      <pubDate>Thu, 18 Dec 2025 13:48:31 +0000</pubDate>
      <link>https://dev.to/ahmad_mahboob/understanding-react-project-structure-created-by-vite-beginners-guide-59ea</link>
      <guid>https://dev.to/ahmad_mahboob/understanding-react-project-structure-created-by-vite-beginners-guide-59ea</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq9iarfb1ymzjwj09snui.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq9iarfb1ymzjwj09snui.png" alt="React Project Structure Image Created By Vite" width="800" height="410"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://vite.dev/guide" rel="noopener noreferrer"&gt;Vite&lt;/a&gt; is a blazing fast frontend build tool powering the next generation of web applications. It is a build tool that aims to provide a faster and leaner development experience for modern web projects. It is very popular among developers especially &lt;a href="https://react.dev/" rel="noopener noreferrer"&gt;React&lt;/a&gt; developers because it is easy to use and provides different useful features that help in the development. It is not only popular but also the recommended method for creating React Project in React official docs. So, understanding the structure of React project created by Vite would help a lot in the journey of learning and working with React. This is a simplified but detailed guide for beginners who are new to React and do not understand its project structure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;You should know how to create React project. If you don’t, that’s not a big deal. You can read &lt;a href="https://ahmadcodes.hashnode.dev/how-to-create-a-react-app-using-vite-step-by-step-guide-for-beginners" rel="noopener noreferrer"&gt;this guide&lt;/a&gt; to understand how to create your React project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create React Project using Vite (Quick Recap)
&lt;/h2&gt;

&lt;p&gt;As you know, to create our React Project, we run this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm create vite@latest project-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Overview of the Project Structure
&lt;/h2&gt;

&lt;p&gt;The Project looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;my-react-app/
├── node_modules/
├── public/
├── src/
├── index.html
├── .gitignore
├── package.json
├── vite.config.js
└── ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Project could seem complex to you at first. But believe me, it’s not that much complex as you’ve imagined.&lt;/p&gt;




&lt;p&gt;Now, I’ll briefly explain each folder and file.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  node_modules/
&lt;/h3&gt;

&lt;p&gt;This folder contains the dependencies of the project. Dependencies are those lines or files of code that are needed in our project. Mostly, dependencies are written by senior developers or organizations. Dependencies are regularly maintained and updated. But, we will not be playing much with this folder. Also, this folder is not pushed to GitHub. This is because these are third-party dependencies and anyone can easily install and use them in their project easily. So, pushing these on GitHub would burn the resources. Also, it is a good developer practice not to push them to GitHub.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  public/
&lt;/h3&gt;

&lt;p&gt;This folder holds the static assets. Static assets means those which are not updated frequently. The assets in this folder will be served on main ‘/’ path during development. Assets in &lt;code&gt;src/&lt;/code&gt; are processed by Vite for optimizations like hashing, bundling, and cache-busting. Assets in &lt;code&gt;public/&lt;/code&gt; are served as-is and are not processed by Vite, making them suitable for static files. Sometimes, it is not required. To prevent Vite from processing our those assets, we put them in public/ folder. These files can be directly accessed by their fixed path.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  src/
&lt;/h3&gt;

&lt;p&gt;It is the most important directory of a React Project. All important files are found here. You would be playing most of the time in this directory. I’ll briefly explain this directory:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;assets&lt;/strong&gt;: It contains images, icons, fonts, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;main.jsx:&lt;/strong&gt; Entry point. React Root is implemented here&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;App.jsx:&lt;/strong&gt; Root component. All other components are rendered from here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;components/:&lt;/strong&gt; The components are placed in this directory.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  index.html
&lt;/h3&gt;

&lt;p&gt;It is the main entry point of the app. It defines the root &lt;code&gt;&amp;lt;div id=”root”&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt;. It’s the placeholder from where React mounts and renders the application&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  package.json
&lt;/h3&gt;

&lt;p&gt;It contains the record of project dependencies and developer dependencies. It also contains the meta data of the app like name, version, type, scripts, etc. When we run &lt;code&gt;npm install&lt;/code&gt;, npm installs the dependencies listed in this file. So, if you delete your node_modules, you can install the node_modules again if you have package.json.If you accidentally delete &lt;code&gt;package.json&lt;/code&gt;, your project setup will break, as npm won’t know which dependencies to install.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  vite.config.js
&lt;/h3&gt;

&lt;p&gt;This file contains Vite’s configuration. Beginners usually do not need to modify it initially&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  .gitignore
&lt;/h3&gt;

&lt;p&gt;This file is important in source control. It controls those files which are not intended to push on GitHub. Like node_modules as I discussed above. This file contains the name of those files which are not to be pushed.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;I’ve tried to briefly explain the important parts of the React Project created using Vite. You would understand this better and better with the passage of time and more and more experience. For better understanding, do practice more and more. Because “&lt;em&gt;Practice makes a man perfect&lt;/em&gt;.”&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>frontend</category>
      <category>react</category>
      <category>vite</category>
    </item>
    <item>
      <title>How to Create a React App Using Vite (Step-by-Step Guide for Beginners)</title>
      <dc:creator>Ahmad Mahboob</dc:creator>
      <pubDate>Wed, 17 Dec 2025 00:34:35 +0000</pubDate>
      <link>https://dev.to/ahmad_mahboob/how-to-create-a-react-app-using-vite-step-by-step-guide-for-beginners-5eif</link>
      <guid>https://dev.to/ahmad_mahboob/how-to-create-a-react-app-using-vite-step-by-step-guide-for-beginners-5eif</guid>
      <description>&lt;p&gt;If you’re a beginner looking forward to diving into learning &lt;a href="https://react.dev" rel="noopener noreferrer"&gt;React&lt;/a&gt;. But you don’t know how to create the first React App. If you are starting to learn React, then you would be wondering how to create your first React app. Then, you are at the right place. In this blog, you will learn how to create React app and run your React app. There are many different ways of creating a React App. But we will be discussing the official suggested method to create first React app (i.e., Using &lt;a href="https://vite.dev" rel="noopener noreferrer"&gt;Vite&lt;/a&gt;). Here’s the complete step-by-step guidance and everything you need to create your first React app:&lt;br&gt;
&lt;strong&gt;First Step&lt;/strong&gt;: Run this command: (You’re supposed to have &lt;a href="https://nodejs.org/en" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt; version 20.19+. If you haven’t installed it, first install it from &lt;a href="https://nodejs.org/en/download" rel="noopener noreferrer"&gt;Node.js official website&lt;/a&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm create vite@latest project-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Second Step&lt;/strong&gt;: If prompted, press ‘y’ to proceed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0b8qalfztdgcjoc179ty.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0b8qalfztdgcjoc179ty.png" alt="Prompt for proceeding img" width="800" height="102"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Third Step&lt;/strong&gt;: Then, select the required framework (i.e., React) that you want to create, from the list like one shown in the image below. Keep in mind to navigate through the list by using Up/Down arrow keys. After selecting the required framework, press Enter key to proceed to next step.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdlqkdt9tulx7m90zcic8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdlqkdt9tulx7m90zcic8.png" alt="React Vite Setup" width="800" height="402"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Fourth Step&lt;/strong&gt;: After selecting the framework, a list of different variants are shown (like the one shown in the image below). From this list, select the required variant and then press Enter. Note: Navigate through the list using Up/Down arrow keys.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj3ys3bw64jpu6ny4pbol.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj3ys3bw64jpu6ny4pbol.png" alt="React Vite Setup JS" width="800" height="355"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Fifth Step&lt;/strong&gt;: After that, this option will appear (as shown in image below). So, select ‘Yes’ and press Enter key to proceed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw9fp2ebrhv3xkl2e6d1y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw9fp2ebrhv3xkl2e6d1y.png" alt="Prompt asking, " start="" width="800" height="95"&gt;&lt;/a&gt;&lt;br&gt;
Now, wait for npm to install required dependencies. Congrats, you have created your first React app.&lt;br&gt;
Now, to run your React app (if you chose ‘No’ in the last step), run these commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd project-name
npm install
npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, your app will be running on Localhost Port 5173:&lt;br&gt;
&lt;a&gt;localhost:5173&lt;/a&gt;&lt;br&gt;
You can also &lt;strong&gt;Ctrl + Click&lt;/strong&gt; to follow the link.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkczzaeu0332i0asp2jy6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkczzaeu0332i0asp2jy6.png" alt="React localhost port address" width="800" height="171"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Why Use Vite Instead of Create React App?
&lt;/h2&gt;

&lt;p&gt;There’s another way of creating React app by running this command:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;But this official method is deprecated and is not officially suggested. So, use Vite for creating React app.&lt;/p&gt;

&lt;p&gt;Related Links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://vite.dev/guide/" rel="noopener noreferrer"&gt;Getting Started | Vite&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://vite.dev/" rel="noopener noreferrer"&gt;Vite Official Website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://create-react-app.dev/" rel="noopener noreferrer"&gt;Create React App is Deprecated&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://react.dev/learn/build-a-react-app-from-scratch#vite" rel="noopener noreferrer"&gt;Build a React App from Scratch — React (Vite)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://react.dev/blog/2025/02/14/sunsetting-create-react-app" rel="noopener noreferrer"&gt;Sunsetting Create React App — React Blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nodejs.org/en" rel="noopener noreferrer"&gt;Node.js — Run JavaScript Everywhere&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://react.dev/learn/build-a-react-app-from-scratch" rel="noopener noreferrer"&gt;Build a React App from Scratch — React&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>vite</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
