<?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>Forem: Selvi Parasakthi K</title>
    <description>The latest articles on Forem by Selvi Parasakthi K (@selviparasakthik).</description>
    <link>https://forem.com/selviparasakthik</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%2F3610466%2F257de7ce-5e42-4ab1-a3b1-2bb2046cf5e5.jpeg</url>
      <title>Forem: Selvi Parasakthi K</title>
      <link>https://forem.com/selviparasakthik</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/selviparasakthik"/>
    <language>en</language>
    <item>
      <title>How to Use React Components Inside Angular (Step-by-Step Guide)</title>
      <dc:creator>Selvi Parasakthi K</dc:creator>
      <pubDate>Tue, 31 Mar 2026 08:10:42 +0000</pubDate>
      <link>https://forem.com/selviparasakthik/how-to-use-react-components-inside-angular-step-by-step-guide-4a91</link>
      <guid>https://forem.com/selviparasakthik/how-to-use-react-components-inside-angular-step-by-step-guide-4a91</guid>
      <description>&lt;p&gt;In real-world projects, teams often work with multiple frameworks like &lt;strong&gt;React&lt;/strong&gt; and &lt;strong&gt;Angular&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But what if you already built a component in React and want to reuse it inside an Angular application?&lt;/p&gt;

&lt;p&gt;👉 Do you need to rewrite everything?&lt;br&gt;
👉 Or is there a smarter way?&lt;/p&gt;

&lt;p&gt;Good news: &lt;strong&gt;You can directly use React components inside Angular&lt;/strong&gt; using &lt;strong&gt;Web Components&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this blog, I’ll walk you through a &lt;strong&gt;step-by-step process with clear explanations&lt;/strong&gt;, so even if you try this for the first time, it will work.&lt;/p&gt;


&lt;h2&gt;
  
  
  🧠 Understanding the Idea First
&lt;/h2&gt;

&lt;p&gt;Before jumping into code, let’s understand what we are doing.&lt;/p&gt;

&lt;p&gt;React components are not directly compatible with Angular because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React uses a Virtual DOM&lt;/li&gt;
&lt;li&gt;Angular uses its own template system&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So they don’t “talk” to each other natively.&lt;/p&gt;
&lt;h3&gt;
  
  
  💡 Solution: Web Components
&lt;/h3&gt;

&lt;p&gt;Web Components are browser-native custom HTML elements.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;random-picker&amp;gt;&amp;lt;/random-picker&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once we convert a React component into a Web Component:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Angular treats it like a normal HTML tag&lt;/li&gt;
&lt;li&gt;No framework conflict&lt;/li&gt;
&lt;li&gt;Fully reusable&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🛠 Step 1: Create a React Project
&lt;/h2&gt;

&lt;p&gt;We’ll first build our React component separately.&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 random-picker
&lt;span class="nb"&gt;cd &lt;/span&gt;random-picker
npm &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  👉 Why Vite?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Fast build tool&lt;/li&gt;
&lt;li&gt;Simple configuration&lt;/li&gt;
&lt;li&gt;Perfect for creating reusable components&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📦 Step 2: Install r2wc
&lt;/h2&gt;

&lt;p&gt;We use a library to convert React → Web Component.&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; @r2wc/react-to-web-component
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  👉 Why this library?
&lt;/h3&gt;

&lt;p&gt;Normally, converting React into a Web Component requires a lot of manual work.&lt;/p&gt;

&lt;p&gt;This package:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Wraps your React component&lt;/li&gt;
&lt;li&gt;Handles lifecycle&lt;/li&gt;
&lt;li&gt;Maps props automatically&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ⚛️ Step 3: Create a Simple React Component
&lt;/h2&gt;

