<?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 TechInsights on Medium]]></title>
        <description><![CDATA[Stories by TechInsights on Medium]]></description>
        <link>https://medium.com/@mujaffarhssn?source=rss-b0714d8b8ace------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*AYGwlmtA9DXRF4nk</url>
            <title>Stories by TechInsights on Medium</title>
            <link>https://medium.com/@mujaffarhssn?source=rss-b0714d8b8ace------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 07:31:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mujaffarhssn/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[Unlocking Hermes: How React Native’s JavaScript Engine Can Boost App Performance and Battery Life]]></title>
            <link>https://medium.com/@mujaffarhssn/unlocking-hermes-how-react-natives-javascript-engine-can-boost-app-performance-and-battery-life-ec7a8ff1d91f?source=rss-b0714d8b8ace------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec7a8ff1d91f</guid>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[battery-life]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[hermes]]></category>
            <dc:creator><![CDATA[TechInsights]]></dc:creator>
            <pubDate>Wed, 25 Sep 2024 20:19:10 GMT</pubDate>
            <atom:updated>2024-09-25T20:24:44.417Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UbmhTFNpL2QMc1QdmCpA_A.png" /></figure><p>As mobile app developers, we’re constantly seeking ways to improve our app’s performance and reduce battery consumption. One often-overlooked solution is React Native’s Hermes engine, a JavaScript engine designed to optimize app performance and reduce power consumption. In this article, we’ll delve into the world of Hermes, exploring its benefits, implementation, and best practices to help you unlock the full potential of your React Native app.</p><blockquote><strong>What is Hermes?</strong> Hermes is a JavaScript engine developed by Facebook, specifically designed for React Native. It’s an alternative to the default JavaScript engine, JSC (JavaScriptCore), and provides significant performance and power consumption improvements. Hermes is optimized for mobile devices, focusing on reducing memory usage, improving startup times, and increasing overall app performance.</blockquote><h4><strong>Benefits of Using Hermes So</strong>, why should you consider using Hermes in your React Native app?</h4><p>Here are some compelling reasons:</p><ul><li><strong>Improved Performance: </strong>Hermes provides faster execution of JavaScript code, resulting in snappier app performance and a better user experience.</li><li><strong>Reduced Battery Consumption:</strong> By optimizing power consumption, Hermes helps extend battery life, making your app more energy-efficient.</li><li><strong>Faster Startup Times:</strong> Hermes reduces the time it takes for your app to launch, ensuring a quicker startup experience for your users.</li></ul><h4><em>How to Enable Hermes in Your React Native App Enabling Hermes in your React Native app is a straightforward process.</em></h4><p>Follow these steps:</p><ol><li>Update Your <strong>react-native</strong> Version: Ensure you&#39;re running React Native <strong>0.64 or higher</strong>, as Hermes is enabled by default in these versions.</li><li>Add the Hermes Dependency: In your <strong>android/app/build.gradle</strong> file, add the following line:</li></ol><pre>dependencies {<br>  implementation &#39;com.facebook.herme:hermes-engine:+&#39;<br>}</pre><p>3. Configure Hermes in Your App: In your index.js file, add the following code:</p><pre>import { HermesEngine } from &#39;hermes-engine&#39;;<br><br>HermesEngine.enable();</pre><p><strong>Best Practices for Optimizing Hermes Performance To get the most out of Hermes, follow these best practices:</strong></p><ul><li><strong>Optimize Your JavaScript Code:</strong> Ensure your JavaScript code is optimized for performance, using techniques like code splitting, memoization, and caching.</li><li><strong>Use Hermes-Specific Features: </strong>Take advantage of Hermes-specific features, such as the hermes-engine module, to optimize performance and power consumption.</li><li><strong>Monitor Performance and Battery Life:</strong> Use tools like the React Native Debugger and Android Studio’s Battery Historian to monitor your app’s performance and battery life, identifying areas for improvement.</li></ul><blockquote><strong>Conclusion:</strong> <br><strong>Hermes is a lightweight JavaScript engine optimized for React Native apps, designed to improve overall performance. It helps in the following ways:</strong></blockquote><p>1. <strong>Faster Startup Time</strong>: Hermes precompiles JavaScript bytecode ahead of time, which reduces the overhead during app startup. Faster startups can lower battery usage in cases where the app is frequently opened and closed.</p><p>2. <strong>Memory and CPU Efficiency</strong>: Hermes uses less memory and CPU than other JavaScript engines, like V8, which indirectly contributes to battery savings. Lower CPU usage typically results in less power consumption.</p><p>3. <strong>Optimized Garbage Collection</strong>: Hermes has a more efficient garbage collection process, which can reduce CPU spikes and lower the app’s impact on battery life.</p><p>While enabling Hermes can offer <strong>performance improvements</strong> that may result in better battery life, the extent of the savings depends on your app’s specific use case, including the amount of JavaScript logic and interactions happening on the client side.</p><p>If your app is heavy on JavaScript execution, enabling Hermes can contribute positively to battery life.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec7a8ff1d91f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Debouncing vs Throttling: Optimizing Your JavaScript for Performance]]></title>
            <link>https://medium.com/@mujaffarhssn/debouncing-vs-throttling-optimizing-your-javascript-for-performance-a99d38f5eb3b?source=rss-b0714d8b8ace------2</link>
            <guid isPermaLink="false">https://medium.com/p/a99d38f5eb3b</guid>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[throttling-in-javascript]]></category>
            <category><![CDATA[debouncing-in-javascript]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[TechInsights]]></dc:creator>
            <pubDate>Sun, 18 Feb 2024 19:19:08 GMT</pubDate>
            <atom:updated>2024-02-18T19:19:08.941Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vctyYItpg96Ncdz_7FxHGA.png" /></figure><p>In the fast-paced world of web development, optimizing performance and enhancing user experience are paramount. Two key techniques in the arsenal of a JavaScript developer for controlling the rate at which a function is executed are debouncing and throttling. Despite their importance, these concepts are often misunderstood or interchangeably used. In this blog post, we’ll dive deep into what debouncing and throttling are, their differences, use cases, and how to implement them with code examples.</p><h3>Understanding Debouncing</h3><p>Debouncing is a programming practice used to ensure that time-consuming tasks do not fire so often, which can cause performance issues. In essence, it limits the execution of a function until a certain amount of idle time has passed without it being triggered again.</p><h3>Use Case: Search Input Field</h3><p>Consider a search input field that fetches suggestions from a server as the user types. Without debouncing, every keystroke would send a request, potentially leading to hundreds of requests per minute. Debouncing allows us to delay the function call until the user has stopped typing for a predefined time.</p><h3>Code Example:</h3><pre>function debounce(func, delay) {<br>  let debounceTimer;<br>  return function() {<br>    const context = this;<br>    const args = arguments;<br>    clearTimeout(debounceTimer);<br>    debounceTimer = setTimeout(() =&gt; func.apply(context, args), delay);<br>  };<br>}</pre><pre>// Usage<br>const fetchSuggestions = debounce(() =&gt; {<br>  // Fetch suggestions from the server<br>}, 250);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B9kXKdRLzdmnWWSBh0J_aQ.png" /></figure><h3>Understanding Throttling</h3><p>Throttling, on the other hand, ensures that a function is executed at most once every specified period. This is particularly useful for managing events that occur more frequently than you need to handle them.</p><h3>Use Case: Scroll Event Listener</h3><p>An example use case is attaching a listener to the scroll event of a webpage. Since the scroll event can fire dozens of times per second, throttling can be used to limit the number of times your callback function executes, improving performance.</p><h3>Code Example:</h3><pre>function throttle(func, limit) {<br>  let inThrottle;<br>  return function() {<br>    const args = arguments;<br>    const context = this;<br>    if (!inThrottle) {<br>      func.apply(context, args);<br>      inThrottle = true;<br>      setTimeout(() =&gt; (inThrottle = false), limit);<br>    }<br>  };<br>}</pre><pre>// Usage<br>window.addEventListener(&#39;scroll&#39;, throttle(() =&gt; {<br>  // Handle the scroll event<br>}, 1000));</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bBzOhmy7m5smUIKf_54WXw.png" /></figure><h3>Debouncing vs Throttling: Key Differences</h3><ul><li>Execution Frequency: Debouncing postpones the execution until after a period of inactivity, while throttling limits the execution to a fixed number of times over an interval.</li><li>Use Cases: Debouncing is ideal for tasks that don’t need to execute repeatedly in quick succession, such as API calls based on user input. Throttling is suited for controlling the execution rate of functions called in response to events like scrolling or resizing.</li></ul><h3>Implementing Debouncing and Throttling in JavaScript</h3><p>Both techniques can be implemented using vanilla JavaScript, as shown in the examples above. Additionally, libraries such as Lodash offer _.debounce and _.throttle functions, providing a more robust and cross-browser compatible solution.</p><h3>Conclusion</h3><p>Debouncing and throttling are powerful techniques for optimizing JavaScript applications, preventing unnecessary code executions, and improving user experience. By understanding their differences and use cases, developers can choose the right approach for their specific needs.</p><p>Incorporating these practices into your development workflow can significantly enhance the performance and responsiveness of your web applications, making them more enjoyable for users.</p><blockquote>Remember, the key to mastering these techniques is practice and experimentation. Try implementing them in your next project and observe the difference they make.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a99d38f5eb3b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Future of JavaScript Frameworks: React’s Place in 2024 and Beyond]]></title>
            <link>https://medium.com/@mujaffarhssn/the-future-of-javascript-frameworks-reacts-place-in-2024-and-beyond-588a4b01796e?source=rss-b0714d8b8ace------2</link>
            <guid isPermaLink="false">https://medium.com/p/588a4b01796e</guid>
            <category><![CDATA[future-of-web-apps]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[TechInsights]]></dc:creator>
            <pubDate>Sun, 18 Feb 2024 19:05:18 GMT</pubDate>
            <atom:updated>2024-02-18T19:05:18.438Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qhqDDSoMmi47XBkDu1uBHw.png" /></figure><p>Introduction Begin with an overview of the JavaScript landscape, highlighting its evolution over the years. Mention the rise of frameworks and libraries that have transformed web development, setting the stage for a discussion on React’s prominence and its future.</p><h4>The Current State of JavaScript Frameworks</h4><ul><li>Diversity and Competition: Briefly touch on the variety of frameworks available today (Vue, Angular, Svelte, etc.) and their unique selling points.</li><li>React’s Dominance: Discuss React’s current position in the market, supported by statistics on usage rates, community size, and contribution levels.</li></ul><p>Image Suggestion: A graph showing the popularity of JavaScript frameworks over time, highlighting React’s growth.</p><blockquote>Why React Stands Out</blockquote><ul><li>Ease of Learning and Flexibility: Explain how React’s learning curve and flexibility contribute to its popularity.</li><li>Strong Community Support: Elaborate on the role of community support, including forums, tutorials, and third-party tools, in fostering React’s growth.</li><li>Corporate Backing: Mention Facebook’s (Meta’s) support for React, ensuring its continuous development and stability.</li></ul><blockquote>React’s Evolution: Past to Present</blockquote><ul><li>From React to React Fiber: Discuss significant milestones in React’s development, focusing on performance improvements and feature additions.</li><li>The Introduction of Hooks: Highlight how React Hooks have revolutionized function components, making state management and side effects handling more intuitive.</li></ul><blockquote>Emerging Trends and React’s Adaptation</blockquote><ul><li>Component-Based Architecture: Dive into how React’s component-based model is influencing web development, making it more modular and reusable.</li><li>Convergence Towards TypeScript: Talk about the growing trend of using TypeScript with React for better development experience and how React is embracing this change.</li><li>Focus on Performance: Detail React’s efforts in optimizing performance, including lazy loading, concurrent mode, and automatic batching.</li></ul><blockquote>The Future of React and JavaScript Frameworks</blockquote><ul><li>React in the World of Web3 and Metaverse: Speculate on React’s role in developing decentralized applications and immersive experiences.</li><li>Sustainability and Green Computing: Discuss the potential for React and other frameworks to contribute to more energy-efficient web development practices.</li><li>Beyond Web Development: Consider React Native’s impact on mobile development and the potential for React’s principles to be applied in other areas, like desktop and VR applications.</li></ul><blockquote>Challenges and Opportunities</blockquote><ul><li>The Balancing Act: Reflect on the challenges React faces in staying lightweight and feature-rich, maintaining backward compatibility, and the potential for new frameworks to emerge.</li><li>Continuous Learning and Adaptation: Encourage developers to stay updated with React’s changes and the broader JavaScript ecosystem to leverage new opportunities.</li></ul><p>Conclusion Reiterate React’s significance in the JavaScript framework ecosystem and its potential to adapt and thrive amidst emerging technologies and trends. Emphasize the importance of community and developer engagement in shaping its future.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=588a4b01796e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Are You Familiar with the Hidden Powers of JSON.stringify() Function?]]></title>
            <link>https://medium.com/@mujaffarhssn/are-you-familiar-with-the-hidden-powers-of-json-stringify-function-59e230accd99?source=rss-b0714d8b8ace------2</link>
            <guid isPermaLink="false">https://medium.com/p/59e230accd99</guid>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[TechInsights]]></dc:creator>
            <pubDate>Sat, 04 Nov 2023 18:39:13 GMT</pubDate>
            <atom:updated>2023-11-04T18:39:13.737Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CXUkxu41ezS42KW-z9ATcg.jpeg" /></figure><p>JSON (JavaScript Object Notation) is a lightweight data interchange format that has become a standard for data exchange between a server and a web application. JavaScript provides a handy method, JSON.stringify(), to convert JavaScript objects into JSON strings. While the basic usage of JSON.stringify() is well-known, its true power lies in its ability to customize the serialization process using the replacer parameter. In this article, we will take a deep dive into the intricacies of JSON.stringify() and explore how the replacer function can be utilized to tailor our JSON output according to specific requirements.</p><h3>Understanding JSON.stringify()</h3><p>At its core, JSON.stringify() converts a JavaScript object into a JSON string. Here&#39;s the basic syntax:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HoSYKxcgO2UMzLu8Sn8BlA.png" /></figure><ul><li>value: The JavaScript object to be converted to a JSON string.</li><li>replacer: An optional function or array that alters the behavior of the stringification process.</li><li>space: An optional parameter that specifies the indentation of nested structures in the resulting string.</li></ul><h3>Exploring the Replacer Function</h3><p>The replacer function is a powerful tool that allows us to customize the serialization process. It is invoked for each item in the object being stringified and provides two parameters: key and value.</p><ul><li>key: The key of the current property being processed.</li><li>value: The value of the current property being processed.</li></ul><h4>Example 1: Customizing Property Values</h4><p>Let’s consider a scenario where we want to change the values of specific properties during serialization:</p><pre>const obj = { name: &quot;John&quot;, age: 30 };<br>const jsonString = JSON.stringify(obj, (key, value) =&gt; {<br>    if (key === &quot;name&quot;) {<br>        return &quot;Jane&quot;; // Modify the &#39;name&#39; property value<br>    }<br>    return value; // Keep other properties unchanged<br>});</pre><pre>console.log(jsonString); // Output: &#39;{&quot;name&quot;:&quot;Jane&quot;,&quot;age&quot;:30}&#39;</pre><p>In this example, the replacer function modifies the value of the name property, changing it from &quot;John&quot; to &quot;Jane&quot;.</p><h4>Example 2: Excluding Properties</h4><p>We can exclude specific properties from the JSON output by returning undefined for those properties:</p><pre>const obj = { name: &quot;John&quot;, age: 30 };<br>const jsonString = JSON.stringify(obj, (key, value) =&gt; {<br>    if (key === &quot;name&quot;) {<br>        return undefined; // Exclude the &#39;name&#39; property<br>    }<br>    return value; // Keep other properties unchanged<br>});</pre><pre>console.log(jsonString); // Output: &#39;{&quot;age&quot;:30}&#39;</pre><p>In this case, the name property is excluded from the JSON string.</p><h4>Example 3: Including Selected Properties</h4><p>We can include only specific properties by providing an array to the replacer function:</p><pre>const obj = { name: &quot;John&quot;, age: 30, city: &quot;New York&quot; };<br>const jsonString = JSON.stringify(obj, [&quot;name&quot;, &quot;age&quot;]);</pre><pre>console.log(jsonString); // Output: &#39;{&quot;name&quot;:&quot;John&quot;,&quot;age&quot;:30}&#39;</pre><p>In this example, only the name and age properties are included in the JSON string.</p><h3>Exploring the Space Argument</h3><p>The space argument in JSON.stringify() allows us to control the formatting of the resulting JSON string. It can be either a number or a string. When space is a number, it specifies the number of spaces to use for indentation. When space is a string, that string (up to 10 characters) is used for indentation. Let&#39;s dive into some examples to understand how the space argument works.</p><h4>Example 1: Using Number as Space</h4><pre>const obj = { name: &quot;John&quot;, age: 30, city: &quot;New York&quot; };<br>const jsonString = JSON.stringify(obj, null, 2);</pre><pre>console.log(jsonString);<br>// Output:<br>// &#39;{<br>//   &quot;name&quot;: &quot;John&quot;,<br>//   &quot;age&quot;: 30,<br>//   &quot;city&quot;: &quot;New York&quot;<br>// }&#39;</pre><p>In this example, the space argument is set to 2, resulting in an indented JSON string with 2 spaces of indentation.</p><h4>Example 2: Using String as Space</h4><pre>const obj = { name: &quot;John&quot;, age: 30, city: &quot;New York&quot; };<br>const jsonString = JSON.stringify(obj, null, &#39;--&#39;);</pre><pre>console.log(jsonString);<br>// Output:<br>// &#39;{<br>// --&quot;name&quot;: &quot;John&quot;,<br>// --&quot;age&quot;: 30,<br>// --&quot;city&quot;: &quot;New York&quot;<br>// }&#39;</pre><p>Here, the space argument is set to the string &#39;--&#39;, causing the JSON string to be indented with double dashes.</p><p>Now that you have a comprehensive understanding of JSON.stringify(), you can leverage this knowledge to optimize your data serialization process and enhance your JavaScript applications.</p><p>Happy coding! 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59e230accd99" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Reduce App Build Size in React Native]]></title>
            <link>https://medium.com/@mujaffarhssn/how-to-reduce-app-build-size-in-react-native-6d5a1ada6d75?source=rss-b0714d8b8ace------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d5a1ada6d75</guid>
            <category><![CDATA[optimization-techniques]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[apk-download]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[TechInsights]]></dc:creator>
            <pubDate>Wed, 11 Oct 2023 10:40:18 GMT</pubDate>
            <atom:updated>2023-10-11T10:40:18.691Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-aSkTbPU3OfwD12DUcsBpg.jpeg" /></figure><p>Developing a React Native app offers unparalleled flexibility and efficiency, but as your project grows, so does the app’s size. A bloated app can lead to slower downloads, increased data usage, and diminished user satisfaction. In this guide, we’ll explore effective strategies to shrink your React Native app’s build size, ensuring a seamless user experience. Additionally, we’ll delve into the advanced technique of analyzing the APK bundle using Android Studio, enabling you to pinpoint and optimize specific node modules. Let’s dive into the details.</p><h4>1. Optimize Image Assets:</h4><ul><li><strong>Use Proper Formats:</strong> Choose appropriate formats like WebP, SVG and PNG.</li><li><strong>Compress Images:</strong> Utilize tools like <a href="https://imageoptim.com/mac">ImageOptim</a> or <a href="https://tinypng.com/">TinyPNG</a> to compress images without quality loss.</li><li><strong>Implement Image Loading Libraries:</strong> Use React Native Fast Image or Expo ImageManipulator for efficient loading.</li></ul><h4>2. Code Splitting and Dynamic Imports:</h4><ul><li><strong>Lazy Loading:</strong> Implement lazy loading with React.lazy() and dynamic imports for heavy modules.</li><li><strong>Code Splitting:</strong> Use tools like React Loadable or React Native Bundle Splitter for smaller, on-demand code chunks.</li></ul><h4>3. Optimize Third-party Libraries:</h4><ul><li><strong>Choose Wisely:</strong> Select lightweight libraries and remove unused dependencies from package.json.</li></ul><h4>4. Bundle Size Analysis and Optimization:</h4><ul><li><strong>Use Bundle Analyzers:</strong> Visualize your bundle size with tools like Webpack Bundle Analyzer.</li><li><strong>Tree Shaking:</strong> Remove dead code using tree shaking techniques during the build process.</li></ul><h4>5. Optimize Fonts:</h4><ul><li><strong>Use System Fonts:</strong> Minimize custom font files; use system fonts whenever possible.</li><li><strong>Subset Fonts:</strong> Generate subsetted font files containing only necessary characters.</li></ul><h4>6. Reduce Redundant Code and Resources:</h4><ul><li><strong>Minimize Redundancy:</strong> Avoid duplicating resources and remove unused code and assets.</li></ul><h4>7. Optimize Native Modules:</h4><ul><li><strong>Proper Linking:</strong> Ensure correct linking of native modules to avoid unnecessary code inclusion.</li><li><strong>Customize Build Configurations:</strong> Customize Gradle (Android) and Xcode (iOS) configurations to exclude unnecessary resources.</li></ul><h4>8. APK Bundle Analysis with Android Studio:</h4><ul><li><strong>Generate APK Bundle:</strong> Create an APK bundle of your React Native app.</li><li><strong>Open Android Studio:</strong> Analyze the APK bundle in Android Studio.</li><li><strong>Use APK Analyzer: </strong>Explore the APK’s contents, focusing on .so (native libraries) and .dex (compiled Java) files.</li><li><strong>Identify JavaScript Modules:</strong> Look for files like index.android.bundle to identify large Node modules.</li><li><strong>Generate Source Maps:</strong> Enable source map generation in your project for detailed module analysis.</li><li><strong>Inspect Bundles:</strong> Use tools like source-map-explorer to identify specific modules contributing to bundle size.</li></ul><h4>9. Optimize Large Modules:</h4><ul><li><strong>Choose Alternatives:</strong> Replace large modules with lighter libraries or custom implementations.</li><li><strong>Implement Dynamic Imports:</strong> Load components and heavy modules dynamically to reduce initial bundle size.</li></ul><h4>Conclusion:</h4><p>By following these comprehensive strategies and leveraging advanced techniques like APK bundle analysis in Android Studio, you can significantly reduce your React Native app’s build size. Regularly audit your project, stay updated with the latest optimization techniques, and use APK analysis to make informed decisions about module optimization. With a leaner app size, your users will enjoy faster downloads, smoother performance, and an overall more satisfying mobile experience. Start implementing these techniques today and ensure your app stands out in the competitive app market.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d5a1ada6d75" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Trick: Automate authToken flow in Postman API testing]]></title>
            <link>https://medium.com/@mujaffarhssn/trick-automate-authtoken-flow-in-postman-api-testing-936d6b1aeea0?source=rss-b0714d8b8ace------2</link>
            <guid isPermaLink="false">https://medium.com/p/936d6b1aeea0</guid>
            <category><![CDATA[api-development]]></category>
            <category><![CDATA[token]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[postman-collections]]></category>
            <category><![CDATA[postman-testing]]></category>
            <dc:creator><![CDATA[TechInsights]]></dc:creator>
            <pubDate>Fri, 06 Oct 2023 12:09:38 GMT</pubDate>
            <atom:updated>2023-10-07T07:04:18.279Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IDWHOZU8EdkTJHyA" /><figcaption>Photo by <a href="https://unsplash.com/@theshubhamdhage?utm_source=medium&amp;utm_medium=referral">Shubham Dhage</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When managing multiple APIs within a Postman collection, the traditional approach involves hitting the login API first, copying the generated token, and pasting it into other APIs for testing. However, this manual process can be automated using Postman’s environment variables. By utilizing environment variables, you can seamlessly share authentication tokens across different requests within the collection, eliminating the need for repetitive manual steps and ensuring a more efficient and streamlined testing process.</p><h4>What are Environment Variables?</h4><p>Environment variables are named values that can be used throughout a Postman collection. They are stored in a separate file and can be used to store sensitive information, such as API keys and tokens. This can help to keep your requests secure and easy to share with others.</p><h4>How to Automate Token Flows Using Environment Variables</h4><p>To automate a token flow in Postman using environment variables, you will need to:</p><blockquote>1. Create an environment variable to store your token. (Click on the Environment button ‘Top right side’)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vTo7dZNwnvIZq9A4ps_EGA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ndd2gEDOyG-1BZp377Mb1A.png" /></figure><blockquote>2. Go to the token API (Login API) &amp; set the token in the environment token variable.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mlw_JrdDVsX48i1B_L7etw.png" /></figure><pre>// If I get the response in JSON format like below<br>{<br>    &quot;user&quot;: {<br>        &quot;data&quot;: {<br>            &quot;id&quot;: &quot;130&quot;,<br>            &quot;type&quot;: &quot;email_account&quot;,<br>        }<br>    },<br>    &quot;meta&quot;: {<br>        &quot;token&quot;: &quot;eyJhbGciOiJIUzUxMiJ9.eyJpZCI6MTMwLCJleHAiOjE2OTY1OTQ5NTAsInRva2VuX3R5cGUiOiJsb2dpbiJ9.KbrNqpAlKRuYG-Q-nshP820MH6LQleKVE_ly_ab2yy1UrlnqiAq4Df5UhaKd77rqJMoVzyWOrUICrGWqT7bOdQ&quot;<br>    }<br>}<br><br>/* Script to set token environment variable dynamically after successful login<br> Change authToken destructuring according to your login response data */<br><br>if(pm.response.code === 200) {<br>const authToken=pm.response.json().meta.token<br>    pm.environment.set(&#39;token&#39;, authToken )<br>}</pre><blockquote>3. Now you can use this token variable in any of the API for passing tokens like this way token: {{token}}</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OPnViTjFk2AFERqvyIK1bg.png" /></figure><h4>Benefits of Automating Token Flows</h4><p>Automating token flows in Postman collections has a number of benefits, including:</p><ul><li>Improved security: Storing tokens in environment variables helps to keep them secure.</li><li>Increased productivity: Automating token flows can save you time and effort, especially if you are working with multiple APIs.</li><li>Improved collaboration: Sharing environment variables with others can make it easier to collaborate on API development projects.</li></ul><h4>Conclusion</h4><p>Automating token flows in Postman collections using environment variables is a powerful way to improve the security, productivity, and collaboration of your API development workflow.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=936d6b1aeea0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering React.js: 15 Essential Interview Questions and Detailed Answers]]></title>
            <link>https://medium.com/@mujaffarhssn/react-js-interview-mastery-expert-answers-to-common-questions-62d96e5b3dd5?source=rss-b0714d8b8ace------2</link>
            <guid isPermaLink="false">https://medium.com/p/62d96e5b3dd5</guid>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[important-question]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[success]]></category>
            <dc:creator><![CDATA[TechInsights]]></dc:creator>
            <pubDate>Mon, 02 Oct 2023 18:11:43 GMT</pubDate>
            <atom:updated>2023-10-06T04:00:06.874Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gj7Iqcn5JTJVmBwi" /><figcaption>Photo by <a href="https://unsplash.com/@linkedinsalesnavigator?utm_source=medium&amp;utm_medium=referral">LinkedIn Sales Solutions</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>1. What is React, why is it used in web development, and how does it differ from other JavaScript libraries or frameworks?</h3><p>React is a JavaScript library for building user interfaces, primarily single-page applications. It allows developers to create reusable UI components and efficiently update and render the UI based on data changes. React is widely used in web development because of its component-based architecture, virtual DOM, and unidirectional data flow, making it easier to build interactive and responsive user interfaces.</p><h4>React differs from other JavaScript libraries/frameworks in several ways:</h4><ul><li><strong>Component-Based Architecture:</strong> React applications are built as a composition of components, making it modular and maintainable.</li><li><strong>Virtual DOM:</strong> React uses a virtual DOM to improve performance by minimizing direct manipulation of the actual DOM, updating only the necessary parts when data changes.</li><li><strong>Unidirectional Data Flow:</strong> React follows a one-way data binding, making it easier to track changes and debug applications.</li><li><strong>JSX:</strong> React uses JSX, a syntax extension that allows mixing HTML with JavaScript, enhancing readability and ease of use.</li><li><strong>React Native:</strong> React can be used to build not only web applications but also native mobile applications, differentiating it from many other frameworks.</li></ul><h3>2. Explain the concept of Virtual DOM in React and how it contributes to performance optimization.</h3><p>The Virtual DOM is a programming concept used in React to improve performance and user experience. When changes are made in a React application, the entire UI doesn’t get updated immediately in the actual DOM. Instead, React first updates a virtual representation of the DOM in memory.</p><p>Here’s how it works:</p><ol><li><strong>Virtual DOM Representation:</strong> When state or props change, React creates a new virtual DOM tree.</li><li><strong>Difference Calculation:</strong> React compares this new tree with the previous one to determine the differences (diffing).</li><li><strong>Minimal DOM Updates:</strong> React calculates the most efficient way to update the actual DOM, applying only the necessary changes.</li></ol><p>By minimizing direct interaction with the real DOM and batching updates, React significantly speeds up the rendering process, leading to a more responsive user interface.</p><h3>3. Differentiate between props and state in React. When would you use one over the other?</h3><p><strong>Props:</strong> Props (short for properties) are immutable data passed from a parent component to a child component. They allow the parent component to pass data to the child component, enabling communication between them. Props are read-only for the child component.</p><ul><li>Use props when you want to pass data from a parent to a child component and maintain a unidirectional flow of data.</li><li>Example:</li></ul><pre>// ParentComponent.js &lt;ChildComponent name=&quot;John&quot; /&gt;  <br>// ChildComponent.js <br>const ChildComponent = (props) =&gt; {<br>   return &lt;p&gt;Hello, {props.name}!&lt;/p&gt;;<br> };</pre><p><strong>State:</strong> State is mutable data that belongs to a component and can be changed over time. It is initialized in the component’s constructor and can be updated using the setState method. State enables components to manage their data internally.</p><ul><li>Use state when you want to manage and track changes to data within a component. State changes trigger re-rendering of the component.</li><li>Example:</li></ul><pre>class Counter extends React.Component {<br>  constructor(props) {<br>    super(props);<br>    this.state = { count: 0 };<br>  }<br>  incrementCount = () =&gt; {<br>    this.setState({ count: this.state.count + 1 });<br>  };<br>  render() {<br>    return (<br>      &lt;div&gt;<br>        {&quot; &quot;}<br>        &lt;p&gt;Count: {this.state.count}&lt;/p&gt;{&quot; &quot;}<br>        &lt;button onClick={this.incrementCount}&gt;Increment&lt;/button&gt;{&quot; &quot;}<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><h3>4. Describe the component lifecycle methods in React. What is the purpose of each method?</h3><p>React components go through various lifecycle stages from initialization to removal. The main lifecycle methods include:</p><h4><strong>Mounting:</strong></h4><ul><li>constructor(): Called when a component is initialized. Used for setting up initial state and binding methods.</li><li>render(): Renders the component UI. It is a mandatory method for class components.</li><li>componentDidMount(): Invoked after the component is rendered in the DOM. Ideal for making API calls or setting up subscriptions.</li></ul><h4>Updating:</h4><ul><li>shouldComponentUpdate(nextProps, nextState): Determines if the component should re-render based on changes in props and state. Returns a Boolean value.</li><li>render(): Re-renders the component if shouldComponentUpdate returns true.</li><li>componentDidUpdate(prevProps, prevState): Called after the component updates in the DOM. Useful for performing side-effects after a component re-renders.</li></ul><h4>Unmounting:</h4><ul><li>componentWillUnmount(): Invoked just before a component is removed from the DOM. Used for cleanup tasks, like canceling network requests or removing event listeners.</li></ul><p>These methods provide developers with control over the component’s behavior at different stages of its lifecycle.</p><h3>5. What is JSX, and how does it differ from regular JavaScript and HTML?</h3><p>JSX (JavaScript XML) is a syntax extension for JavaScript, often used with React. It allows mixing HTML-like code directly within JavaScript. JSX makes React component code more readable and intuitive.</p><h4><strong>Differences from regular JavaScript/HTML:</strong></h4><ul><li><strong>JavaScript Expressions:</strong> In JSX, curly braces {} are used to embed JavaScript expressions. This allows dynamic content and calculations.</li><li><strong>HTML-Like Syntax:</strong> JSX resembles HTML, allowing developers to write familiar HTML tags and attributes within JavaScript.</li><li><strong>Components as Custom Tags:</strong> JSX enables the use of custom components as if they were HTML tags, enhancing reusability and modularity.</li><li><strong>No Separation of Concerns:</strong> JSX combines the concerns of UI structure (HTML-like tags) and UI logic (JavaScript expressions) in one place, simplifying component definition.</li></ul><p>Example:</p><pre>const element = &lt;h1&gt;Hello, {name}!&lt;/h1&gt;;<br>// JSX is transformed to: React.createElement(&#39;h1&#39;, null, &#39;Hello, &#39;, name, &#39;!&#39;)</pre><h3>6. How do you create a functional component in React? Can you provide an example?</h3><p>Functional components are simpler and more concise than class components. They are just JavaScript functions that take props as an argument and return React elements.</p><p>Example of a functional component:</p><pre>import React from &#39;react&#39;;<br>const FunctionalComponent = (props) =&gt; {<br>  return &lt;div&gt;Hello, {props.name}!&lt;/div&gt;;<br>};<br>export default FunctionalComponent;</pre><p>In this example, FunctionalComponent is a functional component that accepts a name prop and renders a greeting message.</p><h3>7. What are class components in React, and how do they differ from functional components?</h3><p>Class components are ES6 classes that extend from React.Component. They can hold and manage local state, have access to lifecycle methods, and can be stateful.</p><p>Functional components, on the other hand, are simpler functions that take props as an argument and return React elements. Before the introduction of Hooks in React 16.8, functional components were stateless and didn’t have access to state or lifecycle methods. However, with Hooks, functional components can now manage state and use other React features.</p><h4>Differences:</h4><ul><li><strong>Syntax:</strong> Class components are defined using ES6 class syntax, while functional components are just JavaScript functions.</li><li><strong>State:</strong> Class components can have state, whereas functional components were stateless before Hooks.</li><li><strong>Lifecycle Methods:</strong> Class components have access to lifecycle methods like componentDidMount, componentDidUpdate, etc., which functional components lacked before Hooks.</li><li><strong>Readability and Simplicity:</strong> Functional components are often shorter and more readable than class components, especially for simple UI components.</li></ul><h3>8. How do you handle forms in React? Explain controlled and uncontrolled components.</h3><p>In React, forms can be handled using controlled and uncontrolled components.</p><ul><li><strong>Controlled Components:</strong> In controlled components, form data is controlled by React. The input elements in the form have their values set by state, and onChange handlers manage the input changes by updating the state.</li><li>Example of a controlled component:</li></ul><pre>class ControlledForm extends React.Component {<br>  constructor(props) {<br>    super(props);<br>    this.state = { inputValue: &quot;&quot; };<br>  }<br>  handleInputChange = (event) =&gt; {<br>    this.setState({ inputValue: event.target.value });<br>  };<br>  handleSubmit = (event) =&gt; {<br>    event.preventDefault();<br>    console.log(&quot;Submitted value:&quot;, this.state.inputValue);<br>  };<br>  render() {<br>    return (<br>      &lt;form onSubmit={this.handleSubmit}&gt;<br>        {&quot; &quot;}<br>        &lt;input<br>          type=&quot;text&quot;<br>          value={this.state.inputValue}<br>          onChange={this.handleInputChange}<br>        /&gt;{&quot; &quot;}<br>        &lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;{&quot; &quot;}<br>      &lt;/form&gt;<br>    );<br>  }<br>}</pre><ul><li><strong>Uncontrolled Components:</strong> Uncontrolled components allow form data to be handled by the DOM itself. Refs are used to directly interact with the DOM elements to get their values.</li><li>Example of an uncontrolled component:</li></ul><pre>const UncontrolledForm = () =&gt; {<br>  let inputRef = React.createRef();<br>  const handleSubmit = (event) =&gt; {<br>    event.preventDefault();<br>    console.log(&quot;Submitted value:&quot;, inputRef.current.value);<br>  };<br>  return (<br>    &lt;form onSubmit={handleSubmit}&gt;<br>      {&quot; &quot;}<br>      &lt;input type=&quot;text&quot; ref={inputRef} /&gt; &lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;{&quot; &quot;}<br>    &lt;/form&gt;<br>  );<br>};</pre><p>Controlled components provide more control and flexibility, making them the preferred approach in most cases. Uncontrolled components can be useful for integrating React with non-React code or libraries.</p><h3>9. What is the purpose of keys in React lists? Why are they important?</h3><p>Keys are special string attributes used in React to help identify which items have changed, been added, or been removed in a list of elements. When rendering dynamic lists in React, each item should have a unique key prop. Keys help React identify which elements have changed, added, or removed, allowing for efficient updates without re-rendering the entire list.</p><h4>Keys are important for several reasons:</h4><ul><li><strong>Efficient Updates:</strong> React can identify the minimal number of changes required, improving performance by preventing unnecessary re-renders.</li><li><strong>Stable Identity:</strong> Keys ensure that the identity of components persists across re-renders. Without keys, components could lose their state or DOM state, leading to unexpected behavior.</li><li><strong>Optimized Reconciliation: </strong>When React performs reconciliation (the process of updating the virtual DOM with the real DOM), keys help React recognize specific elements, making updates faster and more accurate.</li></ul><p>Example usage of keys in a list of React components:</p><pre>const TodoList = ({ todos }) =&gt; {<br>  return (<br>    &lt;ul&gt;<br>      {todos.map(todo =&gt; (<br>        &lt;li key={todo.id}&gt;{todo.text}&lt;/li&gt;<br>      ))}<br>    &lt;/ul&gt;<br>  );<br>};</pre><p>In this example, todo.id is used as a key to uniquely identify each li element in the list of todos.</p><h3>10. What is React Router, and how does it enable client-side routing in a React application?</h3><p>React Router is a popular library for implementing routing in React applications. It enables client-side navigation by allowing developers to declare routes and their corresponding components. React Router uses the browser’s History API to manipulate the URL without triggering a full page refresh, creating a seamless single-page application (SPA) experience.</p><h4>Here’s how React Router works:</h4><ul><li><strong>Route Declaration:</strong> Developers define routes using Route components. Each Route maps a URL path to a React component.</li><li>Example:</li></ul><pre>import { BrowserRouter as Router, Route } from &quot;react-router-dom&quot;;<br>const App = () =&gt; {<br>  return (<br>    &lt;Router&gt;<br>      {&quot; &quot;}<br>      &lt;Route path=&quot;/&quot; exact component={Home} /&gt;{&quot; &quot;}<br>      &lt;Route path=&quot;/about&quot; component={About} /&gt;{&quot; &quot;}<br>      &lt;Route path=&quot;/contact&quot; component={Contact} /&gt;{&quot; &quot;}<br>    &lt;/Router&gt;<br>  );<br>};</pre><ul><li><strong>Linking:</strong> Navigation between routes is achieved using the Link component. When a Link is clicked, it updates the URL without triggering a full page reload.</li><li>Example:</li></ul><pre>import { Link } from &quot;react-router-dom&quot;;<br>const Navbar = () =&gt; {<br>  return (<br>    &lt;nav&gt;<br>      {&quot; &quot;}<br>      &lt;ul&gt;<br>        {&quot; &quot;}<br>        &lt;li&gt;<br>          &lt;Link to=&quot;/&quot;&gt;Home&lt;/Link&gt;<br>        &lt;/li&gt;{&quot; &quot;}<br>        &lt;li&gt;<br>          &lt;Link to=&quot;/about&quot;&gt;About&lt;/Link&gt;<br>        &lt;/li&gt;{&quot; &quot;}<br>        &lt;li&gt;<br>          &lt;Link to=&quot;/contact&quot;&gt;Contact&lt;/Link&gt;<br>        &lt;/li&gt;{&quot; &quot;}<br>      &lt;/ul&gt;{&quot; &quot;}<br>    &lt;/nav&gt;<br>  );<br>};</pre><p>React Router manages the application’s UI state based on the URL, enabling dynamic content rendering while preserving the SPA experience.</p><h3>11. Explain the concept of conditional rendering in React. Provide an example.</h3><p>Conditional rendering in React involves displaying different components or UI elements based on certain conditions. This can be achieved using JavaScript expressions within JSX or by employing conditional operators.</p><p>Example of conditional rendering using a JavaScript expression:</p><pre>const Greeting = ({ isLoggedIn }) =&gt; {<br>  if (isLoggedIn) {<br>    return &lt;UserGreeting /&gt;;<br>  }<br>  return &lt;GuestGreeting /&gt;;<br>};</pre><pre>const UserGreeting = () =&gt; &lt;h1&gt;Welcome back!&lt;/h1&gt;;<br>const GuestGreeting = () =&gt; &lt;h1&gt;Please sign up.&lt;/h1&gt;;</pre><p>In this example, the Greeting component renders different greetings based on the isLoggedIn prop.</p><p>Example of conditional rendering using a conditional operator:</p><pre>const Message = ({ isLoggedIn }) =&gt; {<br>  return (<br>    &lt;div&gt;<br>      {isLoggedIn ? (<br>        &lt;UserMessage /&gt;<br>      ) : (<br>        &lt;GuestMessage /&gt;<br>      )}<br>    &lt;/div&gt;<br>  );<br>};</pre><pre>const UserMessage = () =&gt; &lt;p&gt;Hello, user!&lt;/p&gt;;<br>const GuestMessage = () =&gt; &lt;p&gt;Please log in to continue.&lt;/p&gt;;</pre><p>Here, the Message component conditionally renders either the UserMessage or GuestMessage component based on the isLoggedIn prop.</p><h3>12. What are React Hooks, and why were they introduced? Provide examples of some commonly used hooks.</h3><p>React Hooks are functions that allow developers to “hook into” React state and lifecycle features from functional components. Before Hooks, state management and other React features were only available in class components. Hooks were introduced in React 16.8 to simplify state management, side-effects, and reuse of stateful logic in functional components.</p><h4>Commonly used hooks include:</h4><ul><li><strong>useState:</strong> useState is used to add state management to functional components. It returns a stateful value and a function to update it.</li><li>Example:</li></ul><pre>import React, { useState } from &quot;react&quot;;<br>const Counter = () =&gt; {<br>  const [count, setCount] = useState(0);<br>  return (<br>    &lt;div&gt;<br>      {&quot; &quot;}<br>      &lt;p&gt;Count: {count}&lt;/p&gt;{&quot; &quot;}<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Increment&lt;/button&gt;{&quot; &quot;}<br>    &lt;/div&gt;<br>  );<br>};</pre><ul><li><strong>useEffect:</strong> useEffect performs side effects in functional components. It can mimic componentDidMount, componentDidUpdate, and componentWillUnmount lifecycle methods.</li><li>Example:</li></ul><pre>import React, { useState, useEffect } from &#39;react&#39;;  <br>const DataFetcher = () =&gt; {   const [data, setData] = useState([]);    <br>useEffect(() =&gt; {     fetch(&#39;https://api.example.com/data&#39;)<br>       .then(response =&gt; response.json())  <br>     .then(data =&gt; setData(data))     <br>  .catch(error =&gt; console.error(error));  <br> }, []); <br>// Empty dependency array ensures the effect runs once after the initial render    return (     &lt;ul&gt;       {data.map(item =&gt; (         &lt;li key={item.id}&gt;{item.name}&lt;/li&gt;       ))}     &lt;/ul&gt;   ); };</pre><ul><li><strong>useContext:</strong> useContext allows functional components to access the context directly without wrapping them in a Context.Consumer.</li><li>Example:</li></ul><pre>import React, { useContext } from &quot;react&quot;;<br>const ThemeContext = React.createContext(&quot;light&quot;);<br>const ThemedComponent = () =&gt; {<br>  const theme = useContext(ThemeContext);<br>  return &lt;div&gt;Current theme: {theme}&lt;/div&gt;;<br>};</pre><p>React Hooks provide a cleaner and more concise way to manage state and side-effects, making functional components a powerful choice for building complex applications.</p><h3>13. How can you pass data between parent and child components in React?</h3><p>Data can be passed from parent to child components in React through props. Props (short for properties) are a mechanism for passing data from parent to child components. The parent component can pass any data, including variables, functions, or objects, to the child component as props.</p><p>Example of passing data from a parent to a child component:</p><pre>// ParentComponent.js<br>import React from &#39;react&#39;;<br>import ChildComponent from &#39;./ChildComponent&#39;;<br><br>const ParentComponent = () =&gt; {<br>  const greeting = &#39;Hello from Parent!&#39;;<br>  return &lt;ChildComponent greeting={greeting} /&gt;;<br>};<br>export default ParentComponent;<br>// ChildComponent.js<br>import React from &#39;react&#39;;<br>const ChildComponent = (props) =&gt; {<br>  return &lt;p&gt;{props.greeting}&lt;/p&gt;;<br>};<br>export default ChildComponent;</pre><p>In this example, the ParentComponent passes the greeting variable as a prop to the ChildComponent, which then displays it in a p element.</p><h3>14. What is Redux, and how does it manage the state in a React application? Explain the core principles of Redux.</h3><p>Redux is a state management library for JavaScript applications, primarily used with React. It provides a predictable state container, making it easier to manage and update the state of an application. Redux follows three core principles:</p><ol><li><strong>Single Source of Truth:</strong> The state of the entire application is stored in an object tree within a single store. This ensures that the state is centralized and can be easily accessed and modified.</li><li><strong>State is Read-Only:</strong> The only way to change the state is by dispatching actions. Actions are plain JavaScript objects that describe what happened. Reducers are functions that specify how the state changes in response to actions.</li></ol><p>Example action:</p><pre>{   type: &#39;INCREMENT&#39;,   payload: 1 }</pre><p>3. <strong>Changes are Made with Pure Functions:</strong> To specify how the state tree is transformed by actions, you write pure reducers. Reducers are pure functions that take the previous state and an action, and return the new state.</p><p>Example reducer:</p><pre>const counterReducer = (state = 0, action) =&gt; {<br>  switch (action.type) {<br>    case &quot;INCREMENT&quot;:<br>      return state + action.payload;<br>    default:<br>      return state;<br>  }<br>};</pre><p>By following these principles, Redux provides a clear and predictable way to manage the state of a React application, making it easier to debug, test, and maintain large-scale applications.</p><h3>15. Describe the Flux architecture and its relationship to React.</h3><p>Flux is an architectural pattern used for managing state in front-end applications. It complements React by providing a unidirectional data flow and a centralized data store. The Flux architecture consists of several key components:</p><ul><li><strong>Actions:</strong> Actions are payloads of information that send data to the store. They are the only source of information for the store and carry a type field that specifies the type of action being performed.</li><li><strong>Dispatcher:</strong> The Dispatcher receives actions and dispatches them to registered callbacks. It acts as a central hub for managing all data flow in a Flux application.</li><li><strong>Stores:</strong> Stores contain the application state and logic. They register with the Dispatcher to receive actions and update their state accordingly. Stores emit change events to notify the views when their state changes.</li><li><strong>Views (React Components):</strong> Views are React components that receive data from stores and render the UI. When a store’s state changes, it triggers a re-render in the views.</li></ul><p>Flux enforces a unidirectional data flow, ensuring that the application state remains predictable and easy to understand. React components (views) subscribe to changes in stores, and when actions occur, they trigger updates in the stores, leading to re-renders in the views. This pattern simplifies state management, especially in large and complex applications.</p><p>React’s component architecture fits well with the Flux pattern, as React components can serve as the views in a Flux application. Libraries like Redux are implementations of the Flux pattern, providing a more structured and convenient way to manage application state in React applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62d96e5b3dd5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unravelling and Simplifying HOCs (Higher Order Components) in React ]]></title>
            <link>https://medium.com/@mujaffarhssn/unravelling-and-simplifying-hocs-higher-order-components-in-react-7ba3cf69d9e8?source=rss-b0714d8b8ace------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ba3cf69d9e8</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-js-tutorials]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[higher-order-components]]></category>
            <dc:creator><![CDATA[TechInsights]]></dc:creator>
            <pubDate>Thu, 21 Sep 2023 18:00:53 GMT</pubDate>
            <atom:updated>2023-09-21T18:00:53.627Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rtsXi0I_2qV0yf8h" /><figcaption>Photo by <a href="https://unsplash.com/@igorbumba?utm_source=medium&amp;utm_medium=referral">Igor Bumba</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In the world of React, mastering component composition and state management is key to building maintainable and efficient applications. One of the most powerful yet often misunderstood tools in the React developer’s toolkit is the Higher Order Component (HOC). In this comprehensive guide, we will explore Higher Order Components in-depth, using a practical example: counting bikes and cars in a parking lot. By the end of this journey, you’ll have a deep understanding of HOCs and how they can simplify state management in your React applications.</p><h3>The Power of Higher Order Components (HOCs)</h3><p>Before diving into our real-world example, let’s understand the concept of Higher Order Components (HOCs) more deeply. In React, components are the building blocks of your application. They encapsulate UI and logic into reusable pieces. However, as your app grows, you’ll often find yourself needing to share logic or state between components. This is where HOCs come into play.</p><p>HOCs are functions that take a component and return a new, enhanced component. They are not part of the React API but have become a widely-adopted pattern for creating reusable, shareable logic in your application.</p><h3>The Scenario: Counting Bikes and Cars</h3><p>To illustrate the power of HOCs, we’ll walk through a common scenario. Imagine you’re developing a parking lot management application. You have two separate components: one for counting bikes and another for counting cars. Both components require similar logic to manage and display counts. Instead of duplicating code, we’ll create a Counter HOC to handle this logic efficiently.</p><h3>Step 1: Creating the Counter HOC</h3><p>Let’s start by building the Counter HOC, which will provide the counter logic to any component that uses it. This HOC will leverage React hooks, specifically useState, to manage state.</p><pre>import React, { useState } from &#39;react&#39;;<br><br>const withCounter = (WrappedComponent) =&gt; {<br>  const CounterHOC = (props) =&gt; {<br>    const [count, setCount] = useState(0);<br>    const incrementCounter = () =&gt; {<br>      setCount(count + 1);<br>    };<br>    return (<br>      &lt;WrappedComponent<br>        count={count}<br>        incrementCounter={incrementCounter}<br>        {...props}<br>      /&gt;<br>    );<br>  };<br>  return CounterHOC;<br>};<br>export default withCounter;</pre><p>Here’s a breakdown of what’s happening:</p><ul><li>withCounter is a function that takes a WrappedComponent as its argument.</li><li>Inside CounterHOC, we utilize the useState hook to manage the count state.</li><li>We define an incrementCounter function to update the count.</li><li>Finally, we render the WrappedComponent and pass in the count, incrementCounter, and any other props.</li></ul><h3>Step 2: Creating the Bike and Car Components</h3><p>Now that our Counter HOC is ready, we can create components for counting bikes and cars by enhancing them with the Counter HOC. These components will be a breeze to create, thanks to the reusable logic provided by the HOC.</p><h4>BikeCounter.js</h4><pre>import React from &#39;react&#39;;<br>import withCounter from &#39;./withCounter&#39;;<br><br>const BikeCounter = ({ count, incrementCounter }) =&gt; {<br>  return (<br>    &lt;div&gt;<br>      &lt;h2&gt;Bike Count: {count}&lt;/h2&gt;<br>      &lt;button onClick={incrementCounter}&gt;Increment Bike&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>};<br>export default withCounter(BikeCounter);</pre><h4>CarCounter.js</h4><pre>import React from &#39;react&#39;;<br>import withCounter from &#39;./withCounter&#39;;<br><br>const CarCounter = ({ count, incrementCounter }) =&gt; {<br>  return (<br>    &lt;div&gt;<br>      &lt;h2&gt;Car Count: {count}&lt;/h2&gt;<br>      &lt;button onClick={incrementCounter}&gt;Increment Car&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>};<br>export default withCounter(CarCounter);</pre><p>These components are beautifully simple and focused on displaying the count and handling user interaction. The heavy lifting of managing the count state is abstracted away by the Counter HOC.</p><h3>Step 3: Using the Enhanced Components</h3><p>Now, let’s bring it all together by using the enhanced BikeCounter and CarCounter components in our main application.</p><h4>App.js</h4><pre>import React from &#39;react&#39;;<br>import BikeCounter from &#39;./BikeCounter&#39;;<br>import CarCounter from &#39;./CarCounter&#39;;<br><br>const App = () =&gt; {<br>  return (<br>    &lt;div&gt;<br>      &lt;BikeCounter /&gt;<br>      &lt;CarCounter /&gt;<br>    &lt;/div&gt;<br>  );<br>};<br>export default App;</pre><p>In our App component, we effortlessly incorporate the enhanced BikeCounter and CarCounter. Each instance of these components independently manages its count, thanks to the Counter HOC. There&#39;s no need for complex state management in our main application.</p><h3>Conclusion</h3><p>In this extensive guide, we’ve explored Higher Order Components (HOCs) in-depth. We’ve seen how HOCs can simplify state management and logic sharing in your React applications. By encapsulating the counter logic in a Counter HOC, we’ve achieved code reusability, maintainability, and clean separation of concerns. Armed with this knowledge, you’re ready to tackle more complex scenarios and leverage HOCs to enhance your React application development.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ba3cf69d9e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Classic React Interview Challenge: Initializing React App, Without create-react-app]]></title>
            <link>https://medium.com/@mujaffarhssn/the-classic-react-interview-challenge-initializing-react-app-without-create-react-app-78529966cafa?source=rss-b0714d8b8ace------2</link>
            <guid isPermaLink="false">https://medium.com/p/78529966cafa</guid>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[react-js-training]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[babel]]></category>
            <category><![CDATA[webpack]]></category>
            <dc:creator><![CDATA[TechInsights]]></dc:creator>
            <pubDate>Mon, 11 Sep 2023 05:51:41 GMT</pubDate>
            <atom:updated>2023-09-11T05:51:41.552Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yHsCyh9aJGKnXvrg" /><figcaption>Photo by <a href="https://unsplash.com/@walls_io?utm_source=medium&amp;utm_medium=referral">Walls.io</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In the realm of React interviews, there’s one question that’s achieved legendary status: “Can you initialize a React app without using create-react-app?&quot; It&#39;s a rite of passage for aspiring React developers, a test of your understanding of the core tools and concepts that power this popular JavaScript library. But fear not, because in this article, we&#39;re going to demystify this challenge and equip you with the skills to tackle it with confidence. So, fasten your seatbelts as we embark on a journey to initialize a React app like a pro, without relying on the familiar create-react-app wizardry. Let&#39;s dive in! 🚀</p><h3>Prerequisites</h3><p>Before we jump into the technical details, make sure you have Node.js and npm (Node Package Manager) installed on your system. If you’ve got those sorted, you’re ready to roll.</p><h3>Step 1: Project Setup</h3><p><em>1.1 Create a New Directory</em></p><p>Our journey begins with a single command that creates the canvas for your React masterpiece:</p><pre>mkdir my-react-app<br>cd my-react-app</pre><h3>Step 2: Installing React and ReactDOM</h3><p>The stars of our show are React and ReactDOM. Let’s give them the spotlight:</p><pre>npm install react react-dom</pre><h3>Step 3: Setting Up Babel</h3><p><em>Babel</em> is our trusty translator, ensuring our code speaks the language of all browsers.</p><h3>3.1 Install Babel Dependencies</h3><p>Commander Babel and its faithful troops:</p><pre>npm install @babel/core @babel/preset-env @babel/preset-react babel-loader --save-dev</pre><h3>3.2 Create a Babel Configuration</h3><p>Create a .babelrc file and outfit it with the babel presets:</p><pre>{<br>  &quot;presets&quot;: [&quot;@babel/preset-env&quot;, &quot;@babel/preset-react&quot;]<br>}</pre><h3>Step 4: Configuring Webpack</h3><p>Webpack, the formidable bundler, will assemble our troops and prepare them for battle.</p><h3>4.1 Install Webpack and Related Packages</h3><p>Arm your project with Webpack and its arsenal:</p><pre>npm install webpack webpack-cli webpack-dev-server html-webpack-plugin --save-dev</pre><h3>4.2 Create a Webpack Configuration</h3><p>Your Webpack general, the webpack.config.js file:</p><pre>const path = require(&#39;path&#39;);<br>const HtmlWebpackPlugin = require(&#39;html-webpack-plugin&#39;);<br><br>module.exports = {<br>  entry: &#39;./src/index.js&#39;,<br>  output: {<br>    path: path.resolve(__dirname, &#39;dist&#39;),<br>    filename: &#39;bundle.js&#39;,<br>  },<br>  module: {<br>    rules: [<br>      {<br>        test: /\.(js|jsx)$/,<br>        exclude: /node_modules/,<br>        use: [&#39;babel-loader&#39;],<br>      },<br>    ],<br>  },<br>  plugins: [<br>    new HtmlWebpackPlugin({<br>      template: &#39;./public/index.html&#39;,<br>    }),<br>  ],<br>  devServer: {<br>    contentBase: path.join(__dirname, &#39;public&#39;),<br>    port: 3000,<br>  },<br>};</pre><h3>Step 5: Creating a Basic React App</h3><p>With the infrastructure in place, it’s time to craft your React masterpiece!</p><h3>5.1 Create a src Directory</h3><p>Lay the foundation with a dedicated src directory:</p><pre>mkdir src</pre><h3>5.2 Create a React Component</h3><p>Introducing your star performer, App.js:</p><pre>// src/App.js<br>import React from &#39;react&#39;;<br><br>function App() {<br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Hello, React!&lt;/h1&gt;<br>    &lt;/div&gt;<br>  );<br>}<br>export default App;</pre><h3>5.3 Create an HTML Template</h3><p>Your stage, the index.html file:</p><pre>&lt;!-- public/index.html --&gt;<br>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>  &lt;meta charset=&quot;UTF-8&quot;&gt;<br>  &lt;title&gt;React App&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><h3>5.4 Entry Point</h3><p>And now, the conductor of this symphony, index.js:</p><pre>// src/index.js<br>import React from &#39;react&#39;;<br>import ReactDOM from &#39;react-dom&#39;;<br>import App from &#39;./App&#39;;<br><br>ReactDOM.render(&lt;App /&gt;, document.getElementById(&#39;root&#39;));</pre><h3>Step 6: Running Your React App</h3><p>The moment has arrived. To witness your creation come to life, issue the command:</p><pre>npm start</pre><p>Your React app will rise from the ashes, ready to shine brightly at <a href="http://localhost:3000.">http://localhost:3000.</a></p><h3>Conclusion</h3><p>Mastering the art of initializing a React app without create-react-app is a badge of honor for any React developer. Armed with this knowledge, you can customize your projects, gain a deeper understanding of React&#39;s internals, and impress your future interviewers. Remember, the React world is your canvas, and you are the artist. Happy coding! 🎨🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78529966cafa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding useMemo vs. useCallback in React: A Simple Guide with Code Examples]]></title>
            <link>https://medium.com/@mujaffarhssn/understanding-usememo-vs-usecallback-in-react-a-simple-guide-with-code-examples-290e1bd72737?source=rss-b0714d8b8ace------2</link>
            <guid isPermaLink="false">https://medium.com/p/290e1bd72737</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[usecallback]]></category>
            <category><![CDATA[react-hook-usememo]]></category>
            <dc:creator><![CDATA[TechInsights]]></dc:creator>
            <pubDate>Sun, 10 Sep 2023 18:37:49 GMT</pubDate>
            <atom:updated>2023-09-10T18:37:49.740Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QxYqA3aqfYIebHSI" /><figcaption>Photo by <a href="https://unsplash.com/@brett_jordan?utm_source=medium&amp;utm_medium=referral">Brett Jordan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>React is a popular JavaScript library for building user interfaces, and it provides developers with a variety of tools to optimize the performance of their applications. Two of these tools are useMemo and useCallback, which help prevent unnecessary re-renders in your components. In this article, we&#39;ll explore what these hooks do, how they differ, and when to use each one with straightforward code examples.</p><h3>What is useMemo?</h3><p>useMemo is a React hook used to memoize (or cache) the result of a computation. It takes two arguments: a function and an array of dependencies. The function contains the computation you want to memoize, and the array of dependencies lists the values that, when changed, trigger the re-computation.</p><p>Here’s a simple example:</p><pre>import React, { useMemo, useState } from &#39;react&#39;;<br><br>function App() {<br>  const [count, setCount] = useState(0);<br>  const squaredValue = useMemo(() =&gt; {<br>    return count * count;<br>  }, [count]);<br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Count: {count}&lt;/p&gt;<br>      &lt;p&gt;Squared Value: {squaredValue}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Increment&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}<br>export default App;</pre><p>In this example, squaredValue is computed using useMemo. The computation (squaring count) will only occur when count changes. If you click the &quot;Increment&quot; button, count changes, and squaredValue is recalculated.</p><h3>What is useCallback?</h3><p>useCallback is another React hook that memoizes functions. It is especially useful when you need to pass functions as props to child components. Like useMemo, it takes a function and an array of dependencies, but it returns a memoized version of the function rather than a value.</p><p>Here’s an example of how useCallback can be used:</p><pre>import React, { useCallback, useState } from &#39;react&#39;;<br><br>function ChildComponent({ handleClick }) {<br>  return &lt;button onClick={handleClick}&gt;Click Me&lt;/button&gt;;<br>}<br>function App() {<br>  const [count, setCount] = useState(0);<br>  const handleClick = useCallback(() =&gt; {<br>    setCount(count + 1);<br>  }, [count]);<br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Count: {count}&lt;/p&gt;<br>      &lt;ChildComponent handleClick={handleClick} /&gt;<br>    &lt;/div&gt;<br>  );<br>}<br>export default App;</pre><p>In this example, the handleClick function is memoized using useCallback. This ensures that the handleClick function doesn&#39;t change unless the count dependency changes, preventing unnecessary re-renders of the ChildComponent.</p><h3>When to use useMemo and useCallback?</h3><ul><li>useMemo: Use it when you want to memoize a value that is derived from other data and you don&#39;t want it to recalculate on every render. This is helpful for optimizing expensive calculations or preventing unnecessary rendering of components.</li><li>useCallback: Use it when you want to memoize a function, especially if that function is passed as a prop to child components. It ensures that the function reference remains stable between renders, preventing child components from re-rendering when the parent re-renders.</li></ul><p>In summary, useMemo is for memoizing values, while useCallback is for memoizing functions. Both hooks are essential tools for optimizing your React applications and improving performance by minimizing unnecessary re-renders. By understanding when and how to use them, you can make your React components more efficient and responsive.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=290e1bd72737" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>