<?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 Sudheer Babu on Medium]]></title>
        <description><![CDATA[Stories by Sudheer Babu on Medium]]></description>
        <link>https://medium.com/@sudheerbabu.putta?source=rss-f36348fd1148------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*W7LxdZt8slB9BC8H</url>
            <title>Stories by Sudheer Babu on Medium</title>
            <link>https://medium.com/@sudheerbabu.putta?source=rss-f36348fd1148------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 24 May 2026 03:41:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sudheerbabu.putta/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[How to use Props in React]]></title>
            <link>https://medium.com/@sudheerbabu.putta/how-to-use-props-in-react-d5b28a0347cf?source=rss-f36348fd1148------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5b28a0347cf</guid>
            <dc:creator><![CDATA[Sudheer Babu]]></dc:creator>
            <pubDate>Wed, 11 Jan 2023 10:36:27 GMT</pubDate>
            <atom:updated>2023-01-11T10:36:27.517Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KqiIG8sl7SKyykSOUfAszw.png" /><figcaption>Image of Props in React JS</figcaption></figure><h3>What are Props in React?</h3><p>Props are passed from a parent component to the child component. Now, if you haven’t understood props yet, it allows us to reuse a component logic dynamically which means that the data or information in the component will not be static. We’ll understand this with the help of an example later on.</p><h3>Props Syntax</h3><p>We can use the react props in two different ways and both have their own different syntaxes. The two ways of using props in react app are:</p><h4>Without destructuring:</h4><p>The syntax of defining props without destructuring is given below.</p><pre>function Course(props) {<br>    &lt;div&gt;{props.courseName}&lt;/div&gt;<br>}</pre><h4>With destructuring:</h4><p>The syntax of defining props as a destructuring argument is given below.</p><pre>function Course({courseName}) {<br>    &lt;div&gt;{courseName}&lt;/div&gt;<br>}</pre><p>The detailed working of both the given methods is explained below in this blog.</p><h3>How to use Props in React?</h3><p>Now let’s see a full example and understand how we can use props in a react app. Props are very easy to understand. In this example, we’ll need two things: first one is the main function component <strong>(App.js)</strong> and a second component <strong>(Course) </strong>which we is going to render in our App.js component.</p><h4>App.js Component File:</h4><p>This is the App component (parent) which is the main file of a React application and in this component, we’ll be rendering our second component i.e., Course component which acts as a child component in which we’ll be passing props.</p><pre>import React from &#39;react&#39;<br><br>export const App = () =&gt; {<br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Online Learning Courses&lt;/h1&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><h4>Course component</h4><p>This component will have a prop called <strong><em>courseName </em></strong>which will get its value dynamically after rendering inside the App.js component.</p><pre>import React from &#39;react&#39;<br><br>export const Courses = (props) =&gt; {<br>  return (<br>    &lt;div&gt;<br>        &lt;ul style={{fontSize:&#39;25px&#39;,color:&#39;green&#39;}}&gt;<br>            &lt;li&gt;{props.courseName}&lt;/li&gt;<br>        &lt;/ul&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><h3>Different ways of using props in react</h3><p>Till now we have understood the basic syntax of using props in react and now we’ll learn what are the ways through which we can use props in a react app. So, there are two ways of using props and those are discussed in detail below.</p><h3>1. using Props without Destructuring</h3><p>The First way of using props is to use them without destructuring. When using props without destructuring we pass an argument known as <strong>props </strong>in the function. Let’s understand it step by step with the help of an example.</p><h3>Step 1: Pass “props” as argument in function</h3><p>To use props, we first pass the “props” keyword as an argument into our function which can be seen as follows.</p><pre>Courses = (props) =&gt; {<br>      ......<br>      ......<br>}</pre><h3>Step 2: Using variables directly in JSX template</h3><p>Here we are not declaring the variables before rather we are using them directly into our JSX template i.e., into our &lt;li&gt; element.</p><pre>Courses = (props) =&gt; {<br>  return (<br>    &lt;div&gt;<br>        &lt;ul style={{fontSize:&#39;25px&#39;,color:&#39;green&#39;}}&gt;<br>            &lt;li&gt;{props.courseName}&lt;/li&gt;<br>        &lt;/ul&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><h3>Step 3: Pass data in App.js component</h3><p>Now our data will be passed to the main component i.e. App.js and will look like we are passing the attributes.</p><pre>import React from &#39;react&#39;<br>import { Courses } from &#39;./Courses&#39;<br><br>export const App = () =&gt; {<br>  return (<br>    &lt;div&gt;<br>      &lt;h1 style={{color:&quot;red&quot;, lineHeight : 2, padding: 10}}&gt;Online Learning Courses&lt;/h1&gt;<br>      &lt;Courses courseName=&quot;FrontEnd Developer&quot; /&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><h3>Output:</h3><p>After passing the props, your output will look like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*Q7vLjyC2N-AMb4bS_jdOwQ.png" /><figcaption>Props without Destructuring Output</figcaption></figure><p>So, now we can use data dynamically for any component with the above method and can declare multiple props as per our requirement. Next we’ll see how to use props with destructuring.</p><h3>2. using Props with Destructuring</h3><p>Compared to the above method (without destructuring), this is the most commonly used method to use props as it becomes very easy to modify the function and also it takes less time therefore making it as an optimized way.</p><p>In this method, we don’t declare variables first or pass them directly to the JSX template. Instead of passing the props as an argument we destructured and passed in the variables like the function argument. Let’s understand this in detail and see it step by step with the help of an example.</p><h3>Step 1: Destructuring the Course component</h3><p>Here we are not declaring the variables rather we are destructuring and passing the variables as function arguments. We can read these props by listing their names which are available inside <strong>({ and }) </strong>directly after the Course component.</p><pre>Course = ({courseName, courseType}) =&gt; {<br>  return (<br>    &lt;div&gt;<br>        &lt;ul  style={{fontSize:&#39;25px&#39;,color:&#39;green&#39;}}&gt;<br>            &lt;li&gt;{courseName}&lt;/li&gt;<br>            &lt;li&gt;{courseType}&lt;/li&gt;<br>        &lt;/ul&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><h3>Step 2: Pass data in App.js component</h3><p>Now our data will be passed to the main component i.e. App.js and will look like we are passing the attributes.</p><pre>import React from &#39;react&#39;<br>import { Course } from &#39;./Course&#39;<br><br>export const App = () =&gt; {<br>  return (<br>    &lt;div&gt;<br>      &lt;h1 style={{color:&quot;red&quot;, lineHeight : 2, padding: 10}}&gt;Online Learning Courses&lt;/h1&gt;<br>      &lt;Course courseName=&quot;FrontEnd Developer&quot; courseType=&quot;Developer&quot; /&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><h3>Output:</h3><p>After passing the props, your output will look like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*bisyODJxfg4bxCaGufpXSg.png" /><figcaption>Props with destructuring Output</figcaption></figure><h3>How to specify default value of prop</h3><p>Sometimes, we don’t want the props value to be empty or when no value is specified, at that time we can specify a default value just by destructuring and putting <strong>= </strong>sign and the default value right after the parameter as shown below.</p><pre>Course = ({courseName, courseType}) =&gt; {<br>    ......<br>    ......<br>}</pre><h3>Conclusion</h3><p>In this blog, we learned about props in react, how they are used, their syntax, and different ways of using props. We hope you get a better understanding of how the default value of props are set. To read props, we saw two ways i.e., with and without destructuring. To get more understanding of props, make sure to do practice of them.</p><p><strong>References:</strong></p><p><a href="https://www.knowledgehut.com/blog/web-development/what-is-react-props">https://www.knowledgehut.com/blog/web-development/what-is-react-props</a></p><p><a href="https://www.freecodecamp.org/news/how-to-use-props-in-react/">https://www.freecodecamp.org/news/how-to-use-props-in-react/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5b28a0347cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ternary Operator in JavaScript]]></title>
            <link>https://medium.com/@sudheerbabu.putta/ternary-operator-in-javascript-dc4dd2ccf009?source=rss-f36348fd1148------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc4dd2ccf009</guid>
            <dc:creator><![CDATA[Sudheer Babu]]></dc:creator>
            <pubDate>Tue, 05 Jul 2022 05:49:18 GMT</pubDate>
            <atom:updated>2022-07-05T05:49:18.788Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*Rqns9r6R0I3GEOyHicxcOA.png" /><figcaption>Image from <a href="https://www.tutsmake.com/">https://www.tutsmake.com</a></figcaption></figure><p>The JavaScript <strong>ternary operator</strong> is a single line control flow statement. The <strong>ternary operator</strong> is a short way to declare a conditional statement. and js ternary operator is the only operator that takes three operands.</p><h3>Syntax for Ternary Operator:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*mwKRER3FOHQJ_rdcdLWC6A.png" /><figcaption>Basic Syntax</figcaption></figure><blockquote>The ternary operator evaluates the test condition.</blockquote><blockquote>If the condition is true, <strong>Result1</strong> is executed.</blockquote><blockquote>If the condition is false, <strong>Result2</strong> is executed.</blockquote><h3>Example of Ternary Operator:</h3><p>with the Ternary Operator</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*97zZ8tiGmi0NoM8xL_nq3A.png" /><figcaption>image from <a href="https://www.programiz.com/">programiz.com</a></figcaption></figure><p><strong>Output1 :-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*WNe-2HvhOUXN5WXryhd56Q.png" /><figcaption>Output 1</figcaption></figure><p>Suppose the user enters <strong>78</strong>. Then the condition marks &gt;= 40 is checked which evaluates to true. So the first expression pass is assigned to the result variable.</p><p><strong>Output2 :-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*s4gnIH1ic3w5iW5enfXJJQ.png" /><figcaption>Output 2</figcaption></figure><p>Suppose the use enters <strong>35</strong>. Then the condition marks &gt;= 40 evaluates to false. So the second expression fail is assigned to the result variable.</p><h3>Ternary Operator Used Instead of if…else :</h3><p>without the Ternary Operator</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*noI8FtiniunQydEMzj_vQg.png" /></figure><p>With the Ternary Operator</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*i5AqRZarslcxS17dThZ0RQ.png" /></figure><blockquote>The output of both programs will be the same.</blockquote><p>Output:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*xuOn6iBYtIGdHP7uQzlkZA.png" /><figcaption>Output of both examples</figcaption></figure><h4>conclusion:</h4><ul><li>Ternary operator belongs to both the <strong>operators &amp; conditionals</strong> category.</li><li>It is a replica of the if-else conditional, so its functions are similar to an if-else statement.</li><li>The only difference is the<strong> number of lines of code</strong>.</li><li>The expression that comes first after the condition is always treated as true and the next one is treated as false similar to an <em>if-else</em> statement.</li></ul><p><strong>References:</strong></p><ul><li><a href="https://www.programiz.com/javascript/ternary-operator">https://www.programiz.com/javascript/ternary-operator</a></li><li><a href="https://www.javascripttutorial.net/javascript-ternary-operator/">Make Your Code Cleaner with JavaScript Ternary Operator (javascripttutorial.net)</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc4dd2ccf009" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>