<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Aman Kalra - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Aman Kalra - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Thu, 14 May 2026 17:33:16 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/amankalra/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Use React Dev Tools – With Example Code and Videos ]]>
                </title>
                <description>
                    <![CDATA[ When you're working on a React project, one of the easiest ways to debug your code is using the React Dev Tools. React Dev Tools is an extension created by the React team. It enables developers to deb ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-react-dev-tools/</link>
                <guid isPermaLink="false">66d45d9937bd2215d1e2457a</guid>
                
                    <category>
                        <![CDATA[ Developer Tools ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Aman Kalra ]]>
                </dc:creator>
                <pubDate>Wed, 11 Jan 2023 18:18:53 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/01/thumbnail.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>When you're working on a React project, one of the easiest ways to debug your code is using the React Dev Tools.</p>
<p>React Dev Tools is an extension created by the React team. It enables developers to debug their code inside their Developer Tools.</p>
<p>Once you add the extension, you will get 2 new tabs in DevTools called Components and Profiler, respectively.</p>
<img src="https://www.freecodecamp.org/news/content/images/2023/01/Components-and-Profiler-Tabs-1.png" alt="Image" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><em>Components and Profiler tabs in Chrome Dev Tools</em></p>
<p>To use the full functionality of the extension, you need to be in development mode. This is because in production mode, the component names get changed to letters (as you can see in above screenshot) and you will not be able to profile your components.</p>
<h2 id="heading-how-to-use-the-components-tab">How to Use the Components Tab</h2>
<p>The Components tab allows you to debug your code in dev tools with various functionalities. Let's cover them one by one:</p>
<h3 id="heading-you-can-check-the-props-state-hooks-of-the-component">You can check the props/ state/ hooks of the component</h3>
<img src="https://www.freecodecamp.org/news/content/images/2023/01/Props-and-State-in-Component-s-Tab-1.png" alt="Props and State in Component's Tab" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><em>Viewing Props and State</em></p>
<p>This tab will help you to look for a component and check its respective props/ state in your dev tools, without having to log them in the console separately.</p>
<h3 id="heading-you-can-edit-the-props-state-from-dev-tools">You can edit the props/ state from dev tools</h3>
<div class="embed-wrapper"><iframe width="640" height="360" src="https://player.vimeo.com/video/787154069" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="Vimeo embed" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen="" loading="lazy"></iframe></div>

<p>One of the amazing features is that you can edit the props/ state of your component in the browser itself. This helps you to reflect changes in real time without having to reload or refresh your webpage. Above is a sample video so you can see how it works.</p>
<h3 id="heading-you-can-search-for-a-component">You can search for a component</h3>
<div class="embed-wrapper"><iframe width="640" height="360" src="https://player.vimeo.com/video/787155384" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="Vimeo embed" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen="" loading="lazy"></iframe></div>

<p>You can easily search for a component within your whole application by just typing out the name in the search bar provided. It will show you all related components with the keywords typed in. Then you can navigate between the matching results.</p>
<h3 id="heading-you-can-check-the-components-tree">You can check the component's tree</h3>
<img src="https://www.freecodecamp.org/news/content/images/2023/01/Component-s-Hierrarchy.png" alt="Component's Hierarchy" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><em>Component's Hierarchy</em></p>
<p>While debugging, its important to note which parent components caused the child component to re-render. Checking this in your code is sometimes tedious. But the "<strong>rendered by</strong>" section makes it easier for you by showing all the parent components in a single place.</p>
<h3 id="heading-you-can-log-a-components-data-in-the-console">You can log a component's data in the console</h3>
<img src="https://www.freecodecamp.org/news/content/images/2024/08/logging-components.jpg" alt="Image" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><em>Logging a component's data in the console</em></p>
<p>There are developers who like to work in console, and this feature allows you to log all of your component's data to console with just one click. It shows all relevant information regarding the component like props received, hooks present, which node is it in the DOM, and the file's location in your system.</p>
<h3 id="heading-you-can-check-subcomponents">You can check subcomponents</h3>
<div class="embed-wrapper"><iframe width="640" height="360" src="https://player.vimeo.com/video/787165596" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="Vimeo embed" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen="" loading="lazy"></iframe></div>

<p>Just like checking parent components isn't always easy in your code, the same applies with checking child components.</p>
<p>To overcome this issue, you can double click on a component name, which will show you all the subcomponents present inside the target component in one go.</p>
<h2 id="heading-how-to-use-the-profiler-tab">How to Use the Profiler Tab</h2>
<p>This tab allows you to test the performance of your components and shows which components to focus on for improvements.</p>
<img src="https://www.freecodecamp.org/news/content/images/2023/01/Profiler-tab-1.png" alt="Image" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><em>Profiler tab</em></p>
<p>As you can see above, I've marked a few things on the screenshot. Let's cover them one by one:</p>
<ul>
<li><p><strong>A</strong> is the record button, which will help you record a profiling session.</p>
</li>
<li><p><strong>B</strong> is the refresh button, which will help you refresh the page for a session.</p>
</li>
<li><p><strong>C</strong> is the clear button, which will help you clear the profiling session's result.</p>
</li>
<li><p><strong>D</strong> is the commit chart, which will show you the list of commits during a session.</p>
</li>
<li><p><strong>E</strong> is the component list, which will show you the components rendered during a session.</p>
</li>
<li><p><strong>F</strong> is the flame chart button, which will show you the component list like <strong>E.</strong></p>
</li>
<li><p><strong>G</strong> is the ranked chart button, which will show you the component list in a ranked manner.</p>
</li>
</ul>
<p>Now let's dive into different functionalities present in this tab and how to check the performance of your web page:</p>
<h3 id="heading-how-to-read-the-commit-chart">How to Read the Commit Chart</h3>
<p>The commit chart shows the list of commits during a session. If you can see in the above image, in section <strong>D</strong>, there are 3 bars. These denote 3 commits in a session. And each commit shows a side effect that caused the DOM to update.</p>
<blockquote>
<p><a href="https://reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html#browsing-commits">As per the docs</a>, "The colour and height of each bar corresponds to how long that commit took to render. (Taller, yellow bars took longer than shorter, blue bars.)"</p>
</blockquote>
<p>You can even navigate between the bars and check each commit separately.</p>
<h3 id="heading-how-to-read-the-flame-chart">How to Read the Flame Chart</h3>
<p>Flame chart shows the list of components rendered in a commit. If you can see in the above image, when you click on the section labeled <strong>F</strong>, all horizontal bars in the section <strong>E</strong> represent different components of the 1st commit.</p>
<blockquote>
<p><a href="https://reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html#flame-chart">As per the docs</a>, "The colour of a bar indicates how long the component (and its children) took to render in the selected commit. Yellow components took more time, blue components took less time, and gray components did not render at all during a commit."</p>
</blockquote>
<h3 id="heading-how-to-check-the-performance-of-your-web-page">How to Check the Performance of Your Web Page</h3>
<p>To check the performance of your web page, all you need to do is:</p>
<ul>
<li><p>Click on the record button.</p>
</li>
<li><p>Use your web page so that the Profiler will be able to analyse the rendering of components.</p>
</li>
<li><p>Click the record button again to finish recording.</p>
</li>
</ul>
<p>Then you will see the flame chart, and you can analyse which components are taking more time to render.</p>
<p>Note that the flame chart also shows:</p>
<ol>
<li><p>When exactly the component rendered.</p>
</li>
<li><p>And how long it took to render in a profiling session.</p>
</li>
</ol>
<p><strong>For example</strong>: In below image, the <strong>Home component</strong> was rendered at <strong>1.5s</strong> of the profiling session and it took <strong>27.7 ms</strong> to render.</p>
<img src="https://www.freecodecamp.org/news/content/images/2023/01/Flame-Chart.png" alt="Image" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><em>Flame Chart</em></p>
<h3 id="heading-how-to-read-a-ranked-chart">How to Read a Ranked Chart</h3>
<p>When you click the <strong>Ranked chart</strong> icon as shown in section <strong>G</strong> of the image, you will get a chart view of the components. This view is in descending order, that is the component that took the most time to render will be at the top and the component which took the least time will be at the bottom.</p>
<p>You can see this in the below image:</p>
<img src="https://www.freecodecamp.org/news/content/images/2023/01/Ranked-Chart.png" alt="Image" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><em>Ranked Chart</em></p>
<p><strong>Note</strong>: You can get more information about why your component rendered by just enabling the "Record why each component rendered while profiling." checkbox in settings of the "Profiler" tab. I've attached an image for reference below:</p>
<img src="https://www.freecodecamp.org/news/content/images/2023/01/Render-description.png" alt="Image" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><em>Render description</em></p>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>React Dev Tools is a great extension to have when you're working on your React applications. They can help you easily debug your code and find performance bottlenecks in your application.</p>
<p>Do try out these features next time in your React project.</p>
<h2 id="heading-thanks-for-reading">Thanks for reading!</h2>
<p>If you found this article useful, do share it with your friends and colleagues.</p>
<p>If you like to see similar tips and tricks in HTML, CSS, JavaScript and React, do <a href="https://www.linkedin.com/in/amankalra1">Follow me on LinkedIn</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ find() vs filter() in JavaScript – Differences Explained with Examples ]]>
                </title>
                <description>
                    <![CDATA[ A common interview question that JavaScript developers often get asked is to explain the difference between the find() and filter() methods. In this tutorial today, I'll walk you through what these me ]]>
                </description>
                <link>https://www.freecodecamp.org/news/find-vs-filter-javascript/</link>
                <guid isPermaLink="false">66d45d97052ad259f07e4a53</guid>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Aman Kalra ]]>
                </dc:creator>
                <pubDate>Fri, 14 Oct 2022 22:22:22 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/10/Logo.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>A common interview question that JavaScript developers often get asked is to explain the difference between the find() and filter() methods.</p>