&lt;p&gt;Now let’s create a clean and minimal component (no CSS, so beginners can focus on logic).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/components/RandomPicker.tsx&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&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="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;type&lt;/span&gt; &lt;span class="nx"&gt;Props&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt;
  &lt;span class="nl"&gt;title&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;onResult&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;RandomPicker&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="nx"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
  &lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Pick one&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;onResult&lt;/span&gt;&lt;span class="p"&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="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setResult&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Function to pick a random item&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pick&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="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="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;randomItem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
      &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)];&lt;/span&gt;

    &lt;span class="nf"&gt;setResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomItem&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// send result back (optional)&lt;/span&gt;
    &lt;span class="nx"&gt;onResult&lt;/span&gt;&lt;span class="p"&gt;?.(&lt;/span&gt;&lt;span class="nx"&gt;randomItem&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;pick&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Pick Random&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Result: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&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;code&gt;items&lt;/code&gt; → list of values&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;title&lt;/code&gt; → heading&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;onResult&lt;/code&gt; → callback function&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;pick()&lt;/code&gt; → selects a random item&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is just a normal React component.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔁 Step 4: Convert React to Web Component
&lt;/h2&gt;

&lt;p&gt;Now comes the important part - converting your React component into something Angular can understand.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/random-picker-wc.ts&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;r2wc&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;@r2wc/react-to-web-component&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;RandomPicker&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;./components/RandomPicker&lt;/span&gt;&lt;span class="dl"&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;RandomPickerWC&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;r2wc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;RandomPicker&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;onResult&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;function&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Register as HTML element&lt;/span&gt;
&lt;span class="nx"&gt;customElements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;random-picker&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;RandomPickerWC&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🔍 Deep Explanation
&lt;/h3&gt;

&lt;h4&gt;
  
  
  📌 React → Angular Compatibility Problem
&lt;/h4&gt;

&lt;p&gt;React and Angular are built on completely different architectures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React uses a Virtual DOM&lt;/li&gt;
&lt;li&gt;Angular uses template-driven rendering&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because of this difference, Angular cannot directly render a React component.&lt;br&gt;
To make them work together, we need a framework-independent layer — this is where Web Components come in.&lt;/p&gt;
&lt;h4&gt;
  
  
  📌 Role of &lt;code&gt;r2wc()&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;The r2wc function acts as a bridge between React and the browser.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It wraps your React component&lt;/li&gt;
&lt;li&gt;Converts it into a native Custom Element&lt;/li&gt;
&lt;li&gt;Handles mounting, updating, and unmounting internally&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After this conversion, your React component behaves like a normal HTML tag.&lt;/p&gt;

&lt;p&gt;👉 In simple terms:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;React Component → Web Component → Usable in Angular
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  📌 Why We Define &lt;code&gt;props&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Web Components don’t receive JavaScript props like React.&lt;br&gt;
They receive HTML attributes, which are always strings.&lt;/p&gt;

&lt;p&gt;So we must explicitly define how each prop should be interpreted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;onResult&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;function&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  📌 Understanding Each Prop Type
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;json&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;Used when passing arrays or objects&lt;/li&gt;
&lt;li&gt;Converts string → actual JavaScript data&lt;/li&gt;
&lt;li&gt;Example: &lt;code&gt;"['Apple','Mango']"&lt;/code&gt; → &lt;code&gt;["Apple","Mango"]&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;string&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;Used for simple text values&lt;/li&gt;
&lt;li&gt;Passed directly without transformation&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;function&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;Used for callbacks/events&lt;/li&gt;
&lt;li&gt;Enables communication from React → Angular&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h4&gt;
  
  
  📌 Role of &lt;code&gt;customElements.define()&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;customElements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;random-picker&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;RandomPickerWC&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This step registers your component in the browser.&lt;/p&gt;

&lt;p&gt;After registration:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;random-picker&amp;gt;&lt;/code&gt; becomes a valid HTML element&lt;/li&gt;
&lt;li&gt;It can be used anywhere (Angular, HTML, etc.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without this step:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The browser will not recognize your component&lt;/li&gt;
&lt;li&gt;Nothing will render&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now the browser understands this element.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚡ Step 5: Build React Project (Using vite)
&lt;/h2&gt;

&lt;p&gt;Instead of doing a normal build, we configure Vite to generate a reusable Web Component bundle.&lt;/p&gt;

&lt;p&gt;🧩 Create Vite Config&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// vite.config.ts&lt;/span&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="s2"&gt;vite&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&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="s2"&gt;@vitejs/plugin-react&lt;/span&gt;&lt;span class="dl"&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="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="na"&gt;build&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;lib&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;src/random-picker-wc.ts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;RandomPicker&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;fileName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;random-picker&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;formats&lt;/span&gt;&lt;span class="p"&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;es&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="na"&gt;cssCodeSplit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This generates a file inside the &lt;code&gt;dist&lt;/code&gt; folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dist/random-picker.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 This file contains your Web Component ready to use in Angular.&lt;/p&gt;




&lt;h2&gt;
  
  
  🅰️ Step 6: Setup Angular Project
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ng new angular-app
&lt;span class="nb"&gt;cd &lt;/span&gt;angular-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔗 Step 7: Load React Script in Angular
&lt;/h2&gt;

&lt;p&gt;Open &lt;code&gt;angular.json&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add your React build file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="s2"&gt;"src/assets/random-picker.js"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure you copy &lt;code&gt;random-picker.js&lt;/code&gt; from the React &lt;code&gt;dist&lt;/code&gt; folder into Angular &lt;code&gt;src/assets/&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  👉 Why this step?
&lt;/h3&gt;

&lt;p&gt;Angular doesn’t know about your React component.&lt;br&gt;
So we manually load the script globally.&lt;/p&gt;


&lt;h2&gt;
  
  
  ⚠️ Step 8: Enable Custom Elements in Angular
&lt;/h2&gt;

&lt;p&gt;Angular throws an error for unknown HTML tags.&lt;/p&gt;

&lt;p&gt;To fix that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&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;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;CUSTOM_ELEMENTS_SCHEMA&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;@angular/core&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="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app-root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;templateUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./app.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;schemas&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;CUSTOM_ELEMENTS_SCHEMA&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&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;
  
  
  👉 Why?
&lt;/h3&gt;

&lt;p&gt;This tells Angular:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Don’t complain about unknown elements — I know what I’m doing.”&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🧩 Step 9: Use React Component in Angular
&lt;/h2&gt;

&lt;p&gt;Now you can use your React Web Component just like a normal HTML element in Angular.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;random-picker&lt;/span&gt;
  &lt;span class="na"&gt;title=&lt;/span&gt;&lt;span class="s"&gt;"Fruits Picker"&lt;/span&gt;
  &lt;span class="na"&gt;[attr.items]=&lt;/span&gt;&lt;span class="s"&gt;"'[\"&lt;/span&gt;&lt;span class="na"&gt;Apple&lt;/span&gt;&lt;span class="err"&gt;\",\"&lt;/span&gt;&lt;span class="na"&gt;Mango&lt;/span&gt;&lt;span class="err"&gt;\",\"&lt;/span&gt;&lt;span class="na"&gt;Orange&lt;/span&gt;&lt;span class="err"&gt;\"]'"&lt;/span&gt;
&lt;span class="nt"&gt;&amp;gt;&amp;lt;/random-picker&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🎉 Final Result
&lt;/h2&gt;

&lt;p&gt;Now your Angular app renders a React component 🎯&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React logic runs inside&lt;/li&gt;
&lt;li&gt;Angular displays it&lt;/li&gt;
&lt;li&gt;Both work together seamlessly&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧾 Summary (What You Learned)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;React and Angular are not directly compatible&lt;/li&gt;
&lt;li&gt;Web Components act as a bridge&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;r2wc&lt;/code&gt; simplifies conversion&lt;/li&gt;
&lt;li&gt;Angular can consume custom elements easily&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔥 When Should You Use This?
&lt;/h2&gt;

&lt;p&gt;This approach is perfect when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want to reuse React components&lt;/li&gt;
&lt;li&gt;Multiple teams use different frameworks&lt;/li&gt;
&lt;li&gt;You are building a shared component library&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ⚠️ Common Mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;❌ Forgetting &lt;code&gt;CUSTOM_ELEMENTS_SCHEMA&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;❌ Not adding script in &lt;code&gt;angular.json&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;❌ Passing objects instead of JSON string&lt;/li&gt;
&lt;/ul&gt;




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

&lt;p&gt;This technique is extremely powerful.&lt;/p&gt;

&lt;p&gt;Once you understand this pattern, you can:&lt;br&gt;
👉 Use React components inside Angular applications&lt;br&gt;
👉 Reuse UI across different projects and frameworks&lt;br&gt;
👉 Build framework-independent UI libraries&lt;/p&gt;




&lt;p&gt;If this helped you, feel free to ❤️ and share!&lt;/p&gt;

&lt;p&gt;Happy coding 🚀&lt;/p&gt;

</description>
      <category>webcomponents</category>
      <category>react</category>
      <category>angular</category>
      <category>frontend</category>
    </item>
    <item>
      <title>How to Use Styled Components in React with Dynamic Props (Beginner Friendly Guide)</title>
      <dc:creator>Selvi Parasakthi K</dc:creator>
      <pubDate>Sun, 22 Feb 2026 15:05:16 +0000</pubDate>
      <link>https://forem.com/selviparasakthik/how-to-use-styled-components-in-react-with-dynamic-props-beginner-friendly-guide-2kbi</link>
      <guid>https://forem.com/selviparasakthik/how-to-use-styled-components-in-react-with-dynamic-props-beginner-friendly-guide-2kbi</guid>
      <description>&lt;p&gt;When building modern React applications, styling plays a major role in making the UI dynamic and reusable.&lt;/p&gt;

&lt;p&gt;Instead of writing separate CSS files, Styled Components allows us to write actual CSS inside JavaScript and also apply styles dynamically using props.&lt;/p&gt;

&lt;p&gt;In this blog, let's learn&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is styled-components&lt;/li&gt;
&lt;li&gt;How to install styled-components&lt;/li&gt;
&lt;li&gt;How styled-components work&lt;/li&gt;
&lt;li&gt;How to pass dynamic props&lt;/li&gt;
&lt;li&gt;How to style UI based on props like

&lt;ul&gt;
&lt;li&gt;Background color&lt;/li&gt;
&lt;li&gt;Text Color&lt;/li&gt;
&lt;li&gt;Border Radius&lt;/li&gt;
&lt;li&gt;Image&lt;/li&gt;
&lt;li&gt;Shape&lt;/li&gt;
&lt;li&gt;Shadow&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  1. What is styled-component
&lt;/h3&gt;

&lt;p&gt;Styled Components is a &lt;strong&gt;CSS-in-JS&lt;/strong&gt; library that allows developers to write CSS directly inside JavaScript. It helps in creating reusable styled UI components while also enabling dynamic styling through props.&lt;/p&gt;

&lt;p&gt;By using Styled Components, we can avoid class name conflicts and maintain a clean, component-based styling approach within our React applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Install Styled Components Package
&lt;/h3&gt;

&lt;p&gt;First, install the required packages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install styled-components
npm install --save-dev @types/styled-components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. How styled-component work
&lt;/h3&gt;

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

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

export const Title = styled.h1`
  color: blue;
`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now &lt;code&gt;Title&lt;/code&gt; becomes a styled React component which we can use like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Title&amp;gt;Hello World&amp;lt;/Title&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Dynamic Styling Using Props
&lt;/h3&gt;

&lt;p&gt;The real power of &lt;code&gt;styled-components&lt;/code&gt; comes when we pass props.&lt;br&gt;
We can change the UI dynamically based on user input or state values.&lt;/p&gt;
&lt;h3&gt;
  
  
  5. Creating a Dynamic Card Component
&lt;/h3&gt;

&lt;p&gt;Let’s create a profile card where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Background color is dynamic&lt;/li&gt;
&lt;li&gt;Text color is dynamic&lt;/li&gt;
&lt;li&gt;Border radius is dynamic&lt;/li&gt;
&lt;li&gt;Shadow is toggleable&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Step 1: Create Styled Card
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const Card = styled.div&amp;lt;{
  bg: string;
  textColor: string;
  radius: number;
  shadow: boolean;
}&amp;gt;`
  width: 300px;
  padding: 20px;
  text-align: center;

  background: ${({ bg }) =&amp;gt; bg};
  color: ${({ textColor }) =&amp;gt; textColor};
  border-radius: ${({ radius }) =&amp;gt; radius}px;

  transition: 0.3s;

  ${({ shadow }) =&amp;gt;
    shadow &amp;amp;&amp;amp;
    `
    box-shadow: 0 8px 20px rgba(0,0,0,0.1);
  `}
`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Passing Image as Background&lt;/strong&gt;&lt;br&gt;
Instead of using an &lt;code&gt;&amp;lt;img/&amp;gt;&lt;/code&gt; tag, we can also apply image dynamically as a background.&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 2: Create Avatar Component
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const Avatar = styled.div&amp;lt;{
  shape: string;
  image: string;
}&amp;gt;`
  width: 100px;
  height: 100px;

  border-radius: ${({ shape }) =&amp;gt;
    shape === "circle" ? "50%" : "12px"};

  background: url(${props =&amp;gt; props.image})
    center/cover no-repeat;
`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;image&lt;/code&gt;→ Dynamic image URL&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;shape&lt;/code&gt; → Circle or square avatar&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Using Styled Components in React&lt;/strong&gt;&lt;br&gt;
Now let’s pass these props from our React component.&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 3: Profile Card Component
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Props = {
  name: string;
  role: string;
  bg: string;
  textColor: string;
  radius: number;
  shadow: boolean;
  shape: string;
  image: string;
};

export default function ProfileCard(props: Props) {
  return (
    &amp;lt;Card
      bg={props.bg}
      textColor={props.textColor}
      radius={props.radius}
      shadow={props.shadow}
    &amp;gt;
      &amp;lt;Avatar
        shape={props.shape}
        image={props.image}
      /&amp;gt;

      &amp;lt;h2&amp;gt;{props.name}&amp;lt;/h2&amp;gt;
      &amp;lt;p&amp;gt;{props.role}&amp;lt;/p&amp;gt;
    &amp;lt;/Card&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Passing Values from State&lt;/strong&gt;&lt;br&gt;
We can now control the styles dynamically using React state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ProfileCard
  name="John Doe"
  role="Frontend Developer"
  bg="#ffffff"
  textColor="#000000"
  radius={12}
  shadow={true}
  shape="circle"
  image="https://i.pravatar.cc/100"
/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Changing &lt;code&gt;bg&lt;/code&gt; will change background color&lt;/li&gt;
&lt;li&gt;Changing &lt;code&gt;textColor&lt;/code&gt; will update text&lt;/li&gt;
&lt;li&gt;Changing &lt;code&gt;radius&lt;/code&gt; will update card shape&lt;/li&gt;
&lt;li&gt;Changing &lt;code&gt;shape&lt;/code&gt; will update avatar&lt;/li&gt;
&lt;li&gt;Changing &lt;code&gt;image&lt;/code&gt; will update avatar background
All UI updates dynamically ✨&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Styled Components helps us:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep styling close to components&lt;/li&gt;
&lt;li&gt;Create reusable UI&lt;/li&gt;
&lt;li&gt;Apply styles dynamically&lt;/li&gt;
&lt;li&gt;Build interactive UI easily&lt;/li&gt;
&lt;li&gt;Maintain clean code structure
Using props, we can control the complete UI styling from React state without writing separate CSS files.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>react</category>
      <category>styledcomponents</category>
    </item>
    <item>
      <title>🚀Understanding Webpack: A begineer friendly Guide with Examples</title>
      <dc:creator>Selvi Parasakthi K</dc:creator>
      <pubDate>Sat, 15 Nov 2025 09:19:02 +0000</pubDate>
      <link>https://forem.com/selviparasakthik/understanding-webpack-a-begineer-friendly-guide-with-examples-3dp</link>
      <guid>https://forem.com/selviparasakthik/understanding-webpack-a-begineer-friendly-guide-with-examples-3dp</guid>
      <description>&lt;p&gt;Webpack is one of the most powerful tools in modern JavaScript development. If you're building a front-end application, you've almost certainly seen it in action—even if you didn't notice it.&lt;/p&gt;

&lt;p&gt;This blog breaks down what Webpack does, why it matters, and how to set up a basic Webpack configuration with loaders, CSS/SASS support, and JS minification.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What is Webpack?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Webpack is a static module bundler for modern JavaScript applications.&lt;br&gt;
When Webpack processes your application, it creates an internal dependency graph starting from one or more entry points—then bundles all modules (JS, CSS, images, etc.) into one or more optimized files.&lt;/p&gt;

&lt;p&gt;In simple words:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;✅ Webpack bundles your project's files (JS, CSS, images…)&lt;br&gt;
into fewer, optimized files so your application loads faster.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Sample Project Setup&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Reference repository:&lt;br&gt;
👉&lt;a href="https://github.com/Selvi-Parasakthi-K/webpack-practice" rel="noopener noreferrer"&gt;https://github.com/Selvi-Parasakthi-K/webpack-practice&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Initialize the Project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a &lt;code&gt;package.json&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install Webpack and Webpack CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i webpack webpack-cli --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add &lt;code&gt;"build": "webpack"&lt;/code&gt; in the scripts section, so running &lt;code&gt;npm run build&lt;/code&gt; will trigger Webpack.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
  "build": "webpack"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Create webpack.config.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const path = require("path");

module.exports = {
  entry: "./src/index.js",
  output: {
    filename: "bundle.js",
    path: path.resolve(__dirname, "./dist"),
  },
  mode: "none",
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells webpack:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;entry&lt;/strong&gt; → starting file of your app&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;output&lt;/strong&gt; → where to store bundled files&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;mode&lt;/strong&gt; → can be "development", "production", or "none"&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Loaders in Webpack&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Loaders allow Webpack to handle non-JavaScript files like images, CSS, and SASS.&lt;/p&gt;

&lt;p&gt;Think of loaders as translators—Webpack doesn’t understand images or CSS by default, so loaders help convert them into modules.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Image Loader Example&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Install &lt;code&gt;file-loader&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i file-loader --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add loader rule:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module: {
  rules: [
    {
      test: /\.(jfif|png)$/,
      use: ["file-loader"],
    },
  ],
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;Setting the Public Path&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Public path tells Webpack where the final bundled files (like images) will be loaded from in the browser. It basically sets the base URL for all assets so the browser knows the correct location to fetch them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;output: {
  filename: "bundle.js",
  path: path.resolve(__dirname, "./dist"),
  publicPath: "./dist/",
},
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures images get the correct URL in the final bundle.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Adding CSS Support&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Install these loaders:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;css-loader → lets Webpack understand CSS files&lt;/li&gt;
&lt;li&gt;style-loader → injects CSS into the browser&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Order matters → loaders run from right to left&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  test: /\.css$/,
  use: ["style-loader", "css-loader"], 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If reversed, Webpack will fail.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Adding SASS/SCSS Support&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Install:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i sass sass-loader style-loader css-loader --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the rule:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  test: /\.scss$/,
  use: [
    "style-loader",
    "css-loader",
    {
      loader: "sass-loader",
      options: {
        implementation: require("sass"),
      },
    },
  ],
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Plugins in Webpack&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Plugins in Webpack allow you to perform extra tasks during the build process—like optimizing, minifying, or transforming files—that go beyond what loaders can do.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Minifying JavaScript (Production Optimization)&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Use &lt;code&gt;terser-webpack-plugin&lt;/code&gt; to minify JS.&lt;/p&gt;

&lt;p&gt;Install:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install terser-webpack-plugin --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add to your config:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const path = require("path");
const TerserPlugin = require("terser-webpack-plugin");

module.exports = {
  entry: "./src/index.js",
  output: {
    filename: "bundle.js",
    path: path.resolve(__dirname, "./dist"),
    publicPath: "./dist/",
  },
  mode: "none",
  module: {
    rules: [],
  },
  plugins: [new TerserPlugin()],
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This reduces file size and improves performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;🎯 Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Webpack may look complex at first, but once you understand the basics—entry, output, loaders, and plugins—it becomes an incredibly powerful tool.&lt;/p&gt;

&lt;p&gt;With this setup, you can:&lt;/p&gt;

&lt;p&gt;✔ Bundle JavaScript&lt;br&gt;
✔ Load images&lt;br&gt;
✔ Add CSS &amp;amp; SASS support&lt;br&gt;
✔ Minify and optimize output&lt;/p&gt;

&lt;p&gt;You now have a complete Webpack setup suitable for any small or medium JavaScript project!&lt;/p&gt;

</description>
      <category>webpack</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
