<?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 Asif Ali on Medium]]></title>
        <description><![CDATA[Stories by Asif Ali on Medium]]></description>
        <link>https://medium.com/@asif-ali?source=rss-6b65384fb5a4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Otit2b1e_mr1WU2cPoB6yQ.jpeg</url>
            <title>Stories by Asif Ali on Medium</title>
            <link>https://medium.com/@asif-ali?source=rss-6b65384fb5a4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 16:17:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@asif-ali/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[React Architecture vs. MVC: Unidirectional Flow Advantage.]]></title>
            <link>https://medium.com/@asif-ali/react-architecture-vs-mvc-unidirectional-flow-advantage-c952136919b9?source=rss-6b65384fb5a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/c952136919b9</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-architecture]]></category>
            <category><![CDATA[mvc-frameworks]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Asif Ali]]></dc:creator>
            <pubDate>Thu, 04 Apr 2024 19:35:05 GMT</pubDate>
            <atom:updated>2024-04-04T19:35:05.445Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pDLfgBaOM4Pa3wd-bJTkkg.png" /><figcaption>React Architecture vs. MVC: Unidirectional Flow Advantage.</figcaption></figure><p>In the realm of front-end development, understanding architectural patterns is crucial for building robust and scalable applications. Let’s compare <strong>React Architecture</strong> with the traditional <strong>Model-View-Controller</strong> (<strong>MVC</strong>) pattern and delve into why React’s unidirectional data flow shines:</p><h4><strong>MVC (Model-View-Controller).</strong></h4><p><strong>MVC is a widely used architectural pattern that divides an application into three interconnected components:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*xoWf70R9sg9_d5bTPKXR3A.jpeg" /><figcaption>MVC Model</figcaption></figure><ol><li><strong>Model</strong>: Represents the data and business logic of the application.</li><li><strong>View</strong>: Displays the user interface and interacts with users.</li><li><strong>Controller</strong>: Acts as an intermediary between the Model and View, handling user input and updating the Model or View accordingly.</li></ol><p><strong>While MVC has been a staple in frontend development for decades, it comes with certain limitations, such as:</strong></p><ul><li><strong>Complex Data Flow</strong>: Managing data flow and state synchronization between components can become challenging as applications grow in complexity.</li><li><strong>Bidirectional Data Binding</strong>: Two-way data binding in MVC can lead to unpredictable behavior and make debugging and tracking state changes difficult.</li><li><strong>Spaghetti Code</strong>: In large-scale applications, the interconnected nature of MVC components can result in tangled and hard-to-maintain code.</li></ul><h4><strong>React Architecture: Unidirectional Data Flow.</strong></h4><p>React takes a different approach with its component-based architecture and unidirectional data flow pattern, which offers several advantages over <strong>MVC.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E5g1QdodeRhazY38WGtCxA.gif" /></figure><ol><li><strong>Component-Based</strong>: React breaks down the UI into reusable components, each responsible for its state and rendering logic. This modular approach promotes code reusability and simplifies maintenance.</li><li><strong>Virtual DOM</strong>: React’s virtual DOM efficiently updates only the components that have changed, minimizing DOM manipulation and improving performance.</li><li><strong>Unidirectional Data Flow</strong>: React enforces a unidirectional data flow, where data flows downwards from parent components to child components via props. This one-way flow of data makes the application state more predictable and easier to reason about.</li><li><strong>Immutable Data:</strong> React encourages the use of immutable data structures and pure functions, preventing unexpected side effects and simplifying state management.</li></ol><p>By embracing unidirectional data flow and component-based architecture, React offers a more scalable and maintainable solution compared to traditional <strong>MVC</strong> patterns. With React, developers can build complex user interfaces with confidence, knowing that the data flow remains predictable and the codebase remains modular and easy to maintain.</p><h4>Summary:</h4><p>In the comparison between <strong>React Architecture</strong> and the traditional <strong>MVC pattern</strong>, React’s unidirectional data flow stands out. While MVC relies on complex data flow and bidirectional binding, React’s component-based approach and virtual DOM ensure a streamlined development process. With React, data flows one way, simplifying state management and promoting code reusability. By embracing React’s architecture, developers can build scalable applications with confidence, thanks to its predictable data flow and modular codebase.</p><p><strong>What are your thoughts on React’s architecture compared to MVC?</strong></p><p><strong>#React #MVC #Architecture #FrontendDevelopment #UnidirectionalDataFlow</strong></p><p><strong>If you found this article to be useful, kindly show your appreciation by giving it a clap.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c952136919b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Best Practices for Responsive Design.]]></title>
            <link>https://medium.com/@asif-ali/best-practices-for-responsive-design-ff6ca5dffa02?source=rss-6b65384fb5a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff6ca5dffa02</guid>
            <dc:creator><![CDATA[Asif Ali]]></dc:creator>
            <pubDate>Thu, 04 Apr 2024 12:09:48 GMT</pubDate>
            <atom:updated>2024-04-04T12:09:48.849Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8mERfWmR2nejtsmvOc0nsg.png" /></figure><p><strong>Responsive design </strong>is an approach to web design and development that ensures a website or web application can adapt and provide an optimal viewing and interaction experience across a wide range of devices and screen sizes.</p><p><strong>Responsive design is crucial for ensuring your website looks and functions seamlessly across various devices and screen sizes.</strong></p><h4><strong>Here are some key best practices:</strong></h4><p><strong>Mobile-First Approach:</strong> Start designing for mobile devices first, then progressively enhance for larger screens. This ensures a streamlined experience on smaller devices and prevents unnecessary bloat on larger screens.</p><pre>/* CSS */<br>@media (min-width: 768px) {<br>  /* Styles for tablets and larger screens */<br>}</pre><p><strong>Fluid Grid Layouts:</strong> Use relative units like percentages and ems for layout dimensions instead of fixed pixels. This allows elements to scale proportionally based on the viewport size.</p><pre>/* CSS */<br>.container {<br>  width: 100%;<br>  max-width: 960px; /* Example max-width for desktop */<br>  margin: 0 auto; /* Center align */<br>}</pre><p><strong>Flexible Images and Media:</strong> Set images and media to max-width: 100%; to prevent them from overflowing their containers on smaller screens. Consider using responsive images or CSS media queries to serve appropriately sized images based on device resolution.</p><pre>/* CSS */<br>img {<br>  max-width: 100%;<br>  height: auto;<br>}</pre><p><strong>Media Queries:</strong> Utilize CSS media queries to apply different styles based on viewport width breakpoints. Define breakpoints where your layout needs adjustments to accommodate different screen sizes, such as for smartphones, tablets, and desktops.</p><pre>/* CSS */<br>@media (min-width: 768px) {<br>  /* Tablet styles */<br>}<br>@media (min-width: 992px) {<br>  /* Desktop styles */<br>}</pre><p><strong>Viewport Meta Tag:</strong> Include the viewport meta tag (&lt;meta name=”viewport” content=”width=device-width, initial-scale=1.0&quot;&gt;) in your HTML to ensure proper scaling and rendering on mobile devices.</p><pre>&lt;!-- HTML --&gt;<br>&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;</pre><p><strong>Progressive Enhancement:</strong> Provide a basic, functional experience for all users, then enhance the experience with additional features for larger screens or devices that support advanced capabilities.</p><pre>&lt;!-- HTML --&gt;<br>&lt;noscript&gt;Your browser does not support JavaScript!&lt;/noscript&gt;</pre><p><strong>Touch-Friendly Design:</strong> Optimize touch interactions by increasing the size of clickable elements, adding touch-friendly gestures, and avoiding hover-dependent interactions.</p><pre>/* CSS */<br>.button {<br>  padding: 10px 20px;<br>  font-size: 16px;<br>  cursor: pointer;<br>  touch-action: manipulation; /* Ensure fast click response */<br>}</pre><p><strong>Performance Optimization:</strong> Minimize page load times by optimizing assets, leveraging browser caching, and prioritizing critical resources. Consider lazy loading images and deferring non-essential scripts to improve performance on mobile devices with limited bandwidth.</p><pre>&lt;!-- HTML - Defer non-essential scripts --&gt;<br>&lt;script src=&quot;script.js&quot; defer&gt;&lt;/script&gt;</pre><p><strong>Testing Across Devices:</strong> Test your website on various devices and screen sizes to ensure consistent functionality and appearance. Use browser developer tools, online emulators, and real devices for comprehensive testing.</p><pre>&lt;!-- HTML --&gt;<br>&lt;link rel=&quot;stylesheet&quot; href=&quot;styles.css&quot;&gt;<br>&lt;script src=&quot;script.js&quot;&gt;&lt;/script&gt;</pre><p><strong>Accessibility Considerations:</strong> Ensure your responsive design is accessible to all users, including those with disabilities. Use semantic HTML, provide alternative text for images, and ensure interactive elements are keyboard accessible.</p><pre>&lt;!-- HTML --&gt;<br>&lt;img src=&quot;example.jpg&quot; alt=&quot;Description of the image&quot;&gt;</pre><p><strong>By following these best practices, you can create responsive designs that provide a seamless and user-friendly experience across a wide range of devices and screen sizes.</strong></p><p><strong>#MobileFirst #ResponsiveDesign #FluidGrid #ResponsiveLayout #FlexibleImages #ResponsiveImages #MediaQueries #Breakpoints #ViewportMetaTag #HTMLMeta</strong></p><p><strong>If you found this article to be useful, kindly show your appreciation by giving it a clap.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff6ca5dffa02" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Call Stack for Functions and Execution Contexts.]]></title>
            <link>https://medium.com/@asif-ali/javascript-call-stack-for-functions-and-execution-contexts-018948ebaa69?source=rss-6b65384fb5a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/018948ebaa69</guid>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[functions-in-javascript]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[call-stack]]></category>
            <dc:creator><![CDATA[Asif Ali]]></dc:creator>
            <pubDate>Sun, 03 Mar 2024 20:25:01 GMT</pubDate>
            <atom:updated>2024-03-03T20:25:01.330Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3CiH-2As2gW3cwQ8q_eeEw.png" /></figure><h4>What is the Call Stack?</h4><p>Every javascript execution environment has a call stack. That call stack is used to track function invocations.</p><p><strong>A Stack is a last-in-first-out (LIFO</strong>)<strong> simple data structure</strong>. The top element that we can top out of the stack is the last element that we push into it.</p><p><strong><em>In the case of the JavaScript call stack, these elements are function references.</em></strong></p><p><strong>Since JavaScript is single-threaded, </strong>there is only one stack and it can do one thing at a time. If the stack is executing something, nothing else will happen until the stack is done executing that thing.</p><pre>function f1() { f2(); };<br>function f2() { f3(); };<br>function f3() { f4(); };<br>function f4() { display.log(&#39;done&#39;); };<br><br>f1();</pre><p>When we call multiple functions that call each other, we naturally form a stack then we backtrack the function invocations back to the first caller.</p><p><strong>Let’s walk through a simple example to demonstrate what happens in the stack when we invoke functions.</strong></p><blockquote><strong>Here we have 3 simple functions:</strong><br><strong>add().<br>double()</strong> which calls <strong>add().</strong><br><strong>printDouble()</strong> which calls <strong>double()</strong>.</blockquote><pre>const add = (a, b) =&gt; z;<br><br>const double = (a) =&gt; add(a, a);<br><br>const printDouble = (a) =&gt; {<br>  const output = double(a);<br>  display.log(output);<br>};<br><br>printDouble(9);</pre><p>Now let’s assume that all these functions are wrapped in an <strong>immediately invoked function expression (IIFE)</strong>.</p><p>When we run the above code, JavaScript uses the stack to record where the program is currently executing. Every time we step into a function, <strong>a reference to that function gets pushed into the call stack</strong> and every time we return from a function, <strong>its reference gets popped out of the call stack </strong>It’s really that simple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t58rYt7ZD7mDnxR2XMN00g.png" /><figcaption>functions execution call stack</figcaption></figure><p>So the execution starts with the Wrapping <strong>IFFY function </strong>which is an <strong>anonymous function</strong>. So we push that into the stack. The <strong>IFFY function</strong> defines other functions but only executes <strong>printDouble</strong>. <strong>PrintDouble</strong> gets pushed into the stack. <strong>PrintDouble()</strong> calls <strong>double()</strong>, so we push <strong>double()</strong> into the stack, <strong>double()</strong> calls <strong>add()</strong> and we push <strong>add()</strong> into the stack. And so far, we’re still executing all functions we have not returned from any of them.</p><p><strong>Note how every time a function is added to the stack, its arguments and local variables are added too in that same level.</strong></p><p>You’ll sometimes hear the term <strong>stack frame</strong> to reference the function and its arguments and variables.</p><p>Now When we return from <strong>add()</strong>, we pop add out of the stack. We’re done with it. Then we return from <strong>double()</strong>, so <strong>double()</strong> gets popped out of the stack too. Now the execution continues in <strong>printDouble()</strong>. We get into a new function called <strong>console.log</strong> that gets pushed into the stack and then it gets popped immediately because it did not call any other functions. Then we implicitly return from <strong>printDouble()</strong>, so we pop <strong>printDouble()</strong> out of the stack and finally, we pop the <strong>anonymous iffy</strong> itself out of the stack.</p><h3>Conclusion:</h3><p>In conclusion, the JavaScript call stack is a crucial mechanism for tracking function invocations in the execution environment. It operates as a <strong>last-in-first-out (LIFO)</strong> data structure, with each function reference being pushed onto the stack when invoked and popped out when the function completes. As JavaScript is single-threaded, the stack ensures that only one task is executed at a time. The stack frames, comprising function references along with their arguments and local variables, illustrate the execution flow. In the provided example, the IIFE initiates the stack, and as functions are called and returned, the stack dynamically adjusts, reflecting the sequential execution of the program. Understanding the call stack is fundamental for comprehending the flow of function execution in JavaScript.</p><p><strong>If you found this article to be useful, kindly show your appreciation by giving it a clap.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=018948ebaa69" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embarking on Web App Success: A Simple Guide.]]></title>
            <link>https://medium.com/@asif-ali/embarking-on-web-app-success-a-simple-guide-2402f024b89e?source=rss-6b65384fb5a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/2402f024b89e</guid>
            <dc:creator><![CDATA[Asif Ali]]></dc:creator>
            <pubDate>Sat, 02 Mar 2024 10:09:51 GMT</pubDate>
            <atom:updated>2024-03-03T20:26:28.069Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iE5zB1JR0tq71PYz20zexA.png" /><figcaption>web app success simple guide</figcaption></figure><h4><strong>Creating a web app is like going on an exciting journey. To make sure you reach success, follow these easy steps as your guide.</strong></h4><h4>Set Clear Goals:</h4><p>Before you start building your web app, decide exactly what you want to achieve. Whether it’s making your users happy, earning money, or solving a specific problem, having clear goals helps you stay focused and motivated throughout the project.</p><h4>Understand Your Users:</h4><p>Take the time to get to know the people who will use your web app. What are their interests and preferences? What challenges do they face? Understanding your users ensures that your app meets their needs and provides a positive experience.</p><h4>Plan What Your App Will Do:</h4><p>Outline the features and functions of your web app. Think about what it will do and, equally important, what it won’t do. This planning phase is like creating a map for your journey, helping you navigate the development process without getting overwhelmed.</p><h4>Choose the Right Tools:</h4><p>Select the tools and technology that best fit your web app. Consider factors like user-friendliness, scalability, and the skills of your development team. Choosing the right tools is like picking the best ingredients for a recipe — it ensures a smooth and enjoyable experience for your users.</p><h4>Make a Plan:</h4><p>Develop a detailed plan for building your web app. Set achievable goals, establish deadlines, and allocate resources wisely. This planning phase is crucial for a successful journey, preventing confusion and ensuring that everyone involved knows their role in the development process.</p><h4>Improve Your App:</h4><p>Even after your web app is launched, the journey isn’t over. Actively listen to user feedback, identify areas for improvement, and make necessary updates. This iterative process ensures that your app stays relevant, enjoyable, and valuable to its users.</p><h4>Don’t Forget These Things:</h4><p>Pay attention to user experience — make sure your app is easy and enjoyable to use. Consider how you’ll tell people about your app — marketing is key. Also, think about scalability to handle more users as your app grows. Keep learning, stay adaptable, and continuously refine your app for long-term success.</p><p><strong>Follow these steps, and you’ll be well-prepared for a successful web app journey!</strong></p><h3>Conclusion:</h3><p>As you embark on your web app odyssey armed with these insights, remember that success is not just about the destination but the journey itself. May your web app make a positive impact in the digital realm, and here’s to the continued evolution and success of your creation!</p><p><strong>If you found this article to be useful, kindly show your appreciation by giving it a clap.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2402f024b89e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HOW DOES NEXTJS SOLVE THE PROBLEM OF SEO WITH SPA?]]></title>
            <link>https://medium.com/@asif-ali/how-does-nextjs-solve-the-problem-of-seo-with-spa-4ca579836db6?source=rss-6b65384fb5a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ca579836db6</guid>
            <dc:creator><![CDATA[Asif Ali]]></dc:creator>
            <pubDate>Sun, 10 Dec 2023 00:30:28 GMT</pubDate>
            <atom:updated>2023-12-10T00:30:28.143Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r2HgmGZAKG_Syj8RFOqfig.png" /><figcaption>NEXTJS SOLVED SEO PROBLEM</figcaption></figure><p><strong>Resolving SEO Challenges in Single Page Applications with Next.js</strong></p><p><strong>Introduction: </strong><br>When it comes to building websites with Next.js, considerations for <strong>Performance</strong>, <strong>SEO</strong>, <strong>Production Builds</strong>, and <strong>Routing</strong> are at the forefront. In this article, we’ll delve into the intricacies of addressing the SEO challenges associated with <strong>Single Page Applications (SPAs)</strong> and explore how Next.js adeptly resolves these issues.</p><p><strong>Understanding SEO: </strong><br><strong>Search Engine Optimization (SEO)</strong> plays a pivotal role in determining the visibility of your pages in search results on platforms like <strong>Google</strong> or <strong>Bing</strong>. However, SPAs pose a unique challenge to effective SEO implementation.</p><p><strong>SEO Challenges with SPAs: </strong><br>In traditional client-side rendered apps, when React initializes, it starts by displaying an initial empty <strong>div</strong> with the <strong>“root” ID</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zGu61VZGjXZp6Y4fWdMYYA.jpeg" /></figure><p>Subsequently, the browser requests <strong>JavaScript</strong> and <strong>assets</strong>, including images. If there are <strong>API requests</strong>, additional data retrieval occurs and finally page looks like the below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hFwygEAEy0nfFEZDg0jQHw.jpeg" /></figure><p>Unfortunately, this multi-step process poses a significant problem for <strong>SEO</strong> because search engines index only what is initially loaded. This means that on the initial load, the page appears empty, lacking the valuable information crucial for <strong>SEO</strong>.</p><p><strong>How Next.js Addresses the Issue: </strong><br>Next.js offers effective solutions to overcome these SEO challenges by enabling server-side rendering through various approaches:</p><ol><li><strong>Server Side Rendering (SSR):</strong> With SSR, Next.js allows rendering pages on the server rather than the client. This ensures that the JavaScript runs on the server, and assets and data are pre-fetched on the server itself, eliminating the need for client-side requests common in traditional SPAs due to we received a fully prepared <strong>HTML</strong> page on the client side in no time.</li><li><strong>Static Side Generation (SSG):</strong> Another approach provided by Next.js is SSG, where pages can be generated at build time. This allows for the creation of static HTML files, reducing the reliance on client-side rendering and improving SEO by ensuring that the initial page load contains meaningful content.</li><li><strong>Incremental Static Regeneration (ISR)</strong>: ISR in Next.js takes SSG a step further by allowing certain pages to be regenerated incrementally in the background. This ensures that the content remains up-to-date without sacrificing performance or SEO benefits.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RkPctOwldUat0YSBoHfMQQ.jpeg" /><figcaption>server-side-rendered page</figcaption></figure><p><strong>All the mentioned approaches share a common goal</strong>: addressing the challenge of the initial page load. They effectively tackle this issue, ensuring that the first time a user visits a page, there is no delay or empty content. By rendering the page on the server in advance, Next.js ensures that the user receives a fully prepared page from the start. This solution not only eliminates the problem of an empty initial page on the client side but also results in an efficient resolution of <strong>SEO</strong> concerns. The server-rendered page is ready to go, providing a complete and optimized experience for both users and search engines.</p><p><strong>Conclusion:</strong> <br>By incorporating <strong>Server Side Rendering</strong>, <strong>Static Side Generation</strong>, or <strong>Incremental Static Regeneration </strong>as per project requirements, Next.js offers an efficient solution to the SEO challenges associated with <strong>SPAs</strong>. This strategic approach to rendering on the server enhances the visibility and indexing of valuable content by search engines, thereby optimizing SEO for Next.js applications.</p><p>If you found this article to be useful, kindly show your appreciation by giving it a <strong>clap</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ca579836db6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Closure is Different from Lexical Scoping in Javascript.]]></title>
            <link>https://medium.com/@asif-ali/how-closure-is-different-from-lexical-scoping-in-javascript-d9a611823b04?source=rss-6b65384fb5a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9a611823b04</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[function]]></category>
            <category><![CDATA[javascript-scope]]></category>
            <category><![CDATA[clouser]]></category>
            <category><![CDATA[lexical-scoping]]></category>
            <dc:creator><![CDATA[Asif Ali]]></dc:creator>
            <pubDate>Sat, 12 Aug 2023 16:01:20 GMT</pubDate>
            <atom:updated>2023-08-12T16:01:20.838Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2oiCBd3feOH9hgzQe07C4g.png" /><figcaption>lexical scoping is an important part of the closure.</figcaption></figure><h4><strong>In Javascript, there is often a blending of concepts of closure and lexical scoping.</strong></h4><p>However, it’s important to note that <strong>closure</strong> and <strong>lexical scoping</strong> are two interconnected yet distinct concepts in JavaScript. Lexical scoping is actually a crucial component of closure, as we’ll delve into later.</p><p><strong>Prerequisites to understand this topic.</strong><br>1) Concept of Functions in Javascript.<br>2) Concept of scoping ( Block scope and Function scope ).</p><p><strong>After Reading this article I hope we will understand the following concepts.</strong><br>1) Difference between closure and lexical scoping.<br>2) How we can explain concepts of closure and lexical scoping in an interview via example<br>3) Why closures required lexical scoping.</p><h4>So What is the concept of Lexical scoping in Javascript?</h4><p>Lexical scoping encompasses everything the defined function can access.</p><pre>// scope global<br>var a = 1;<br>void function one(){<br>  // scope [one]<br>  // lexical scope [one , global]<br>  var b = 2;<br><br>  void function two(){<br>    // scope [two]<br>    // lexical scope [one , two , global]<br>    var c = 3;<br><br>    void function three(){<br>      // scope [three]<br>      // lexical scope [one , two , three , global]<br>      var d = 4;<br>      console.log(a + b + c + d);<br>    }();<br>  }();<br>}();</pre><p>In the given example, three functions are defined and promptly invoked, a pattern often referred to as <strong>IIFE</strong> (<strong>Immediately Invoked Function Expression</strong>).</p><p>In the first function, its <strong>lexical scope</strong> encompasses both its own scope and the global scope. Similarly, the <strong>lexical scope</strong> of the second function encompasses the scopes of function one, function two, and the global scope.</p><h4>So What is the concept of Clouser in Javascript?</h4><p>Clouser is a function that helps a defined function to access everything between itself and global scope, Even after the parent and above all functions have closed.</p><p>Here in the definition, we have two parts, First part refers to lexical scope but the second part is important to understand the concept of closure.</p><pre>const parentFunction = () =&gt; {<br>     let a = 2;<br>     console.log(a);<br><br>     const childFunction = () =&gt; {<br>          console.log(a += 1);<br>     }<br><br>     return childFunction;<br>}<br><br>const result = parentFunction();  // Line 1<br>console.log(result);              // Line 2<br>result();                         // Line 3</pre><p><strong>Let’s break the above example to understand step by step.</strong><br>1) Upon the execution of Line 1, the scope <strong>parentFunction</strong> is established, leading to the printing of <strong>2</strong> in the console. Following this, <strong>parentFunction</strong> returns <strong>childFunction </strong>and<strong> </strong>the function&#39;s scope is terminated and subsequently closed.</p><p>Up to this point, the understanding is precise and evident.</p><p>We are now aware that once the execution of <strong>parentFunction</strong> concludes, its scope is closed. Consequently, when we invoke <strong>result()</strong>, we are essentially calling the anonymous function that was assigned to <strong>childFunction</strong>. This function retains access to the variable (<strong>a</strong>) within <strong>parentFunction</strong>, even though <strong>parentFunction</strong> has already concluded and its scope has closed.</p><p>This capability arises from the closure that was formed during the definition of the function.</p><h3><strong>Summary</strong></h3><p>This article explores the interplay of closure and lexical scoping in JavaScript. Lexical scoping defines a function’s accessible scope, while closure enables a function to access variables even after its scope closes. The article provides examples of both concepts, highlighting their significance and how they coexist to enhance JavaScript’s functionality.</p><p>If you found this article to be useful, kindly show your appreciation by giving it a clap.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9a611823b04" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How useEffect is Different from useLayoutEffect in REACT JS.]]></title>
            <link>https://medium.com/@asif-ali/how-useeffect-is-different-from-uselayouteffect-in-react-js-744225677434?source=rss-6b65384fb5a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/744225677434</guid>
            <dc:creator><![CDATA[Asif Ali]]></dc:creator>
            <pubDate>Tue, 21 Feb 2023 22:45:17 GMT</pubDate>
            <atom:updated>2023-02-21T22:45:17.047Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6cNO22ni-dXcY-zMmfrkYg.png" /><figcaption>useEffect vs useLayoutEffect</figcaption></figure><p>React JS provides a number of built-in hooks that can significantly simplify our coding efforts, including <strong>useState</strong>, <strong>useEffect</strong>, <strong>useRef</strong>, <strong>useReducer</strong>, <strong>useContext</strong>, <strong>useMemo</strong>, <strong>useCallback</strong>, and <strong>useLayoutEffect</strong>.</p><p>While we may have a basic understanding of what each of these hooks does, in this article we will be delving into two of the most important hooks: <strong>useEffect</strong> and <strong>useLayoutEffect</strong>. Specifically, we will explore the differences between these hooks and when to use each one for optimal performance and functionality in our React JS applications.</p><p>In order to fully grasp the <strong>useEffect</strong> and <strong>useLayoutEffect</strong> hooks in React JS, it&#39;s important to first understand the lifecycle of a React component.</p><p>There are three main phases a component goes through <strong>Mounting</strong>, <strong>Updating</strong>, and <strong>Unmounting</strong>.</p><p><strong>To better illustrate this concept, let&#39;s take a look at a simple class component that demonstrates the different lifecycle methods involved in each phase.</strong></p><pre>class Test extends React.Component {<br>  constructor(props){<br>    super(props)<br>    this.state ={<br>      isLoading : false,<br>    }<br>  }<br>}<br><br>componentDidUpdate(prevProps , prevState) {<br>  // Some Code that will Run After Component Updates<br>}<br><br>componentWillUnmount() {<br>  // Some code that will run just Before Component unMounts<br>}<br><br>componentDidMount() {<br> // Some code that will execute Right after Component Mounts <br>}</pre><blockquote>The following code is an example of a simple functional component that demonstrates how life cycle methods in a class component can be replaced with a single hook <strong>useEffect</strong>. By using this hook, we can simplify our code and avoid the complexity associated with class components.</blockquote><pre>const Test = () =&gt; {<br>  const [isLoading , setIsLoading] = useState(fasle);<br>  <br>  useEffect(() =&gt; {<br>    /* Some Code That Will Run After Component Mounts and After <br>      Every Update Same Like componentDidMount and componentDidUpdate <br>      with minor tweaks depends on dependency array */<br>    <br>    return () = &gt; {<br>    /* This Block will run just Before Component unMounts same Like <br>       componetWillUnMount and usually use for cleanup memory Leaks */<br>    }<br>  },[]) <br>}</pre><p>As we’ve discussed, the <strong>useEffect</strong> hook in React functional components is capable of replacing three of the life cycle methods that are typically used in class components. By utilizing<strong>useEffect</strong>we can streamline our code and reduce the overall complexity of our components.</p><p>It’s important to note that while the <strong>useEffect</strong> hook in React functional components is capable of replacing three life cycle methods typically used in class components, there is a subtle yet significant difference between the two. Understanding this difference is crucial to effectively utilize <strong>useEffect</strong>in your components.</p><p>To enhance our comprehension of how these three life cycle methods are executed in class components, let’s take a look at a diagram that visually depicts their flow. This will provide us with a better understanding of how these methods work and how they differ from the <strong>useEffect</strong> hook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xa4aJQoS9KvcksPvNJdBDA.png" /></figure><p>The diagram shows that the first step of both functional and class components is the same, which is the Return. After this, the <strong>componentDidMount</strong> method is executed in the case of a class component, while the first function, which is the <strong>useEffect</strong>, is executed in the case of a functional component. So far, everything seems to be in order. However, when an update occurs, the <strong>componentDidUpdate</strong> method in a class component is executed synchronously. This means that the code in this method must finish executing before the DOM can be updated.</p><p>In contrast, the code in the first function of the <strong>useEffect</strong> in a functional component runs asynchronously. This means that it does not block the DOM from updating before it finishes executing its code block. Therefore, if there is code that mutates the DOM in the <strong>componentDidMount</strong> and <strong>componentDidUpdate</strong> methods, we cannot use the <strong>useEffect</strong> in a functional component. This is because it creates a flickering issue, as the <strong>useEffect’s</strong> 1st function does not block the return block (<strong>DOM updates</strong>) and runs while the update is happening, as well as after the 1st function finishes.</p><p>In a class component, the return block only runs (i.e., DOM updates) once, at the end of the <strong>componentDidMount</strong> lifecycle method. To replicate this same feature in a functional component, we need to use <strong>useLayoutEffect</strong> instead of useEffect. This is because <strong>useLayoutEffect</strong> is a synchronous method that executes after all DOM mutations are complete, just like the <strong>componentDidUpdate</strong> method in a class component. By using <strong>useLayoutEffect</strong>, we can ensure that the DOM is updated only once, at the end of the lifecycle method.</p><h3>Summary</h3><p>The article explores the concepts of <strong>useEffect</strong> and <strong>useLayoutEffect</strong> by comparing them with the lifecycle methods of class components. It also discusses how to replicate the synchronous behavior of the <strong>componentDidMount</strong> method in class components in functional components. Additionally, it explains when to use useEffect versus <strong>useLayoutEffect</strong>. Unlike <strong>useEffect</strong>, <strong>useLayoutEffect</strong> is a synchronous method that blocks the DOM from updating or running the return block until it finishes executing.</p><p>If you found this article to be useful, kindly show your appreciation by giving it a clap.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=744225677434" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Comparing React’s useState and useReducer Hooks]]></title>
            <link>https://medium.com/@asif-ali/comparing-reacts-usestate-and-usereducer-hooks-b1ee4da379bf?source=rss-6b65384fb5a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1ee4da379bf</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[usereducer]]></category>
            <category><![CDATA[usestate]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Asif Ali]]></dc:creator>
            <pubDate>Wed, 15 Feb 2023 08:49:59 GMT</pubDate>
            <atom:updated>2023-02-15T08:53:32.748Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JKK9fZ7J8Vpspo_nOmLk-w.png" /><figcaption>Comparing React’s useState and useReducer Hooks</figcaption></figure><h3>What is useState in React?</h3><p><strong>useState </strong>is a compelling Hook for simplifying managing states in our React Application. In <strong>useState </strong>definition of the setter function is hidden</p><h3>What is useReducer in React?</h3><p><strong>useReducer </strong>Hooks is used to storing and updating states just like useState Hook but in <strong>useReducer </strong>definition of the setter function is built custom as will explain in a bit.</p><p><strong>useState </strong>is Built with <strong>useReducer </strong>under it? Let me Explain How?</p><p>Before jumping into it, we first define what Reducer is<strong> </strong>in the context of React App.</p><h4><strong>What is Reducer?</strong></h4><p><strong>Reducer </strong>is simply a function that takes in a previous state as the first parameter, an action as the second parameter, and returns a new state.</p><pre>(previousState , action) =&gt; newState</pre><p>Let&#39;s Start Comparing useState and <strong>useReducer </strong>and will see how <strong>useState </strong>is built with <strong>useReducer</strong>.</p><pre>const [ data , setData ] = useState([])<br>const [ data , setData] = useReducer((state , action ) =&gt; action , [])</pre><p>Above both examples have the same functionality so we can say that <strong>useState </strong>and <strong>useReducer </strong>can replace each other, No doubt useState is a little shorter syntactically but from a functionality perspective we can use any one of these Hooks.</p><p>Let&#39;s Make Reducer more practical and extensible Right now, our reducer has only one trick, It sets the state to one value let&#39;s fix this.</p><pre>function reducer() {<br>switch (action.data) {<br>case &quot;setData&quot; : return action.data<br>default : return state<br>}}<br><br>const [ data , dispatch] = useReducer(reducer, [])</pre><p>In the above example, we fixed the issue of only one trick as now useReducer is able to update multiple types of data using a switch statement similarly we can use as many as we can to handle different types of data so we can now handle the functionality of multiple useState with just single <strong>useReducer. </strong>Also, we can separate the above reducer function into a separate file to share this logic between multiple components this makes useReducer more powerful compared to <strong>useState</strong>.</p><p>Now in the case of useReducer to set data or update data instead of using <strong>setData </strong>we will use dispatch to update our state here is How?</p><pre>dispatch( { type : &quot;setData&quot; , data : data })</pre><h4>Similarly, if we want to use the same syntax for useState we can do it as well with some changes Here it is.</h4><pre>function reducer2() {<br>switch (action.data) {<br>default : return state<br>}}<br><br>const [data , setData ] = useState( reducer2 , [] )</pre><p>You can think of this as useState is just useReducer with only a default action type.</p><h3><strong>Summary</strong></h3><p>This article explores the concepts of <strong>useState </strong>and <strong>useReducer</strong>, and demonstrates how useState is essentially constructed using useReducer. In the second section, the article illustrates how the syntax for both Hooks is identical. Additionally, it explains how useReducer can facilitate code reuse across multiple React components, and how it can reduce the need for multiple instances of <strong>useState </strong>by enabling the same functionality to be achieved with just one <strong>useReducer</strong>.</p><p>If you found this article to be useful, kindly show your appreciation by giving it a clap.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1ee4da379bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>