<p>In this tutorial today, I'll walk you through what these methods are and when you should use them.</p>
<h2 id="heading-what-is-the-filter-method">What is the <code>filter()</code> method?</h2>
<p>This method returns all the elements of the array that satisfy the condition specified in the callback function.</p>
<p>Let's see with an example how it actually works:</p>
<pre><code class="language-typescript">const x = [1, 2, 3, 4, 5];

const y = x.filter(el =&gt; el*2 === 2);

console.log("y is: ", y); // y is: [1]
</code></pre>
<p>If you check out the output of the above example, the <strong>value of y is</strong> <strong>an array of 1 element</strong> that satisfies the condition. This is because the filter() method iterates over all elements of the array and then returns a filtered array which satisfy the condition specified.</p>
<h2 id="heading-what-is-the-find-method">What is the <code>find()</code> method?</h2>
<p>This method returns first element of the array that satisfies the condition specified in the callback function.</p>
<p>Let's see with an example how it actually works:</p>
<pre><code class="language-typescript">const x = [1, 2, 3, 4, 5];

const y = x.find(el =&gt; el*2 === 2);

console.log("y is: ", y); // y is: 1
</code></pre>
<p>Now, if you see the output of the above example, the <strong>value of y is 1</strong>. This is because the find() method searches for first element in the array that satisfies the condition specified.</p>
<p>The main differences between above examples is:</p>
<ol>
<li><p><code>filter()</code> returns an array containing the element that satisfies the condition, but <code>find()</code> returns the element itself that satisfies the condition.</p>
</li>
<li><p>In <code>filter()</code>, whole array is iterated despite the fact that the element being searched for is present at the beginning. But in <code>find()</code>, as soon as the element that satisfies the condition is found, it gets returned.</p>
</li>
</ol>
<h2 id="heading-use-cases-for-find-and-filter">Use Cases for <code>find()</code> and <code>filter()</code></h2>
<p>When you have a use case where more than 1 element is expected to be returned and you want to perform operation on all elements, then you can use the <strong>filter()</strong> method. But if you expect only a single element to be returned from the array, then you can use <strong>find()</strong> and avoid extra iterations.</p>
<p>Let's look at examples of both use cases:</p>
<h3 id="heading-1-filter-use-case-example">1. filter() use case example</h3>
<pre><code class="language-typescript">const x = [1, 2, 3, 4, 5];

