<?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 Divyaraj Baraiya on Medium]]></title>
        <description><![CDATA[Stories by Divyaraj Baraiya on Medium]]></description>
        <link>https://medium.com/@divyarajbaraiya05?source=rss-3abfb63b3e9b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*5YiwCS0A-zTASA9b.jpg</url>
            <title>Stories by Divyaraj Baraiya on Medium</title>
            <link>https://medium.com/@divyarajbaraiya05?source=rss-3abfb63b3e9b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 08:53:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@divyarajbaraiya05/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[“Level Up Your Async Game: Exploring Promise.all, Promise.any, Promise.race & Promise.allSettled”]]></title>
            <link>https://medium.com/@divyarajbaraiya05/level-up-your-async-game-exploring-promise-all-9aa00a14ac21?source=rss-3abfb63b3e9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9aa00a14ac21</guid>
            <category><![CDATA[promises]]></category>
            <category><![CDATA[asynchronous]]></category>
            <category><![CDATA[promises-in-javascript]]></category>
            <category><![CDATA[asynchronous-programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Divyaraj Baraiya]]></dc:creator>
            <pubDate>Fri, 21 Jun 2024 08:40:21 GMT</pubDate>
            <atom:updated>2024-06-21T08:42:57.790Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*WdDPlotMqrwWrRPrtwzrQw.jpeg" /></figure><p>Hey 👋 promise pioneers and async enthusiasts! Today, we’re skipping the snooze-fest of typical promise chain tutorials and finally explanations🥱. Instead, I&#39;ve dug up some seriously cool, practical uses for JavaScript promises that might just blow your mind. Get ready to level up your coding game with promises that actually matter. Grab a 🍸, get comfy, and let&#39;s dive in! 🏊</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*do9rNHzPhrhPOiaxANVvzQ.jpeg" /><figcaption>Promise.{all, any, race, allSettled}</figcaption></figure><h3>Promise.all</h3><p><strong>Description: </strong>Promise.all waits for all promises to be resolved or any to be rejected. If any promise is rejected, the whole Promise.all is rejected with that reason.</p><p><strong>Demonstration: </strong>Imagine you’re throwing a pizza party and need to order pizza, drinks, and desserts. You need all items to arrive before the party starts, but if any order fails, the party is off!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YwQmcUWrO9F1w49qWiy5Sg.png" /><figcaption>Promise.all</figcaption></figure><p>In this example, Promise.all ensures all deliveries arrive before the party starts. If any delivery fails (like the desserts), the entire operation is rejected, and the error is caught in the .catch block. This way, you either have a full party with all items or none at all, making it an all-or-nothing scenario.</p><p><strong>Use Case:</strong> Use when you need all promises to resolve and want to handle the case where any of them fails.</p><p><strong>Error Handling:</strong> Catch the error in the .catch block.</p><h3>Promise.any</h3><p><strong>Description: </strong>Promise.anywaits for the first promise to be resolved successfully. If all promises are rejected, it rejects with an AggregateError containing all rejection reasons.</p><p><strong>Demonstration: </strong>Imagine you’re planning a weekend getaway and need to book a hotel room. You have several preferred hotels in mind, and you’ll consider your reservation successful as soon as any of them confirms your booking. If all your preferred choices are fully booked or unavailable, you’ll need to reconsider your weekend plans.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MZyQFbZFxRoGubxGOvdHmQ.png" /><figcaption>Promise.any</figcaption></figure><p>In this example, Promise.any attempts to book a hotel room among several preferred options (bookHotelA, bookHotelB, bookHotelC). It resolves as soon as the first hotel confirms the booking (bookHotelB in this case). If all preferred hotels reject the booking due to being fully booked or under maintenance, Promise.any catches all rejection reasons (bookHotelA and bookHotelC) in an AggregateError, allowing you to handle the situation accordingly.</p><p><strong>Use Case:</strong> Use when you need the first successful result and don’t mind if some promises fail.</p><p><strong>Error Handling:</strong> Handle AggregateError if all promises reject.</p><h3>Promise.race</h3><p><strong>Description: </strong>Promise.race waits for the first promise to settle (resolve or reject). It resolves with the value of the first promise to resolve or reject with the reason of the first promise to reject.</p><p><strong>Demonstration: </strong>Imagine you’re in a race with your friends, each running at different speeds. The winner is determined by the first runner to cross the finish line. If any runner encounters an obstacle and fails to finish, the race result is determined immediately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pWCTEQvqz16zf9_pJY6RJw.png" /><figcaption>Promise.race</figcaption></figure><p>In this example, Promise.race simulates a marathon race where runnerA, runnerB, and runnerC represent different runners racing towards the finish line. It resolves with the result of the first runner to complete the race (runnerB finishes the race in 1.5 seconds). However, if any runner encounters an obstacle and suffers an injury (runnerC encounters an obstacle and gets injured in 3 seconds), Promise.race catches the rejection reason.</p><p><strong>Use Case:</strong> Use when you only care about the first promise to settle, regardless of whether it resolves or rejects.</p><p><strong>Error Handling:</strong> Catch the first settled promise’s rejection in the .catch block.</p><h3>Promise.allSettled</h3><p><strong>Description: </strong>Promise.allSettled waits for all promises to settle (either resolve or reject). It returns an array of objects representing the outcome of each promise, regardless of whether they were fulfilled or rejected.</p><p>Promise.allSettled does not reject its promise itself, unlike Promise.all, Promise.any or Promise.race.</p><p><strong>Demonstration: </strong>Imagine you’re organizing a treasure hunt for a group of kids, each given a clue to find their share of the treasure. You want to know if each kid successfully finds their clue or encounters difficulties along the way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*USBnXR5J4mEonRjLh25yUg.png" /><figcaption>Promise.allSettled</figcaption></figure><p>In this example, Promise.allSettled represents a treasure hunt organized for kids (findClue1, findClue2, findClue3). Each promise simulates a child&#39;s experience with their clue, whether they successfully find it (fulfilled) or encounter obstacles (rejected).</p><p>The .then block processes the settled promises and prints messages based on each child&#39;s treasure hunt experience. If a child successfully finds their clue, an exciting message is logged. If they face challenges or get lost, a humorous error message is logged, adding an amusing element to the treasure hunt narrative.</p><p><strong>Use Case: </strong>Use when you need to know the outcome of all promises, regardless of whether they resolved or rejected.</p><p><strong>Error Handling:</strong> Check each result’s status to handle fulfillment or rejection.</p><p>Each method has its own use case based on how you want to handle asynchronous operations: waiting for all to complete (Promise.all), getting the first successful result (Promise.any), getting the fastest result (Promise.race), or collecting all results regardless of success or failure (Promise.allSettled).</p><p>By understanding and utilizing these different promise methods, you can handle various asynchronous scenarios in JavaScript effectively.</p><h4>Until next time, happy coding!</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9aa00a14ac21" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Reusable Drag-and-Drop Lists in React (Typescript) with React Beautiful DND…]]></title>
            <link>https://medium.com/@divyarajbaraiya05/creating-reusable-drag-and-drop-lists-in-react-typescript-with-react-beautiful-dnd-ec5bdf88a9d3?source=rss-3abfb63b3e9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec5bdf88a9d3</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[drag-and-drop]]></category>
            <category><![CDATA[typescript-with-react]]></category>
            <category><![CDATA[react-beautiful-dnd]]></category>
            <dc:creator><![CDATA[Divyaraj Baraiya]]></dc:creator>
            <pubDate>Tue, 15 Aug 2023 10:58:16 GMT</pubDate>
            <atom:updated>2023-08-15T10:58:16.775Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating Reusable Drag-and-Drop Lists in React (Typescript) with React Beautiful DND <a href="https://www.npmjs.com/package/react-beautiful-dnd">react-beautiful-dnd</a></h3><p>Introduction:</p><ul><li>Briefly introduce the concept of drag-and-drop interactions and their importance in modern web applications.</li><li>Mention that React Beautiful DND is a popular library for implementing drag-and-drop functionality in React applications.</li><li>Introduce the main objective of the blog post: creating a reusable component for drag-and-drop lists.</li></ul><p>React Beautiful DND is a popular and powerful library that provides a seamless way to implement drag-and-drop interactions in React applications. It is specifically designed to make complex drag-and-drop functionalities feel effortless to build and maintain. With its intuitive API and thoughtful design, React Beautiful DND simplifies the process of creating interactive and visually appealing user interfaces that respond to user actions.</p><p>In this blog post, we’ll harness the capabilities of React Beautiful DND to create a reusable component for drag-and-drop lists. This component will allow us to easily incorporate drag-and-drop functionality into various parts of our React application, making it a powerful tool for enhancing user interactions and improving the overall user experience. Let’s dive in and explore how we can leverage this library to build an efficient and customizable drag-and-drop component.</p><h3>Defining the Component For Drag &amp; Drop with list items</h3><pre><br><br>import React from &quot;react&quot;;<br>import { DragDropContext, Draggable, Droppable, OnDragEndResponder, DraggableProvided, DroppableProvided } from &quot;react-beautiful-dnd&quot;;<br><br>interface AppDraggableListProps&lt;T&gt; {<br>    droppableId: string;<br>    data: T[];<br>    onDragEnd: OnDragEndResponder;<br>    renderItem: (item: T, provided: DraggableProvided) =&gt; JSX.Element;<br>    renderWrapper: (<br>        children: JSX.Element,<br>        providedMain: DroppableProvided,<br>    ) =&gt; JSX.Element;<br>    direction?: Direction;<br>}<br><br>export const AppDraggableList = &lt;T extends { id: number }&gt;({<br>    droppableId,<br>    data,<br>    onDragEnd,<br>    renderItem,<br>    renderWrapper,<br>    direction,<br>}: AppDraggableListProps&lt;T&gt;) =&gt; (<br>    &lt;DragDropContext onDragEnd={onDragEnd}&gt;<br>        &lt;Droppable droppableId={droppableId} direction={direction}&gt;<br>            {(providedMain) =&gt;<br>                renderWrapper(<br>                    &lt;&gt;<br>                        {data.map((item, index) =&gt; (<br>                            &lt;Draggable<br>                                key={item.id}<br>                                index={index}<br>                                draggableId={String(item.id)}<br>                            &gt;<br>                                {(provided) =&gt; renderItem(item, provided)}<br>                            &lt;/Draggable&gt;<br>                        ))}<br><br>                        {providedMain.placeholder}<br>                    &lt;/&gt;,<br>                    providedMain<br>                )<br>            }<br>        &lt;/Droppable&gt;<br>    &lt;/DragDropContext&gt;<br>);</pre><h3>Real-World Example: Drag-and-Drop Animal List</h3><pre>// Usage of common component<br><br>import { DropResult, DraggableProvided } from &quot;react-beautiful-dnd&quot;;<br><br>const MyComponent: React.FC = () =&gt; {<br><br>    interface Animal {<br>        id: number;<br>        name: string;<br>        breed: string;<br>    }<br><br>    const data: Animal[] = [<br>        { id: 1, name: &quot;Dog&quot;, breed: &quot;Labrador&quot; },<br>        { id: 2, name: &quot;Cat&quot;, breed: &quot;Siamese&quot; },<br>        { id: 3, name: &quot;Rabbit&quot;, breed: &quot;Holland Lop&quot; },<br>    ];<br><br>    const handleDragEnd = (result: DropResult) =&gt; {<br>        // Handle drag end logic<br>    };<br><br>    const renderAnimalItem = (<br>        animal: Animal,<br>        provided: DraggableProvided<br>    ) =&gt; {<br>        // Your animal item rendering logic<br>        return (<br>            &lt;div<br>                className=&quot;item&quot;<br>                ref={provided.innerRef}<br>                {...provided.draggableProps}<br>            &gt;<br>                &lt;div&gt;Name: {animal.name}&lt;/div&gt;<br>                &lt;div&gt;Breed: {animal.breed}&lt;/div&gt;<br>            &lt;/div&gt;<br>        );<br>    };<br><br>    const renderWrapper = (<br>        children: JSX.Element,<br>        providedMain: DroppableProvided<br>    ) =&gt; (<br>        &lt;div<br>            className=&quot;animal-list-container&quot;<br>            ref={providedMain.innerRef}<br>            {...providedMain.droppableProps}<br>        &gt;<br>            {children}<br>        &lt;/div&gt;<br>    );<br><br>    return (<br>        &lt;AppDraggableList<br>            droppableId=&quot;unique-id&quot; // specific for this drag n drop continaer<br>            data={data}<br>            onDragEnd={handleDragEnd}<br>            renderItem={renderAnimalItem}<br>            renderWrapper={renderWrapper}<br>            direction=&quot;vertical&quot;<br>        /&gt;<br>    );<br>};<br><br>export default MyComponent;</pre><p>Before we wrap up, we want to extend our heartfelt gratitude to you for joining us on this journey through the realm of creating reusable drag-and-drop lists in React. We hope that this tutorial has equipped you with the tools and knowledge to enhance your front-end development skills and create remarkable user experiences.</p><p>Until next time, happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec5bdf88a9d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>