<?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 Jatin on Medium]]></title>
        <description><![CDATA[Stories by Jatin on Medium]]></description>
        <link>https://medium.com/@wjatin150?source=rss-93444b627a81------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*SiFZACiEOifAGmtp</url>
            <title>Stories by Jatin on Medium</title>
            <link>https://medium.com/@wjatin150?source=rss-93444b627a81------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 02:16:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wjatin150/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[Understanding Callbacks vs. Promises vs. Async/Await in JavaScript]]></title>
            <link>https://medium.com/@wjatin150/understanding-callbacks-vs-promises-vs-async-await-in-javascript-5871c1685060?source=rss-93444b627a81------2</link>
            <guid isPermaLink="false">https://medium.com/p/5871c1685060</guid>
            <dc:creator><![CDATA[Jatin]]></dc:creator>
            <pubDate>Thu, 20 Jun 2024 04:38:43 GMT</pubDate>
            <atom:updated>2024-06-20T04:38:43.387Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introduction</h4><p>JavaScript offers three main ways to handle asynchronous operations: callbacks, promises, and async/await. Understanding the differences, benefits, and use cases of each can help you write cleaner, more efficient code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KDQIk8LXP5JziQJyHK4_CA.jpeg" /></figure><h4>Callbacks</h4><p><strong>What are Callbacks?</strong></p><ul><li>Functions passed as arguments to other functions, to be executed once an operation is complete.</li><li>The traditional way to handle asynchronous operations.</li></ul><p><strong>Example:</strong></p><pre>function fetchData(callback) {<br>  setTimeout(() =&gt; {<br>    callback(&#39;Data received&#39;);<br>  }, 1000);<br>}<br>fetchData(data =&gt; {<br>  console.log(data);<br>});</pre><p><strong>Pros:</strong></p><ul><li>Simple and straightforward for basic asynchronous tasks.</li></ul><p><strong>Cons:</strong></p><ul><li>Can lead to “callback hell” with nested callbacks, making code hard to read and maintain.</li><li>Error handling is cumbersome and scattered.</li></ul><h4>Promises</h4><p><strong>What are Promises?</strong></p><ul><li>Objects representing the eventual completion (or failure) of an asynchronous operation.</li><li>Allows chaining with .then(), .catch(), and .finally().</li></ul><p><strong>Example:</strong></p><pre>fetch(&#39;https://api.example.com/data&#39;)<br>  .then(response =&gt; response.json())<br>  .then(data =&gt; console.log(data))<br>  .catch(error =&gt; console.error(&#39;Error:&#39;, error));</pre><p><strong>Pros:</strong></p><ul><li>Better readability and structure compared to callbacks.</li><li>Chainable, making it easier to handle sequences of asynchronous operations.</li></ul><p><strong>Cons:</strong></p><ul><li>Can become verbose with multiple .then() calls.</li></ul><h4>Async/Await</h4><p><strong>What is Async/Await?</strong></p><ul><li>Syntactic sugar built on top of promises.</li><li>Makes asynchronous code look and behave like synchronous code, improving readability.</li></ul><p><strong>Example:</strong></p><pre>async function fetchData() {<br>  try {<br>    const response = await fetch(&#39;https://api.example.com/data&#39;);<br>    const data = await response.json();<br>    console.log(data);<br>  } catch (error) {<br>    console.error(&#39;Error:&#39;, error);<br>  }<br>}<br>fetchData();</pre><p><strong>Pros:</strong></p><ul><li>More readable and concise for complex asynchronous code.</li><li>Easier error handling with try and catch.</li></ul><p><strong>Cons:</strong></p><ul><li>Requires understanding of promises, as it is built on top of them.</li></ul><h4>Key Differences</h4><ol><li><strong>Syntax and Readability:</strong></li></ol><ul><li>Callbacks: Can quickly become complex and hard to follow with nested functions.</li><li>Promises: More readable and manageable, but can still become verbose.</li><li>Async/Await: Most readable and concise, especially for sequential asynchronous operations.</li></ul><p><strong>2. Error Handling:</strong></p><ul><li>Callbacks: Requires explicit error handling, often leading to scattered code.</li><li>Promises: Centralized error handling with .catch().</li><li>Async/Await: Simplified error handling with try and catch.</li></ul><p><strong>3. Usage:</strong></p><ul><li>Callbacks: Suitable for simple asynchronous tasks or legacy code.</li><li>Promises: Ideal for chaining multiple asynchronous operations.</li><li>Async/Await: Best for sequential asynchronous operations and cleaner code.</li></ul><h4>Which is Better and Why?</h4><p><strong>Async/Await is Preferred:</strong></p><ul><li><strong>Readability</strong>: Easiest to read and maintain, especially for complex sequences of asynchronous operations.</li><li><strong>Error Handling</strong>: Simplifies error management with try and catch.</li></ul><p><strong>When to Use Each:</strong></p><ul><li><strong>Callbacks</strong>: Use for simple tasks or when working with legacy code that relies on them.</li><li><strong>Promises</strong>: Use when you need to perform multiple asynchronous operations in parallel and handle results with .then().</li><li><strong>Async/Await</strong>: Use for most other cases, particularly for sequential asynchronous operations or when you want cleaner, more readable code.</li></ul><h4>Conclusion</h4><p>Each method of handling asynchronous operations in JavaScript has its own use cases and benefits. Callbacks are simple but can become unwieldy, promises provide better structure and readability, and async/await offers the most modern, readable, and efficient approach. Understanding when and how to use each method will help you write better asynchronous code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5871c1685060" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Comparing Routing in React.js and Next.js]]></title>
            <link>https://medium.com/@wjatin150/comparing-routing-in-react-js-and-next-js-a76a1c1db5ab?source=rss-93444b627a81------2</link>
            <guid isPermaLink="false">https://medium.com/p/a76a1c1db5ab</guid>
            <dc:creator><![CDATA[Jatin]]></dc:creator>
            <pubDate>Mon, 17 Jun 2024 13:25:00 GMT</pubDate>
            <atom:updated>2024-06-17T13:25:00.945Z</atom:updated>
            <content:encoded><![CDATA[<p>Routing is a crucial aspect of building web applications, determining how users navigate through different pages or views. React.js and Next.js offer distinct approaches to routing, each with its own set of features and use cases. Let’s explore the key differences between routing in React.js and Next.js.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*_kxHfd0wiT3zaf66Duxh0w.jpeg" /></figure><h4>1. Routing in React.js</h4><p>In React.js, routing is typically handled using an external library like React Router. React Router is a powerful and flexible routing library that allows developers to define routes, nested routes, and dynamic routes within a React application.</p><p><strong>Key Features of React Router:</strong></p><ul><li><strong>Declarative Routing:</strong> Routes are defined declaratively using JSX syntax.</li><li><strong>Dynamic Routing:</strong> Supports dynamic route parameters and nested routes.</li><li><strong>Client-Side Routing:</strong> Handles routing on the client side, updating the URL without refreshing the page.</li><li><strong>Customizable Navigation:</strong> Provides components like BrowserRouter, Route, Link, Switch, and NavLink for creating navigation structures.</li></ul><p><strong>Example of React Router Setup:</strong></p><pre>import React from &#39;react&#39;;<br>import { BrowserRouter as Router, Route, Switch } from &#39;react-router-dom&#39;;<br>import Home from &#39;./Home&#39;;<br>import About from &#39;./About&#39;;<br>import BlogPost from &#39;./BlogPost&#39;;</pre><pre>const App = () =&gt; (<br>  &lt;Router&gt;<br>    &lt;Switch&gt;<br>      &lt;Route exact path=&quot;/&quot; component={Home} /&gt;<br>      &lt;Route path=&quot;/about&quot; component={About} /&gt;<br>      &lt;Route path=&quot;/blog/:slug&quot; component={BlogPost} /&gt;<br>    &lt;/Switch&gt;<br>  &lt;/Router&gt;<br>);</pre><pre>export default App;</pre><p><strong>Key Points:</strong></p><ul><li><strong>Manual Setup:</strong> Requires explicit setup of routes and components.</li><li><strong>Flexibility:</strong> Highly customizable and can be integrated into any React project.</li></ul><h4>2. Routing in Next.js</h4><p>Next.js offers a built-in routing mechanism that is based on the file system, making it more straightforward and convention-based. The pages directory in a Next.js project automatically maps files to routes.</p><p><strong>Key Features of Next.js Routing:</strong></p><ul><li><strong>File-Based Routing:</strong> Routes are automatically created based on the file structure in the pages directory.</li><li><strong>Dynamic Routing:</strong> Supports dynamic routes using file naming conventions with square brackets (e.g., [id].js).</li><li><strong>Static and Server-Side Rendering:</strong> Integrated support for static site generation (SSG) and server-side rendering (SSR).</li><li><strong>API Routes:</strong> Provides built-in support for creating API endpoints within the pages/api directory.</li></ul><p><strong>Example of Next.js File-Based Routing:</strong></p><ul><li>pages/index.js maps to /</li><li>pages/about.js maps to /about</li><li>pages/blog/[slug].js maps to dynamic routes like /blog/hello-world</li></ul><p><strong>Example of Dynamic Route in Next.js:</strong></p><pre>// pages/blog/[slug].js<br>import { useRouter } from &#39;next/router&#39;;</pre><pre>const BlogPost = () =&gt; {<br>  const router = useRouter();<br>  const { slug } = router.query;</pre><pre>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Blog Post: {slug}&lt;/h1&gt;<br>      &lt;p&gt;This is the content for blog post: {slug}.&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>};</pre><pre>export default BlogPost;</pre><p><strong>Key Points:</strong></p><ul><li><strong>Automatic Routing:</strong> No need for manual route definitions; relies on file structure.</li><li><strong>Simplified Navigation:</strong> Easier to understand and manage, especially for larger projects.</li><li><strong>Built-In Features:</strong> Includes features like SSR, SSG, and API routes without additional configuration.</li></ul><h4>Conclusion</h4><p>Both React.js and Next.js offer robust routing solutions, but they cater to different needs and project structures. React.js, with React Router, provides flexibility and customization, making it suitable for projects where complex routing logic is required. Next.js, with its file-based routing, simplifies routing setup and integrates advanced features like SSR and SSG, making it ideal for modern web applications.</p><p>Understanding these differences helps you choose the right tool for your project, ensuring efficient and maintainable routing structures.</p><p>Which routing approach do you prefer for your projects? Share your thoughts in the comments below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a76a1c1db5ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Class Components vs. Functional Components in React]]></title>
            <link>https://medium.com/@wjatin150/understanding-class-components-vs-functional-components-in-react-5f8c0c94f02b?source=rss-93444b627a81------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f8c0c94f02b</guid>
            <dc:creator><![CDATA[Jatin]]></dc:creator>
            <pubDate>Fri, 14 Jun 2024 04:25:44 GMT</pubDate>
            <atom:updated>2024-06-14T04:25:44.464Z</atom:updated>
            <content:encoded><![CDATA[<p>React offers two primary ways to define components: class components and functional components. Each has its unique features and use cases. Let’s explore the differences and benefits of both to help you make informed decisions in your React projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KxRVoCyRd2YAdv9tXVDIzg.jpeg" /></figure><h4>Class Components</h4><p>Class components have been a staple in React since its early days. They are ES6 classes that extend from React.Component and include lifecycle methods and state management. Key features include:</p><ul><li><strong>State Management:</strong> Managed using this.state and this.setState.</li><li><strong>Lifecycle Methods:</strong> Methods like componentDidMount and componentDidUpdate for handling side effects.</li><li><strong>this Context:</strong> Requires proper binding of this when using methods as callbacks.</li></ul><h4>Functional Components</h4><p>Functional components are simpler and, with the introduction of Hooks, can now manage state and side effects. Key features include:</p><ul><li><strong>Simplicity:</strong> Easier to read and write as they are plain JavaScript functions.</li><li><strong>Hooks:</strong> useState, useEffect, and other hooks for state management and side effects.</li><li><strong>No </strong><strong>this Binding:</strong> Avoids the complexities of this context.</li></ul><h4>Comparison</h4><ul><li><strong>Readability:</strong> Functional components are generally more concise and easier to understand.</li><li><strong>State &amp; Side Effects:</strong> Both can handle these, but hooks make functional components more powerful and flexible.</li><li><strong>Lifecycle Management:</strong> Class components use lifecycle methods, while functional components use hooks like useEffect.</li></ul><h4>When to Use Which?</h4><ul><li><strong>Functional Components:</strong> Ideal for most cases due to simplicity and the power of hooks. Great for modern React development.</li><li><strong>Class Components:</strong> Useful for legacy codebases or specific scenarios like error boundaries.</li></ul><h4>Conclusion</h4><p>Functional components with hooks are becoming the preferred choice in React development due to their simplicity and flexibility. However, understanding both class and functional components ensures you can handle any React project effectively.</p><p>Which do you prefer in your React projects? Share your thoughts in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f8c0c94f02b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>