const y = x.filter(el =&gt; el%2 === 0);

console.log("y is: ", y); // y is: [2, 4]
</code></pre>
<p>In above example, <code>**filter()**</code> makes more sense as you would want to iterate over all elements of the array to find the elements that are divisible by 2.</p>
<h3 id="heading-2-find-use-case-example">2. find() use case example</h3>
<pre><code class="language-typescript">const emp = [
    {
        name: "Ram",
        empID: 101
    },
    {
        name: "Sham",
        empID: 102
    },
    {
        name: "Mohan",
        empID: 103
    }
];

const res = emp.find(el =&gt; el.empID === 102);

console.log("res is: ", res); // res is: {name: 'Sham', empID: 102}
</code></pre>
<p>In above example, <code>**find()**</code> makes more sense as there is just 1 employee who has <code>102</code> as the <code>empID</code> so, <code>find()</code> helps to avoid iterating over the 3rd object in the array.</p>
<h3 id="heading-thanks-for-reading"><strong>Thanks for reading!</strong></h3>
<p>If you found this article useful, do share it with your friends and colleagues.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ TypeScript Generics – Use Case and Examples ]]>
                </title>
                <description>
                    <![CDATA[ In this tutorial, you'll learn the basics of generics in TypeScript. We'll discuss how to use them and when they're useful in your code. Use Case for Generics Let's start with a simple example, where  ]]>
                </description>
                <link>https://www.freecodecamp.org/news/typescript-generics-use-case-and-examples/</link>
                <guid isPermaLink="false">66d45d9b052ad259f07e4a5d</guid>
                
                    <category>
                        <![CDATA[ generics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ TypeScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Aman Kalra ]]>
                </dc:creator>
                <pubDate>Fri, 07 Oct 2022 20:49:10 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/10/pexels-hitarth-jadhav-220357.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this tutorial, you'll learn the basics of generics in TypeScript. We'll discuss how to use them and when they're useful in your code.</p>
