<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sahils Verma  on Medium]]></title>
        <description><![CDATA[Stories by Sahils Verma  on Medium]]></description>
        <link>https://medium.com/@sahils.verma.1000?source=rss-6d89dfe4fccf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*W8P-7qvt1vaiHZec</url>
            <title>Stories by Sahils Verma  on Medium</title>
            <link>https://medium.com/@sahils.verma.1000?source=rss-6d89dfe4fccf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 24 May 2026 21:49:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sahils.verma.1000/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Props in React]]></title>
            <link>https://medium.com/@sahils.verma.1000/props-in-react-9ec008123efe?source=rss-6d89dfe4fccf------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ec008123efe</guid>
            <category><![CDATA[destructuring]]></category>
            <category><![CDATA[props-in-react]]></category>
            <category><![CDATA[spread-operator-in-js]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Sahils Verma ]]></dc:creator>
            <pubDate>Sat, 07 Jun 2025 09:52:38 GMT</pubDate>
            <atom:updated>2025-06-07T12:17:36.337Z</atom:updated>
            <content:encoded><![CDATA[<h3># What is props in React ?</h3><ul><li>In React, props (short for <em>properties</em>) is a <strong>parameter </strong>of <a href="https://react.dev/reference/react/createElement">React.createElement(type, <strong><em>props</em></strong>, …children)</a> that is <strong>an Object </strong>or <strong>null</strong>.</li><li>Props are used to <strong>Pass Data</strong> from One Component to Another — Typically <strong>Parent Component</strong> to <strong>Child Component</strong>.</li><li>The props object holds <strong><em>key-value</em></strong> pairs, where each <strong>key is a prop name</strong>, and the <strong>value is the data</strong> you want to pass.</li><li><strong>Purpose of Props :</strong></li><li>- Share data across the component hierarchy.</li><li>- Reuse components efficiently.</li><li>- Customize components dynamically.</li></ul><h3># Passing props to Pure React Object</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-uq4uOHxe21T8wJdMJcNdQ.png" /><figcaption>React code passing props to <strong>button</strong></figcaption></figure><h3># Corresponding <strong>JSX</strong></h3><ul><li>in JSX <strong>passing props</strong> just looklike <strong>adding attributes to HTML element.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-gnfMQVni0yXSUbxqixw_g.png" /><figcaption>here this HTML like structure is JSX not-React or HTML</figcaption></figure><p>in above snaps, there are <strong>className, onClick, disabled, type</strong> are <strong>pre-define props</strong></p><h3># Types of prop</h3><p>there are two types of prop in react</p><ul><li><strong>Pre-define</strong>(i.e key, children, src, className, id, etc).</li><li><strong>User-define : </strong>defining custom <strong>key=value</strong> pair to <strong>share desire Data</strong> to component.</li></ul><h3># User Define Props.</h3><ul><li>User can define there custom props as a pre-define props.</li></ul><p># all the props of corresponding HTML element render as Attribute</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T_iQyMpiF2u7zOJN9CZAyA.png" /><figcaption>passing custom prop to div</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p9NYzonn8UMb-pkg45VI_A.png" /><figcaption>all the props corresponding toHTML element render as Attribute</figcaption></figure><ul><li>“div” use <strong>mytitle </strong>as attribute. (note for element <strong>atrributes are always in lowercase</strong>).</li></ul><h3>## How can we use “Custom” prop</h3><ul><li>we can use “Custom prop” in our created “Custom Component”.</li><li>let us create our custom <strong>MyCard </strong>component and use props there.</li><li>Step 1 : create a function <strong>MyCard </strong>and accept a parameter as <strong>props</strong>.</li><li>Step 2 : create a reactElement object <strong>cardElement</strong></li><li>Step 3 : pass the <strong>MyCard function</strong> and <strong>props </strong>in it React.createElement()</li><li>Step 4 : log the <strong>props </strong>parameter in <strong>MyCard</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kUi4cRJa82WgAaxL05MmqQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*BPwIRSOcDx0hCjAedsbbQw.png" /><figcaption>log</figcaption></figure><ul><li>look createElement <strong>invoke MyCard </strong>function with <strong>props </strong>object.</li><li>now we can use this props object inside our MyCard function or Component.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YIjVWf8sWOyUzNXqPgqFnA.png" /><figcaption>using props here</figcaption></figure><h3># Corresponding JSX</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FsmRMQbHDFLTBf-5Nvx7Tw.png" /><figcaption>jsx code</figcaption></figure><h3># Children Prop</h3><ul><li>what we pass as <strong>3rd </strong>parameter of <strong>React.createElement()</strong></li><li><strong>that </strong>also <strong>pass as children </strong>in <strong>props object.</strong></li><li>Note: we not create any children key=value pair this is pass my React.createElement() method</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NK-sYDcMPy2M9_hHISXFJw.png" /><figcaption>children prop</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*ByAfSO6z3ALM9XgGZOMl4w.png" /><figcaption>log</figcaption></figure><ul><li>see at line 12, “hello” the 3rd parameter is passed as children in props</li></ul><h3># Corresponding JSX</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lt-Squz9mY7qMM7SfRMz7Q.png" /><figcaption>jsx</figcaption></figure><ul><li>In JSX, children pass as <strong>between the opening and closing tag.</strong></li><li>we can also pass <strong>Nested JSX</strong> that is all <strong>stored in children prop.</strong></li></ul><h3># Props with Destructuring syntax</h3><ul><li>we are usually see at function componet ({title}) this kind on syntax.</li><li>this is object destructuring simply.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q1qGkrWB4T9Hmo9eei4PNg.png" /><figcaption>Destructuring Syntax</figcaption></figure><ul><li>Destructuring is a javascript concept.</li><li>by the help of destructuring we can read only those prop from props object that we want.</li></ul><h3># Props with Spread (…)Operator Syntax.</h3><ul><li>this … three dots are know as spread operator in javascript.</li><li>we are also some where in react code {…props} this type of thing.</li><li>that is acutally spread operator.</li><li>Example :</li><li>we are creating a Custom button Component PrimaryBtn.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ut6MVx7PskhnUopyT8zQZg.png" /><figcaption>spread operator</figcaption></figure><ul><li>look in PrimaryBtn Component we pass three props(onClick,style and children (by nesting)) that are for button.</li><li>instead of passing one by one prop to &lt;button&gt; component .</li><li>we pass all the props at once by use {…props} syntax to &lt;button&gt; component inside PrimaryBtn.</li><li>Now we can pass any number of props to &lt;PrimaryBtn&gt; component that are all the props directly pass to &lt;button&gt; component.</li></ul><h3>🧩 Mini Project: <strong>Profile Card Component</strong></h3><p>Let’s build a small <strong>Profile Card App</strong> that demonstrates how props work — including children, destructuring, and the spread operator.</p><h3>💼 Goal:</h3><ul><li>Build a ProfileCard component that accepts:</li><li>name, title, avatar (props)</li><li>Custom content using children</li><li>Render multiple ProfileCards using an array of data</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9hXLIzvQ7ns-kKhWDNkPNQ.png" /><figcaption>Project Ui</figcaption></figure><h3>💡 Concepts Practiced</h3><ul><li>Passing props to custom components</li><li>Using children for custom inner content</li><li>Applying object destructuring in functional components</li></ul><h3>📌 Optional Challenge</h3><p>Enhance it further:</p><ul><li>Add a button inside each card using the <strong>spread operator</strong></li><li>Add onClick behavior like “Follow” or “Send Message”</li><li>Add conditional styling using props (e.g., isOnline)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ec008123efe" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>