<h2 id="heading-use-case-for-generics">Use Case for Generics</h2>
<p>Let's start with a simple example, where you want to print the value of an argument passed:</p>
<pre><code class="language-typescript">function printData(data: number) {
    console.log("data: ", data);
}

printData(2);
</code></pre>
<p>Now, let's suppose you want to make <code>printData</code> a more generic function, where you can pass any type of argument to it like: <strong>number</strong>/ <strong>string</strong>/ <strong>boolean</strong>. So, you might think to follow an approach like below:</p>
<pre><code class="language-typescript">function printData(data: number | string | boolean) {
    console.log("data: ", data);
}

printData(2);
printData("hello");
printData(true);
</code></pre>
<p>But in the future, you might want to print an array of numbers using the same function. In that case the types will increase and it will become cumbersome to maintain all those different types.</p>
<p>This is when <strong>Generics</strong> come into the picture.</p>
<h2 id="heading-how-generics-work-in-ts">How Generics Work in TS</h2>
<p>Generics are like variables – to be precise, type variables – that store the type (for example number, string, boolean) as a value.</p>
<p>So, you can solve the problem we discussed above with generics as shown below:</p>
<pre><code class="language-typescript">function printData&lt;T&gt;(data: T) {
    console.log("data: ", data);
}

printData(2);
printData("hello");
printData(true);
</code></pre>
<p>In the above example <code>printData-generics.ts</code>, there is a slight difference in syntax:</p>
<ol>
<li><p>You use a type variable inside angular brackets after the function name <code>&lt;T&gt;</code></p>
</li>
<li><p>You then assign the type variable to the parameter <code>data: T</code></p>
</li>
</ol>
<p>Let's explore these differences a bit more.</p>
<p>To use generics, you need to use angular brackets and then specify a type variable inside them. Developers generally use <code>T</code>, <code>X</code> and <code>Y</code>. But it can be anything depending upon your preference.</p>
<p>You can then assign the same variable name as the type to the parameter of the function.</p>
<p>Now, whatever argument you pass to the function, it gets inferred and there's no need to hardcode the type anywhere.</p>
<p>Even if you pass an array of numbers or an object to the <code>printData</code> function, everything will be displayed properly without TS complaining:</p>
<pre><code class="language-typescript">function printData&lt;T&gt;(data: T) {
    console.log("data: ", data);
}

printData(2);
printData("hello");
printData(true);
printData([1, 2, 3, 4, 5, 6]);
printData([1, 2, 3, "hi"]);
printData({ name: "Ram", rollNo: 1 });
</code></pre>
<p>Let's see another example:</p>
<pre><code class="language-typescript">function printData&lt;X,Y&gt;(data1: X, data2: Y) {
    console.log("Output is: ", data1, data2);
}

printData("Hello", "World");
printData(123, ["Hi", 123]);
</code></pre>
<p>In above example, we passed 2 arguments to <code>printData</code> and used <code>X</code> and <code>Y</code> to denote the types for both the parameters. <code>X</code> refers to 1st value of the argument and <code>Y</code> refers to 2nd value of the argument.</p>
<p>Here as well, the types of <code>data1</code> and <code>data2</code> are not specified explicitly because TypeScript handles the type inference with the help of generics.</p>
<h3 id="heading-how-to-use-generics-with-interfaces">How to Use Generics with Interfaces</h3>
<p>You can even use generics with interfaces. Let's see how that works with the help of a code snippet:</p>
<pre><code class="language-typescript">interface UserData&lt;X,Y&gt; {
    name: X;
    rollNo: Y;
}

const user: UserData&lt;string, number&gt; = {
    name: "Ram",
    rollNo: 1
}
</code></pre>
<p>In above snippet, <code>&lt;string, number&gt;</code> are passed to the interface <code>UserData</code>. In this way, <code>UserData</code> becomes a reusable interface in which any data type can be assigned depending upon the use case.</p>
<p>Here in this example, <code>name</code> and <code>rollNo</code> will always be <code>string</code> and <code>number</code>, respectively. But this example was to showcase how you can use generics with interfaces in TS.</p>
<h3 id="heading-thanks-for-reading">Thanks for reading!</h3>
<p>If you found this article useful, do share it with your friends and colleagues.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
