<?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 Rahul Jain on Medium]]></title>
        <description><![CDATA[Stories by Rahul Jain on Medium]]></description>
        <link>https://medium.com/@rahuljain-dev?source=rss-e7c9b5635bbf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LLnwzeTnM2OCBIcQpo8tgQ.png</url>
            <title>Stories by Rahul Jain on Medium</title>
            <link>https://medium.com/@rahuljain-dev?source=rss-e7c9b5635bbf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 20:54:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rahuljain-dev/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[Shadow DOM: The Frontend Superpower Most Developers Never Learn]]></title>
            <link>https://rahuljain-dev.medium.com/shadow-dom-the-frontend-superpower-most-developers-never-learn-04fe1c609600?source=rss-e7c9b5635bbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/04fe1c609600</guid>
            <category><![CDATA[dom]]></category>
            <category><![CDATA[shadow-dom]]></category>
            <dc:creator><![CDATA[Rahul Jain]]></dc:creator>
            <pubDate>Wed, 24 Jun 2026 14:08:47 GMT</pubDate>
            <atom:updated>2026-06-24T14:08:47.146Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DvK2aq-Oxiiwo5yaTaZWlg.png" /></figure><h3>Understanding the Hidden Side of the Web</h3><p>When building modern web applications, you’ve probably heard terms like <strong>DOM</strong>, <strong>Virtual DOM</strong>, and <strong>Shadow DOM</strong>. While most developers interact with the DOM daily, Shadow DOM often feels mysterious and is frequently misunderstood.</p><p>In this article, we’ll explore what the DOM is, the different types of DOM-related concepts used in modern web development, and take a deep dive into Shadow DOM with practical examples.</p><h3>What Is the DOM?</h3><p>DOM stands for <strong>Document Object Model</strong>.</p><p>When a browser loads an HTML document, it converts the HTML into a tree-like structure that JavaScript can interact with.</p><p>Consider this HTML:</p><pre>&lt;body&gt;<br>  &lt;h1&gt;Hello World&lt;/h1&gt;<br>  &lt;button&gt;Click Me&lt;/button&gt;<br>&lt;/body&gt;</pre><p>The browser creates a structure like:</p><pre>Document<br> └── Body<br>      ├── H1<br>      │    └── &quot;Hello World&quot;<br>      └── Button<br>           └── &quot;Click Me&quot;</pre><p>This structure is called the DOM Tree.</p><p>Using JavaScript, we can access and modify elements:</p><pre>document.querySelector(&quot;h1&quot;).textContent = &quot;Welcome!&quot;;</pre><p>The browser updates the page instantly.</p><h3>Types of DOM Developers Should Know</h3><p>Although “DOM” is commonly used as a single term, modern web development involves several DOM-related concepts.</p><h3>1. Real DOM</h3><p>The Real DOM is the actual browser representation of your webpage.</p><p>Characteristics:</p><ul><li>Directly rendered by the browser</li><li>Updates affect the UI immediately</li><li>Every change triggers rendering work</li></ul><p>Example:</p><pre>const heading = document.querySelector(&quot;h1&quot;);<br>heading.textContent = &quot;Updated&quot;;</pre><p>Advantages:</p><ul><li>Native browser implementation</li><li>Easy to understand</li></ul><p>Disadvantages:</p><ul><li>Frequent updates can become expensive</li><li>Large applications may suffer performance issues</li></ul><h3>2. Virtual DOM</h3><p>Popularized by React.</p><p>The Virtual DOM is a lightweight JavaScript copy of the Real DOM.</p><p>Instead of updating the browser DOM directly:</p><ol><li>React updates the Virtual DOM.</li><li>Compares old and new versions.</li><li>Calculates differences.</li><li>Updates only changed parts of the Real DOM.</li></ol><p>Visualization:</p><pre>State Change<br>      ↓<br>Virtual DOM Update<br>      ↓<br>Diffing Algorithm<br>      ↓<br>Real DOM Update</pre><p>Benefits:</p><ul><li>Better performance</li><li>Efficient rendering</li><li>Improved developer experience</li></ul><p>Frameworks using Virtual DOM:</p><ul><li>React</li><li>Preact</li><li>Inferno</li></ul><h3>3. Shadow DOM</h3><p>This is where things get interesting.</p><p>Shadow DOM provides encapsulation for HTML, CSS, and JavaScript.</p><p>It allows a component to have its own isolated DOM tree that is separate from the main document.</p><p>Think of it as a mini webpage living inside another webpage.</p><h3>Why Was Shadow DOM Created?</h3><p>Imagine building a reusable button component.</p><p>CSS:</p><pre>button {<br>  color: red;<br>}</pre><p>Another developer writes:</p><pre>button {<br>  color: blue;<br>}</pre><p>Now styles conflict.</p><p>As applications grow, CSS collisions become a nightmare.</p><p>Shadow DOM solves this problem by creating a protected scope.</p><h3>How Shadow DOM Works</h3><p>A Shadow DOM is attached to an element known as the <strong>Shadow Host</strong>.</p><p>Example:</p><pre>&lt;div id=&quot;myComponent&quot;&gt;&lt;/div&gt;</pre><p>JavaScript:</p><pre>const host = document.getElementById(&quot;myComponent&quot;);</pre><pre>const shadowRoot = host.attachShadow({<br>  mode: &quot;open&quot;<br>});</pre><pre>shadowRoot.innerHTML = `<br>  &lt;style&gt;<br>    p {<br>      color: green;<br>    }<br>  &lt;/style&gt;</pre><pre>  &lt;p&gt;Hello from Shadow DOM&lt;/p&gt;<br>`;</pre><p>Result:</p><pre>Document DOM<br> └── div#myComponent<br>        └── Shadow Root<br>              └── p</pre><p>The paragraph exists inside its own isolated environment.</p><h3>Shadow Host</h3><p>The element that owns the Shadow DOM.</p><p>Example:</p><pre>&lt;div id=&quot;widget&quot;&gt;&lt;/div&gt;</pre><p>Here:</p><pre>const host = document.getElementById(&quot;widget&quot;);</pre><p>The div acts as the Shadow Host.</p><h3>Shadow Root</h3><p>The root node of the Shadow DOM.</p><p>Created using:</p><pre>host.attachShadow({ mode: &quot;open&quot; });</pre><p>Everything inside this root remains encapsulated.</p><h3>Open vs Closed Shadow DOM</h3><p>There are two modes.</p><h3>Open Mode</h3><pre>host.attachShadow({<br>  mode: &quot;open&quot;<br>});</pre><p>Allows external JavaScript access.</p><pre>host.shadowRoot</pre><p>returns the Shadow Root.</p><h3>Closed Mode</h3><pre>host.attachShadow({<br>  mode: &quot;closed&quot;<br>});</pre><p>External scripts cannot access:</p><pre>host.shadowRoot</pre><p>returns:</p><pre>null</pre><p>Useful for stronger encapsulation.</p><h3>Style Isolation</h3><p>One of Shadow DOM’s biggest advantages.</p><p>Inside Shadow DOM:</p><pre>p {<br>  color: green;<br>}</pre><p>Outside:</p><pre>p {<br>  color: red;<br>}</pre><p>The styles do not interfere with each other.</p><p>This makes components highly reusable.</p><h3>Slots in Shadow DOM</h3><p>Sometimes we want users to inject content.</p><p>Shadow DOM provides &lt;slot&gt;.</p><p>Component:</p><pre>&lt;my-card&gt;<br>  &lt;h2&gt;My Title&lt;/h2&gt;<br>&lt;/my-card&gt;</pre><p>Shadow Template:</p><pre>&lt;div class=&quot;card&quot;&gt;<br>  &lt;slot&gt;&lt;/slot&gt;<br>&lt;/div&gt;</pre><p>Output:</p><pre>&lt;div class=&quot;card&quot;&gt;<br>  &lt;h2&gt;My Title&lt;/h2&gt;<br>&lt;/div&gt;</pre><p>Slots allow flexibility while maintaining encapsulation.</p><h3>Shadow DOM and Web Components</h3><p>Shadow DOM is a key pillar of Web Components.</p><p>Web Components consist of:</p><h3>Custom Elements</h3><pre>&lt;user-profile&gt;&lt;/user-profile&gt;</pre><h3>Shadow DOM</h3><p>Provides encapsulation.</p><h3>HTML Templates</h3><p>Reusable markup structures.</p><p>Together they allow developers to create framework-independent UI components.</p><h3>Real-World Examples</h3><p>Many browser elements already use Shadow DOM internally.</p><p>Examples:</p><ul><li>Video player controls</li><li>Input elements</li><li>Date pickers</li><li>Select dropdowns</li></ul><p>Even though you see them on the page, their internal implementation is protected.</p><h3>Benefits of Shadow DOM</h3><h3>Encapsulation</h3><p>Prevents style and markup conflicts.</p><h3>Reusability</h3><p>Components can be dropped into any application.</p><h3>Maintainability</h3><p>Large applications become easier to manage.</p><h3>Framework Independence</h3><p>Works with:</p><ul><li>Vanilla JavaScript</li><li>React</li><li>Angular</li><li>Vue</li><li>Lit</li></ul><h3>Limitations of Shadow DOM</h3><h3>Debugging Complexity</h3><p>Nested shadow trees can be harder to inspect.</p><h3>SEO Considerations</h3><p>Search engine support has improved, but rendering behavior should still be validated.</p><h3>Global Styling Restrictions</h3><p>Framework-wide styles don’t automatically penetrate Shadow DOM.</p><p>Additional strategies may be required.</p><h3>DOM vs Virtual DOM vs Shadow DOM</h3><p>FeatureReal DOMVirtual DOMShadow DOMBrowser RepresentationYesNoPartialImproves Rendering PerformanceNoYesNoStyle IsolationNoNoYesComponent EncapsulationNoNoYesUsed ByBrowserReactWeb Components</p><p>A common misconception is that Virtual DOM and Shadow DOM solve the same problem.</p><p>They don’t.</p><p><strong>Virtual DOM optimizes updates.</strong></p><p><strong>Shadow DOM isolates components.</strong></p><p>These technologies can even work together.</p><h3>When Should You Use Shadow DOM?</h3><p>Use Shadow DOM when:</p><ul><li>Building reusable UI libraries</li><li>Creating design systems</li><li>Developing widgets for third-party websites</li><li>Building Web Components</li><li>Preventing CSS leakage</li></ul><p>Avoid it when:</p><ul><li>Global styling is essential</li><li>Simplicity matters more than encapsulation</li><li>Team members are unfamiliar with Web Components</li></ul><h3>Key Takeaways</h3><p>✅ The DOM (Document Object Model) is the browser’s representation of your HTML document and allows JavaScript to manipulate page content.</p><p>✅ The Real DOM directly reflects what’s rendered in the browser, but frequent updates can become expensive in large applications.</p><p>✅ The Virtual DOM improves performance by comparing changes and updating only the necessary parts of the Real DOM.</p><p>✅ Shadow DOM solves a different problem — it provides encapsulation and style isolation for reusable components.</p><p>✅ Shadow DOM prevents CSS conflicts by creating a protected scope for HTML, CSS, and JavaScript.</p><p>✅ Web Components rely heavily on Shadow DOM to build framework-independent, reusable UI elements.</p><p>✅ Virtual DOM and Shadow DOM are not competitors — they solve different challenges and can work together.</p><p>✅ Understanding Shadow DOM is becoming increasingly important as modern frontend development moves toward reusable and scalable component architectures.</p><h3>Final Thoughts</h3><p>The DOM is the foundation of every web application, but modern development requires understanding the tools built around it.</p><p>While Virtual DOM helps optimize rendering performance, Shadow DOM empowers developers to build isolated, reusable, and maintainable components that scale across projects and teams.</p><p>As Web Components continue gaining adoption, Shadow DOM is no longer just a niche browser feature — it’s becoming an essential skill for frontend developers.</p><h3>What’s Your Experience?</h3><p>Have you worked with Shadow DOM or Web Components in production?</p><p>Do you think component encapsulation is worth the added complexity, or do traditional CSS approaches still work best for your projects?</p><p>Share your thoughts in the comments — I’d love to hear how your team approaches component architecture and styling challenges.</p><p>If this guide helped, follow me for more deep dives into JavaScript, Web Components, React, browser internals, and modern frontend engineering. 🚀</p><p>#JavaScript #WebDevelopment #FrontendDevelopment #ShadowDOM #WebComponents #DOM #VirtualDOM #ReactJS #Programming #SoftwareEngineering</p><h3>About the Author</h3><p><a href="https://rahuljain.dev/"><strong>Rahul Jain</strong> </a>is a frontend developer passionate about modern web technologies, open source, clean code, and building exceptional user experiences.</p><p>He regularly writes about JavaScript, React, Web Components, browser APIs, frontend architecture, and emerging web platform features.</p><p>Connect with him on <a href="https://github.com/rahuljaim">GitHub </a>and <a href="https://www.linkedin.com/in/rahuljain-dev/">LinkedIn </a>to follow his latest articles and projects.</p><p>This article was written for developers who want to deepen their understanding of how modern web applications work under the hood.</p><p>If you enjoyed reading it, please clap 👏, share it with fellow developers, and help spread knowledge within the developer community.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=04fe1c609600" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building GitHub Profile Forge: A Premium Open-Source Developer Dashboard]]></title>
            <link>https://medium.com/skillstuff/building-github-profile-forge-a-premium-open-source-developer-dashboard-bb2aff6cb66a?source=rss-e7c9b5635bbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb2aff6cb66a</guid>
            <category><![CDATA[github-profile-readme]]></category>
            <category><![CDATA[github-profile]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[profile]]></category>
            <dc:creator><![CDATA[Rahul Jain]]></dc:creator>
            <pubDate>Fri, 19 Jun 2026 16:48:42 GMT</pubDate>
            <atom:updated>2026-06-24T13:43:10.743Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q54hWBuQO9XR77JGZ7xIww.png" /></figure><p>A journey from idea to a fully-featured dashboard that helps developers showcase their work beautifully</p><h3>Introduction</h3><p>Every developer knows the importance of a strong GitHub presence. It’s often the first thing recruiters check, the portfolio that speaks louder than words, and the proof of your craft that goes beyond a resume. Yet, most GitHub profiles look the same — a list of repositories, some stats, and perhaps a README.</p><p>I wanted to change that. I wanted to give developers a way to turn their GitHub profile into something visually stunning, interactive, and truly representative of their coding journey. That’s how GitHub Profile Forge was born.</p><p>This article is the story of building it — the technical choices, the challenges, and the lessons learned along the way.</p><h3>The Problem: Static Profiles Need a Refresh</h3><p>When you look at a typical GitHub profile, you see:</p><ul><li>A list of repositories</li><li>A few basic stats (followers, stars)</li><li>Maybe a pinned README</li></ul><p>But your coding journey is so much more than that. It’s the languages you’ve mastered, the patterns in your contributions, the projects you’re most proud of, and the community you’ve built. A static list doesn’t tell that story.</p><p>Existing tools like basic README generators help, but they still produce text-heavy outputs that lack visual appeal. I wanted to create something that would make developers think: <em>“Wow, this is MY story!”</em></p><h3>The Vision: A Dashboard, Not Just a Page</h3><p>My goal was to build a premium, interactive dashboard that would:</p><ol><li>Showcase real-time GitHub data in a beautiful way</li><li>Provide meaningful visualizations that tell a story about the developer</li><li>Be fully customizable with drag-and-drop functionality</li><li>Export cleanly to Markdown for READMEs or PNG for social sharing</li><li>Be 100% open source under Apache 2.0</li></ol><p>I wanted developers to be able to enter any GitHub username and instantly see a professional-grade dashboard they’d be proud to share.</p><h3>Technical Architecture: Keeping It Simple and Powerful</h3><h3>The Stack</h3><p>I chose to keep the tech stack intentionally simple and accessible:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*6F0Cvq8O0L8ehZgvd0kZ2w.png" /></figure><p>The decision to use vanilla JavaScript rather than a framework like React or Next.js was deliberate. It keeps the project accessible to developers of all skill levels, reduces dependencies, and ensures fast load times. As other developers have shown with similar projects, you can build powerful GitHub dashboards with just HTML, CSS, and JavaScript.</p><h3>GitHub API Integration</h3><p>The dashboard fetches data from multiple GitHub REST API endpoints :</p><pre>// Core API calls<br>GET /users/{username}<br>GET /users/{username}/repos<br>GET /users/{username}/events/public</pre><p>Each call is carefully handled with error management and rate-limit awareness. For a production version, adding a GitHub Personal Access Token would significantly increase rate limits from 60 to 5,000 requests per hour.</p><h3>Key Features That Make It Special</h3><h3>1. Real-Time GitHub Statistics</h3><p>The dashboard displays six key metrics that give a comprehensive overview of a developer’s activity:</p><ul><li>Total Forks — Community engagement with your projects</li><li>Stars Earned — Popularity and appreciation</li><li>PRs Merged — Collaboration and contribution</li><li>Repositories — Breadth of work</li><li>Contributors — Team impact</li><li>Commits — Active coding time</li></ul><p>These aren’t just numbers — they’re the story of your developer journey.</p><h3>2. Interactive Data Visualizations</h3><p>Charts make data digestible at a glance :</p><ul><li>Language Distribution (Doughnut Chart) — See your tech stack at a glance</li><li>Contribution Heatmap (Bar Chart) — Understand your coding patterns</li><li>Code Frequency (Line Chart) — When do you code most?</li></ul><h3>3. Pinned Repositories</h3><p>Your best work deserves prominence. The dashboard automatically surfaces your top repositories by stars, showing:</p><ul><li>Repository name and description</li><li>Primary language with color coding</li><li>Star and fork counts</li></ul><p>This feature aligns perfectly with the advice to “pin your best projects to the top of your GitHub profile” .</p><h3>4. Drag-and-Drop Customization</h3><p>Not everyone wants the same stats in the same order. The drag-and-drop functionality lets users rearrange their dashboard to prioritize what matters most to them.</p><h3>5. Export Capabilities</h3><ul><li>Markdown Export — Generate a beautiful README.md with visual badges and structured sections</li><li>PNG Export — Capture the dashboard as a high-resolution image for social sharing</li></ul><h3>6. Dark/Light Theme</h3><p>A seamless theme switcher using CSS variables makes the dashboard comfortable to view in any lighting condition .</p><h3>7. Animated Star &amp; Fork Promo</h3><p>Two animated buttons at the top encourage visitors to star and fork the repository, with real-time count updates from the GitHub API and a fun celebration animation on click.</p><h3>8. Social Sharing</h3><p>Direct sharing to Twitter, LinkedIn, WhatsApp, and Reddit makes it easy for developers to showcase their dashboard.</p><h3>9. Wakatime Integration</h3><p>Simulated coding activity metrics (hours coded, projects, languages, average daily hours) provide a complete picture of developer productivity. This is ready for real Wakatime API integration.</p><h3>10. Recent Activity Feed</h3><p>A live feed of the user’s latest GitHub events (pushes, PRs, issues, stars) makes the profile feel alive and current.</p><h3>Design Philosophy: Developer-First Experience</h3><h3>Visual Design</h3><p>I drew inspiration from GitHub’s dark theme and modern dashboard designs :</p><ul><li>Color Palette: #0d1117 (dark background), #58a6ff (accent blue), #2ea043 (accent green), #f1c40f (gold for stars)</li><li>Typography: Inter font for clean, readable text</li><li>Card-based layout: Clear visual hierarchy</li><li>Subtle animations: Smooth transitions that feel premium</li></ul><h3>Responsive Design</h3><p>The dashboard works on all devices, from desktop to mobile. Statistics cards reflow gracefully, charts resize, and navigation adapts.</p><h3>Accessibility</h3><p>ARIA labels, semantic HTML, and proper contrast ratios ensure the dashboard is usable by everyone.</p><h3>The Development Journey: Challenges and Solutions</h3><h3>Challenge 1: Rate Limits</h3><p>GitHub API has rate limits . For public profiles without authentication, you get 60 requests per hour. <br><strong>Solution</strong>: Implement caching and consider adding a token option for users.</p><h3>Challenge 2: Chart Responsiveness</h3><p>Charts needed to look good on all screen sizes. Using Chart.js responsive configuration and proper container sizing solved this.</p><h3>Challenge 3: PNG Export Quality</h3><p>html2canvas required careful configuration to produce high-quality screenshots with proper colors and fonts.</p><h3>Challenge 4: Drag-and-Drop</h3><p>Implementing smooth drag-and-drop with vanilla JavaScript required careful event handling and state management.</p><h3>Challenge 5: Theme Switching</h3><p>CSS variables made theme switching elegant, but chart colors needed to update dynamically when the theme changed.</p><h3>Open Source and Community</h3><p>GitHub Profile Forge is Apache 2.0 licensed with a complete Code of Conduct and Contributing Guide. I believe great software is built by communities, not individuals.</p><h3>How to Contribute</h3><ol><li>Fork the repository</li><li>Create a feature branch</li><li>Make your changes</li><li>Submit a pull request</li></ol><p>The project welcomes contributions of all kinds — bug reports, feature suggestions, documentation improvements, and code contributions.</p><h3>What I Learned</h3><p>Building this project taught me several valuable lessons:</p><ol><li>Start with the user experience — Every feature should serve a real need for developers</li><li>Keep it accessible — Vanilla JavaScript and simple tech stacks invite more contributions</li><li>Visuals matter — Developers are visual people; beautiful design earns trust</li><li>Open source is about community — Documentation and contribution guidelines are as important as code</li><li>Small details make a difference — Animations, tooltips, and responsive design show care</li></ol><h3>Future Roadmap</h3><p>The project is already feature-rich, but there’s always more to build:</p><ul><li>Real Wakatime API integration — Replace simulated data with actual Wakatime stats</li><li>GitHub Actions workflow — Auto-update profiles daily</li><li>Additional charts — Radar charts, polar area charts for different views</li><li>More export options — PDF, social media cards</li><li>Browser extension — Quick access to the dashboard</li></ul><h3>Try It Yourself</h3><p>GitHub Profile Forge is live and ready for you to try:</p><ul><li>Live Demo: <a href="https://rahuljaim.github.io/github-readme-profile-generator-forge/">https://rahuljaim.github.io/github-readme-profile-generator-forge/</a></li><li>GitHub Repo: <a href="https://github.com/rahuljaim/github-readme-profile-generator-forge">https://github.com/rahuljaim/github-readme-profile-generator-forge</a></li></ul><p>Enter any GitHub username and see your profile transformed!</p><h3>Final Thoughts</h3><p>Building GitHub Profile Forge was more than just a coding exercise. It was about creating a tool that helps developers tell their story — visually, dynamically, and beautifully. Your GitHub profile is your developer identity, and it deserves to shine.</p><p>I encourage you to try the dashboard, star the repository, contribute to the project, and most importantly, build your own tools that serve the developer community.</p><p>The best open source projects start with one person solving their own problem and sharing the solution with the world.</p><p>About the Author</p><p>Rahul Jain is a frontend developer passionate about open source, clean code, and beautiful user experiences. Connect with him on <a href="https://github.com/rahuljaim">GitHub</a> or <a href="https://www.linkedin.com/in/rahuljain-dev/">LinkedIn</a>.</p><p><em>This article was originally published for all developers. If you enjoyed it, please clap 👏 and share it with other developers!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb2aff6cb66a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/skillstuff/building-github-profile-forge-a-premium-open-source-developer-dashboard-bb2aff6cb66a">Building GitHub Profile Forge: A Premium Open-Source Developer Dashboard</a> was originally published in <a href="https://medium.com/skillstuff">Skill Stuff</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Class Components vs. Functional Components + Old vs. New Redux: The Complete Guide (2026)]]></title>
            <link>https://medium.com/skillstuff/react-class-components-vs-functional-components-old-vs-new-redux-the-complete-guide-2026-038762efa419?source=rss-e7c9b5635bbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/038762efa419</guid>
            <category><![CDATA[redux-toolkit]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Rahul Jain]]></dc:creator>
            <pubDate>Wed, 17 Jun 2026 05:22:31 GMT</pubDate>
            <atom:updated>2026-06-17T05:22:31.676Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8XAnWMFac1UdWxg7df6Zng.png" /></figure><p>When I first started with React, I was confused by two things: Should I use class components or functional components? And why does Redux look so different in 2026 compared to the tutorials from 2018?</p><p>This guide breaks down everything you need to know — class vs. functional components, and the evolution from old Redux (with connect and mapStateToProps) to modern Redux (with Hooks like useSelector and useDispatch).</p><p>Let’s dive in.</p><h3>Part 1: Class Components vs. Functional Components</h3><h3>What Are Class Components?</h3><p>Class components were the <strong>original way</strong> to write React components before React 16.8 (2019). They use JavaScript classes and have their own lifecycle methods.</p><pre>// Class Component (Old Way)<br>import React, { Component } from &#39;react&#39;;<br><br>class Counter extends Component {<br>  constructor(props) {<br>    super(props);<br>    this.state = {<br>      count: 0<br>    };<br>  }<br><br>  increment = () =&gt; {<br>    this.setState({ count: this.state.count + 1 });<br>  };<br><br>  componentDidMount() {<br>    console.log(&#39;Component mounted!&#39;);<br>  }<br><br>  render() {<br>    return (<br>      &lt;div&gt;<br>        &lt;p&gt;Count: {this.state.count}&lt;/p&gt;<br>        &lt;button onClick={this.increment}&gt;Increment&lt;/button&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}<br><br>export default Counter;</pre><h3>Key Characteristics of Class Components:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*dfkCI1O0fcbFzmi63wl6dQ.png" /></figure><h3>What Are Functional Components?</h3><p>Functional components are <strong>modern React</strong> (introduced officially with React 16.8 + Hooks in 2019). They are simpler, cleaner, and support all React features including Hooks.</p><pre>// Functional Component (Modern Way)<br>import React, { useState, useEffect } from &#39;react&#39;;<br><br>const Counter = () =&gt; {<br>  const [count, setCount] = useState(0);<br><br>  const increment = () =&gt; {<br>    setCount(count + 1);<br>  };<br><br>  useEffect(() =&gt; {<br>    console.log(&#39;Component mounted!&#39;);<br>  }, []);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Count: {count}&lt;/p&gt;<br>      &lt;button onClick={increment}&gt;Increment&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>};<br><br>export default Counter;</pre><h3>Key Characteristics of Functional Components:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*xINlTlG0obey4ECkBdoTGw.png" /></figure><h3>Side-by-Side Comparison</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*Rmd9QjgU7T_zIUNFUsUiqA.png" /></figure><h3>Why Functional Components Are Better (2026 Standard)</h3><ol><li><strong>Simpler Syntax</strong> — No this, no super(), no method binding</li><li><strong>Hooks Power</strong> — Reusable state logic with useEffect, useContext, useReducer</li><li><strong>Better Performance</strong> — React optimizes functional components more efficiently</li><li><strong>Testable</strong> — Pure functions are easier to test than class instances</li><li><strong>Community Standard</strong> — 95% of new React code is functional (2026 trend)</li></ol><p><strong>Bottom line:</strong> Start with functional components. Learn class components only if you’re maintaining legacy code.</p><h3>Part 2: Old Redux vs. New Redux (With Hooks)</h3><p>Redux has evolved dramatically. Here’s what changed:</p><h3>Old Redux (Pre-2019)</h3><p>Before React Hooks, Redux used the connect() Higher-Order Component (HOC) pattern.</p><pre>// OLD REDUX: Using connect() and mapStateToProps<br>import React, { Component } from &#39;react&#39;;<br>import { connect } from &#39;redux/react&#39;;<br><br>class Counter extends Component {<br>  increment = () =&gt; {<br>    this.props.dispatch({ type: &#39;INCREMENT&#39; });<br>  };<br><br>  render() {<br>    return (<br>      &lt;div&gt;<br>        &lt;p&gt;Count: {this.props.count}&lt;/p&gt;<br>        &lt;button onClick={this.increment}&gt;Increment&lt;/button&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}<br><br>// mapStateToProps: Extract data from Redux state<br>const mapStateToProps = (state) =&gt; {<br>  return {<br>    count: state.counter.count<br>  };<br>};<br><br>// mapDispatchToProps: Connect dispatch actions<br>const mapDispatchToProps = (dispatch) =&gt; {<br>  return {<br>    dispatch<br>  };<br>};<br><br>// Wrap component with connect()<br>export default connect(mapStateToProps, mapDispatchToProps)(Counter);</pre><h3>Problems with Old Redux:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*hshanMOpao4RtogGcTWHEA.png" /></figure><h3>New Redux (2019+ with Hooks)</h3><p>Redux now supports React Hooks (useSelector, useDispatch). This is the <strong>modern standard</strong> (Redux Toolkit + Hooks).</p><pre>// NEW REDUX: Using Hooks (useSelector + useDispatch)<br>import React from &#39;react&#39;;<br>import { useSelector, useDispatch } from &#39;react-redux&#39;;<br>import { increment } from &#39;./counterSlice&#39;;<br><br>const Counter = () =&gt; {<br>  const count = useSelector((state) =&gt; state.counter.count);<br>  const dispatch = useDispatch();<br><br>  const handleIncrement = () =&gt; {<br>    dispatch(increment());<br>  };<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Count: {count}&lt;/p&gt;<br>      &lt;button onClick={handleIncrement}&gt;Increment&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>};<br><br>export default Counter;</pre><h3>Benefits of New Redux:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*JftV3t0uY9ogo9RijJxKGg.png" /></figure><h3>Side-by-Side Redux Comparison</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*9ij43xxKRWUU3DKiQ2eolg.png" /></figure><h3>Modern Redux Toolkit (2026 Best Practice)</h3><p>Redux Toolkit is the <strong>official recommended way</strong> to write Redux. It simplifies store setup, reducers, and actions.</p><pre>// 1. Create Redux Store with Redux Toolkit (store.js)<br>import { configureStore, createSlice } from &#39;@reduxjs/toolkit&#39;;<br><br>const counterSlice = createSlice({<br>  name: &#39;counter&#39;,<br>  initialState: { count: 0 },<br>  reducers: {<br>    increment: (state) =&gt; {<br>      state.count += 1;<br>    },<br>    decrement: (state) =&gt; {<br>      state.count -= 1;<br>    }<br>  }<br>});<br><br>export const { increment, decrement } = counterSlice.actions;<br><br>export const store = configureStore({<br>  reducer: {<br>    counter: counterSlice.reducer<br>  }<br>});</pre><pre>// 2. Wrap App with Provider (App.js)<br>import React from &#39;react&#39;;<br>import { Provider } from &#39;react-redux&#39;;<br>import { store } from &#39;./store&#39;;<br>import Counter from &#39;./Counter&#39;;<br><br>const App = () =&gt; {<br>  return (<br>    &lt;Provider store={store}&gt;<br>      &lt;Counter /&gt;<br>    &lt;/Provider&gt;<br>  );<br>};<br><br>export default App;</pre><pre>// 3. Use in Component (Counter.js)<br>import React from &#39;react&#39;;<br>import { useSelector, useDispatch } from &#39;react-redux&#39;;<br>import { increment, decrement } from &#39;./store&#39;;<br>const Counter = () =&gt; {<br>  const count = useSelector((state) =&gt; state.counter.count);<br>  const dispatch = useDispatch();<br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Count: {count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; dispatch(increment())}&gt;+&lt;/button&gt;<br>      &lt;button onClick={() =&gt; dispatch(decrement())}&gt;-&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>};<br>export default Counter;</pre><p><strong>Why Redux Toolkit?</strong></p><p>✅ Auto-generates action creators<br>✅ Reducer logic is cleaner (no return { ...state } boilerplate)<br>✅ Built-in devtools support<br>✅ TypeScript-friendly<br>✅ Officially recommended by Redux team (2026)</p><h3>Part 3: Complete Migration Guide (Old → New)</h3><h3>If You Have Legacy Code (Class + connect), Migrate to Modern:</h3><pre>// BEFORE (Old Class + connect)<br>import React, { Component } from &#39;react&#39;;<br>import { connect } from &#39;redux/react&#39;;<br><br>class UserProfile extends Component {<br>  componentDidMount() {<br>    this.props.fetchUser(this.props.userId);<br>  }<br><br>  render() {<br>    return &lt;div&gt;{this.props.user.name}&lt;/div&gt;;<br>  }<br>}<br><br>const mapStateToProps = (state) =&gt; ({<br>  user: state.user.profile<br>});<br><br>const mapDispatchToProps = (dispatch) =&gt; ({<br>  fetchUser: (id) =&gt; dispatch({ type: &#39;FETCH_USER&#39;, id })<br>});<br><br>export default connect(mapStateToProps, mapDispatchToProps)(UserProfile);</pre><pre>// AFTER (Modern Functional + Hooks)<br>import React, { useEffect } from &#39;react&#39;;<br>import { useSelector, useDispatch } from &#39;react-redux&#39;;<br>import { fetchUser } from &#39;./userSlice&#39;;<br>const UserProfile = ({ userId }) =&gt; {<br>  const user = useSelector((state) =&gt; state.user.profile);<br>  const dispatch = useDispatch();<br>  useEffect(() =&gt; {<br>    dispatch(fetchUser(userId));<br>  }, [userId]);<br>  return &lt;div&gt;{user.name}&lt;/div&gt;;<br>};<br>export default UserProfile;</pre><p><strong>Migration Benefits:</strong></p><p>✅ 40% less code<br>✅ No this confusion<br>✅ Hooks for lifecycle logic<br>✅ Cleaner useSelector state access</p><h3>Final Verdict: What Should You Use in 2026?</h3><h3>React Components:</h3><p><strong>Use Case — — — — -Recommended Pattern</strong><br><strong>New Projects — — -</strong>✅ Functional Components + Hooks<br><strong>Legacy Code — — — </strong>🔄 Class Components (maintain, don’t expand)<br><strong>Learning React — -</strong>✅ Functional (95% of modern code)</p><h3>Redux:</h3><p>Use Case — — — — -Recommended Pattern<br><strong>New Projects — — </strong>✅ Redux Toolkit + useSelector/useDispatch<br><strong>Legacy Code — —- </strong>🔄 connect() (maintain, migrate gradually)<br><strong>Learning Redux — </strong>✅ Hooks (official 2026 standard)</p><h3>Quick Reference Cheat Sheet</h3><pre>// ✅ MODERN: Functional Component + Redux Hooks<br>import { useState, useEffect } from &#39;react&#39;;<br>import { useSelector, useDispatch } from &#39;react-redux&#39;;<br><br>const MyComponent = () =&gt; {<br>  const data = useSelector((state) =&gt; state.data);<br>  const dispatch = useDispatch();<br>  const [local, setLocal] = useState(&#39;&#39;);<br><br>  useEffect(() =&gt; {<br>    dispatch(loadData());<br>  }, []);<br><br>  return &lt;div&gt;{data}&lt;/div&gt;;<br>};</pre><pre>// ❌ LEGACY: Class Component + connect()<br>import { Component } from &#39;react&#39;;<br>import { connect } from &#39;redux/react&#39;;<br><br>class MyComponent extends Component {<br>  // ... 50 lines of boilerplate<br>}</pre><h3>Key Takeaways</h3><ol><li><strong>Functional Components</strong> are the modern standard (95% of React code in 2026)</li><li><strong>Redux Hooks</strong> (useSelector, useDispatch) replace connect() and mapStateToProps</li><li><strong>Redux Toolkit</strong> is the official recommended way to write Redux (simpler, TypeScript-friendly)</li><li><strong>Class Components</strong> are legacy — learn them only for maintaining old code</li><li><strong>Start fresh with modern patterns</strong> — they’re cleaner, faster, and future-proof</li></ol><p><strong>What’s your experience?</strong> Are you still using class components or old Redux connect()? Share in the comments—I&#39;d love to hear what patterns your team uses!</p><p><em>If this guide helped, follow me for more React, Redux, and web.dev deep dives. Let’s build better apps together!</em> 🚀</p><p>#ReactJS #Redux #JavaScript #WebDevelopment #FunctionalComponents #ReduxToolkit #ReactHooks #MERNStack #Programming #Frontend</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=038762efa419" width="1" height="1" alt=""><hr><p><a href="https://medium.com/skillstuff/react-class-components-vs-functional-components-old-vs-new-redux-the-complete-guide-2026-038762efa419">React Class Components vs. Functional Components + Old vs. New Redux: The Complete Guide (2026)</a> was originally published in <a href="https://medium.com/skillstuff">Skill Stuff</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React + TypeScript Cheatsheet: The Ultimate Quick Reference for 2026]]></title>
            <link>https://medium.com/skillstuff/react-typescript-cheatsheet-the-ultimate-quick-reference-for-2026-c7b471fbab9b?source=rss-e7c9b5635bbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7b471fbab9b</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[typescript-with-react]]></category>
            <category><![CDATA[cheatsheet]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Rahul Jain]]></dc:creator>
            <pubDate>Mon, 15 Jun 2026 13:09:32 GMT</pubDate>
            <atom:updated>2026-07-07T05:10:01.611Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="react typescript cheatsheet by rahuljain.dev" src="https://cdn-images-1.medium.com/max/1024/1*BuQzwq0S730B24PP4lUU6g.jpeg" /></figure><p>When I started mixing React with TypeScript, I spent hours debugging type errors, guessing prop types, and wrestling with generics. This cheatsheet is the distilled guide I wish I had — covering props, state, hooks, events, and common patterns with clean, copy-paste-ready code.</p><p>Whether you’re a beginner or leveling up, bookmark this and use it daily.</p><h3>1. Basic Component Types</h3><h3>Functional Component with Props</h3><pre>interface UserProps {<br>  name: string;<br>  age: number;<br>  isActive?: boolean; // Optional prop<br>}<br><br>const User: React.FC&lt;UserProps&gt; = ({ name, age, isActive = false }) =&gt; {<br>  return &lt;div className={isActive ? &quot;active&quot; : &quot;&quot;}&gt;{name} - {age}&lt;/div&gt;;<br>};</pre><h3>Alternative (More Modern Syntax)</h3><pre>const User = ({ name, age, isActive = false }: UserProps) =&gt; {<br>  return &lt;div className={isActive ? &quot;active&quot; : &quot;&quot;}&gt;{name} - {age}&lt;/div&gt;;<br>};</pre><h3>2. State with TypeScript</h3><h3>useState Basics</h3><pre>import { useState } from &#39;react&#39;;<br><br>// String state<br>const [name, setName] = useState&lt;string&gt;(&quot;&quot;);<br><br>// Number state<br>const [count, setCount] = useState&lt;number&gt;(0);<br><br>// Object state<br>interface User {<br>  id: number;<br>  name: string;<br>}<br>const [user, setUser] = useState&lt;User | null&gt;(null);<br><br>// Array state<br>const [items, setItems] = useState&lt;string[]&gt;([]);<br>const [users, setUsers] = useState&lt;User[]&gt;([]);</pre><h3>useState with Complex Types</h3><pre>interface FormState {<br>  email: string;<br>  password: string;<br>  errors: {<br>    email?: string;<br>    password?: string;<br>  };<br>}<br><br>const [form, setForm] = useState&lt;FormState&gt;({<br>  email: &quot;&quot;,<br>  password: &quot;&quot;,<br>  errors: {}<br>});</pre><h3>3. Props &amp; Event Handlers</h3><h3>Button Click Event</h3><pre>interface ButtonProps {<br>  onClick: (e: React.MouseEvent&lt;HTMLButtonElement&gt;) =&gt; void;<br>  label: string;<br>  disabled?: boolean;<br>}<br><br>const CustomButton: React.FC&lt;ButtonProps&gt; = ({ onClick, label, disabled }) =&gt; {<br>  return &lt;button onClick={onClick} disabled={disabled}&gt;{label}&lt;/button&gt;;<br>};</pre><h3>Change Event (Input)</h3><pre>interface InputProps {<br>  value: string;<br>  onChange: (e: React.ChangeEvent&lt;HTMLInputElement&gt;) =&gt; void;<br>  placeholder?: string;<br>}<br><br>const CustomInput: React.FC&lt;InputProps&gt; = ({ value, onChange, placeholder }) =&gt; {<br>  return &lt;input value={value} onChange={onChange} placeholder={placeholder} /&gt;;<br>};</pre><h3>Form Submit Event</h3><pre>const handleSubmit = (e: React.FormEvent&lt;HTMLFormElement&gt;) =&gt; {<br>  e.preventDefault();<br>  // Handle form submission<br>};<br></pre><h3>4. Hooks with TypeScript</h3><h3>useEffect</h3><pre>useEffect(() =&gt; {<br>  const fetchData = async () =&gt; {<br>    const response = await fetch(&quot;/api/data&quot;);<br>    const data = await response.json() as { id: number; name: string };<br>    setUser(data);<br>  };<br>  <br>  fetchData();<br>}, []); // Empty array = run once on mount</pre><h3>useCallback</h3><pre>const handleClick = useCallback((e: React.MouseEvent&lt;HTMLButtonElement&gt;) =&gt; {<br>  console.log(&quot;Clicked&quot;);<br>}, []);</pre><h3>useMemo</h3><pre>const filteredItems = useMemo&lt;string[]&gt;(() =&gt; {<br>  return items.filter(item =&gt; item.length &gt; 3);<br>}, [items]);</pre><h3>useRef</h3><pre>// DOM reference<br>const inputRef = useRef&lt;HTMLInputElement&gt;(null);<br><br>// Focus input<br>inputRef.current?.focus();<br><br>// Any value (mutable)<br>const countRef = useRef&lt;number&gt;(0);<br>countRef.current = 5;</pre><h3>useReducer</h3><pre>interface State {<br>  count: number;<br>}<br><br>type Action = <br>  | { type: &quot;INCREMENT&quot; }<br>  | { type: &quot;DECREMENT&quot; };<br><br>const reducer = (state: State, action: Action): State =&gt; {<br>  switch (action.type) {<br>    case &quot;INCREMENT&quot;:<br>      return { count: state.count + 1 };<br>    case &quot;DECREMENT&quot;:<br>      return { count: state.count - 1 };<br>    default:<br>      return state;<br>  }<br>};<br><br>const [state, dispatch] = useReducer(reducer, { count: 0 });</pre><h3>5. Children &amp; Generic Props</h3><h3>React.Children with Types</h3><pre>interface CardProps {<br>  children: React.ReactNode;<br>  title: string;<br>}<br><br>const Card: React.FC&lt;CardProps&gt; = ({ children, title }) =&gt; {<br>  return (<br>    &lt;div className=&quot;card&quot;&gt;<br>      &lt;h2&gt;{title}&lt;/h2&gt;<br>      {children}<br>    &lt;/div&gt;<br>  );<br>};</pre><h3>Generic Component</h3><pre>interface ListProps&lt;T&gt; {<br>  items: T[];<br>  renderItem: (item: T) =&gt; React.ReactNode;<br>}<br><br>const List = &lt;T extends {}&gt;({ items, renderItem }: ListProps&lt;T&gt;) =&gt; {<br>  return &lt;ul&gt;{items.map((item, i) =&gt; &lt;li key={i}&gt;{renderItem(item)}&lt;/li&gt;)}&lt;/ul&gt;;<br>};<br><br>// Usage<br>const users = [{ id: 1, name: &quot;Alice&quot; }, { id: 2, name: &quot;Bob&quot; }];<br>&lt;List&lt;User&gt; items={users} renderItem={(user) =&gt; user.name} /&gt;;</pre><h3>6. Context with TypeScript</h3><pre>interface UserContextType {<br>  user: User | null;<br>  setUser: (user: User | null) =&gt; void;<br>}<br><br>const UserContext = createContext&lt;UserContextType | undefined&gt;(undefined);<br><br>// Consumer<br>const UserProvider: React.FC = ({ children }) =&gt; {<br>  const [user, setUser] = useState&lt;User | null&gt;(null);<br>  <br>  return (<br>    &lt;UserContext.Provider value={{ user, setUser }}&gt;<br>      {children}<br>    &lt;/UserContext.Provider&gt;<br>  );<br>};<br><br>// Using useContext<br>const UserDisplay: React.FC = () =&gt; {<br>  const context = useContext(UserContext);<br>  if (!context) return null;<br>  <br>  return &lt;div&gt;{context.user?.name}&lt;/div&gt;;<br>};</pre><h3>7. TypeScript Utility Types for React</h3><pre>// Props from existing component<br>type ButtonProps = React.ComponentProps&lt;&quot;button&quot;&gt;;<br><br>// Event handler types<br>type ClickHandler = (e: React.MouseEvent) =&gt; void;<br>type ChangeHandler = (e: React.ChangeEvent&lt;HTMLInputElement&gt;) =&gt; void;<br><br>// Exclude or pick props<br>type ModalProps = Omit&lt;ButtonProps, &quot;onClick&quot;&gt;; // Remove onClick<br>type FormProps = Pick&lt;ButtonProps, &quot;disabled&quot; | &quot;label&quot;&gt;; // Keep only these<br><br>// Make all props optional<br>type OptionalProps = Partial&lt;ButtonProps&gt;;<br><br>// Make all props required<br>type RequiredProps = Required&lt;OptionalProps&gt;;</pre><h3>8. Common Type Errors &amp; Fixes</h3><h3>❌ “Property does not exist on type”</h3><pre>// Wrong<br>const [user, setUser] = useState(); // ❌ No type inferred<br><br>// Right<br>const [user, setUser] = useState&lt;User | null&gt;(null); // ✅</pre><h3>❌ “Event target type is incorrect”</h3><pre>// Wrong<br>const handleChange = (e: React.ChangeEvent) =&gt; {<br>  const value = e.target.value; // ❌ target is &#39;EventTarget&#39;<br>};<br><br>// Right<br>const handleChange = (e: React.ChangeEvent&lt;HTMLInputElement&gt;) =&gt; {<br>  const value = e.target.value; // ✅ target is HTMLInputElement<br>};</pre><h3>❌ “Cannot access property on nullable value”</h3><pre>// Wrong<br>inputRef.current.focus(); // ❌ current could be null<br><br>// Right<br>inputRef.current?.focus(); // ✅ Optional chaining</pre><h3>9. TypeScript Props Quick Reference</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*-w62qVhiojCmeRnm4Kk9Xg.png" /></figure><h3>10. Copy-Paste Template for New Components</h3><pre>import React, { useState, useEffect } from &#39;react&#39;;<br><br>interface MyComponentProps {<br>  title: string;<br>  items: string[];<br>  onSelect?: (item: string) =&gt; void; // Optional callback<br>}<br><br>const MyComponent: React.FC&lt;MyComponentProps&gt; = ({ title, items, onSelect }) =&gt; {<br>  const [selected, setSelected] = useState&lt;string | null&gt;(null);<br><br>  useEffect(() =&gt; {<br>    console.log(&quot;Items changed:&quot;, items);<br>  }, [items]);<br><br>  const handleClick = (item: string) =&gt; {<br>    setSelected(item);<br>    onSelect?.(item); // Optional call<br>  };<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h2&gt;{title}&lt;/h2&gt;<br>      &lt;ul&gt;<br>        {items.map((item) =&gt; (<br>          &lt;li key={item} onClick={() =&gt; handleClick(item)}&gt;<br>            {item}<br>          &lt;/li&gt;<br>        ))}<br>      &lt;/ul&gt;<br>      {selected &amp;&amp; &lt;p&gt;Selected: {selected}&lt;/p&gt;}<br>    &lt;/div&gt;<br>  );<br>};<br><br><br>export default MyComponent;</pre><h3>Pro Tips</h3><ol><li><strong>Always type your state</strong> — useState&lt;Type&gt;() instead of letting TypeScript infer.</li><li><strong>Use </strong><strong>React.FC</strong> for explicit component typing (or drop it for modern syntax).</li><li><strong>Prefer </strong><strong>React.ReactNode</strong> over any for children.</li><li><strong>Use optional chaining</strong> (?.) for nullable refs/values.</li><li><strong>Leverage utility types</strong> (Partial, Omit, Pick) to avoid repeating props.</li></ol><p><strong>What’s your favorite TypeScript + React pattern?</strong> Drop a comment below — I’d love to see what works for your team!</p><p><em>If this cheatsheet helped, follow me for more React, TypeScript, and web.dev deep dives. Let’s build better apps together!</em> 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7b471fbab9b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/skillstuff/react-typescript-cheatsheet-the-ultimate-quick-reference-for-2026-c7b471fbab9b">React + TypeScript Cheatsheet: The Ultimate Quick Reference for 2026</a> was originally published in <a href="https://medium.com/skillstuff">Skill Stuff</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SSR, SSG, ISG, and CSR: The Complete Guide to Web Rendering Strategies]]></title>
            <link>https://rahuljain-dev.medium.com/ssr-ssg-isg-and-csr-the-complete-guide-to-web-rendering-strategies-de7065a57205?source=rss-e7c9b5635bbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/de7065a57205</guid>
            <category><![CDATA[ssrs]]></category>
            <category><![CDATA[ssg]]></category>
            <dc:creator><![CDATA[Rahul Jain]]></dc:creator>
            <pubDate>Mon, 15 Jun 2026 12:38:24 GMT</pubDate>
            <atom:updated>2026-06-15T12:38:24.921Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IVoUizYOK4bJ7Ieh5wxokg.jpeg" /></figure><p>When I first stepped into web development, I struggled a lot to understand the differences between HTML rendering strategies. You’ll hear terms like CSR, SSR, SSG, and ISR (often called ISG) tossed around in React and Next.js discussions, but what do they actually mean? And which should you choose for your project?</p><p>Let’s break it down with real examples, performance comparisons, and practical recommendations.</p><h3>What Are Rendering Strategies?</h3><p>Rendering strategies determine <strong>when and where</strong> your HTML gets generated before being sent to the user’s browser. This choice impacts:</p><ul><li><strong>Performance</strong> (how fast your page loads)</li><li><strong>SEO</strong> (how well search engines can index your content)</li><li><strong>User experience</strong> (interactivity and freshness of data)</li><li><strong>Server costs</strong> (computational resources required)</li></ul><h3>1. CSR (Client-Side Rendering)</h3><h3>How It Works</h3><p>The server sends a <strong>blank HTML page with JavaScript files</strong>. Your browser then executes that JavaScript to build the actual content dynamically.</p><pre>// Traditional React app (create-react-app, Vite) uses CSR by default<br>function App() {<br>  return &lt;div&gt;Hello, this is rendered in the browser!&lt;/div&gt;;<br>}</pre><h3>Characteristics</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*typCj0Q7hBVmeSj8UuE5Gw.png" /></figure><h3>Example Use Case</h3><p>A user dashboard where data is personalized and changes frequently (e.g., banking app, admin panel).</p><h3>2. SSR (Server-Side Rendering)</h3><h3>How It Works</h3><p>The server <strong>prepares the full HTML with content</strong> for each incoming request and sends it directly to the browser.</p><pre>// Next.js with getServerSideProps<br>export async function getServerSideProps(context) {<br>  const data = await fetchAPI();<br>  return { props: { data } };<br>}</pre><h3>Characteristics</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*LrVdkB5UDMUcDrejGfAV7w.png" /></figure><h3>Trade-offs</h3><ul><li><strong>Expensive</strong>: Generates HTML from scratch on every request</li><li><strong>Server-dependent</strong>: Requires a running server for each request</li></ul><h3>3. SSG (Static Site Generation)</h3><h3>How It Works</h3><p>All HTML pages are <strong>generated ahead of time</strong> (at build time). When someone visits, they get a pre-made page served from a CDN.</p><pre>// Next.js with getStaticProps<br>export async function getStaticProps() {<br>  const data = await fetchAPI();<br>  return { props: { data } };<br>}</pre><h3>Characteristics</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*QkmETKnADjzlpbPn52MUFw.png" /></figure><h3>Example Use Case</h3><p>A company blog or marketing site where content doesn’t change hourly.</p><h3>4. ISR / ISG (Incremental Static Regeneration)</h3><p><em>Note: ISG is often called ISR in Next.js documentation.</em></p><h3>How It Works</h3><p>Pages are <strong>served statically</strong> but can be <strong>regenerated automatically in the background</strong> at specified intervals or upon certain triggers.</p><pre>// Next.js ISR with revalidate<br>export async function getStaticProps() {<br>  return {<br>    props: { data },<br>    revalidate: 10 // Regenerate after 10 seconds<br>  };<br>}</pre><h3>Characteristics</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*5jkJbIXINHAxaWl095yO4A.png" /></figure><p>Why It’s Powerful</p><ul><li>Provides <strong>all benefits of SSG</strong> (speed, CDN)</li><li><strong>Mitigates SSG’s drawback</strong> (stale data) by regenerating HTML on-demand</li></ul><h3>Quick Comparison Table</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*bKVnjv5oC-c487igFIqZKw.png" /></figure><h3>How to Choose: A Practical Decision Framework</h3><h3>Question 1: Does SEO matter?</h3><ul><li><strong>Yes</strong> → Avoid CSR (or add.dynamic sitemap + meta tags)</li><li><strong>No</strong> → CSR is acceptable (dashboards, admin panels)</li></ul><h3>Question 2: How often does content change?</h3><ul><li><strong>Rarely (weekly/monthly)</strong> → SSG</li><li><strong>Frequently (hourly/daily)</strong> → ISR/ISG</li><li><strong>Real-time (every second)</strong> → SSR</li></ul><h3>Question 3: What’s your performance budget?</h3><ul><li><strong>Need lightning-fast pages</strong> → SSG or ISR</li><li><strong>Need always-fresh data</strong> → SSR</li><li><strong>Need heavy interactivity</strong> → CSR</li></ul><h3>Pro Tip from Industry</h3><blockquote><em>Use </em><strong><em>SSG or ISR for most pages</em></strong><em>, and reserve </em><strong><em>SSR for highly dynamic or personalized content</em></strong><em>. Employ </em><strong><em>CSR for components that need heavy interactivity but aren’t critical for SEO</em></strong><em>.</em></blockquote><h3>Real-World Examples</h3><h3>Blog Website</h3><ul><li><strong>Strategy</strong>: SSG or ISR</li><li><strong>Why</strong>: Content is mostly static, SEO is critical, speed matters</li></ul><h3>E-commerce Product Page</h3><ul><li><strong>Strategy</strong>: ISR</li><li><strong>Why</strong>: Price/inventory changes frequently, but page is mostly static</li></ul><h3>News Website</h3><ul><li><strong>Strategy</strong>: SSR or ISR</li><li><strong>Why</strong>: Content updates constantly, SEO critical</li></ul><h3>User Dashboard (Banking App)</h3><ul><li><strong>Strategy</strong>: CSR or SSR</li><li><strong>Why</strong>: Personalized data, SEO not important, interactivity key</li></ul><h3>Common Mistakes to Avoid</h3><ol><li><strong>Using CSR for SEO-critical pages</strong> (blogs, marketing sites)</li><li><strong>Using SSG for frequently changing data</strong> without ISR</li><li><strong>Using SSR for static content</strong> (unnecessary server load)</li><li><strong>Not considering CDN caching</strong> with SSG/ISR</li></ol><h3>Next.js Implementation Cheat Sheet</h3><pre>// CSR — Default React (create-react-app, Vite)<br>// No special code needed<br><br>// SSR — Next.js getServerSideProps<br>export async function getServerSideProps() {<br>  // Fetch on each request<br>}<br><br>// SSG — Next.js getStaticProps<br>export async function getStaticProps() {<br>  // Fetch at build time<br>}<br><br>// ISR — Next.js getStaticProps with revalidate<br>export async function getStaticProps() {<br>  return {<br>    revalidate: 10 // Seconds between regenerations<br>  };<br>}</pre><h3>Final Thoughts</h3><p>There’s no “best” strategy — the right choice depends on your <strong>specific context</strong>. Here’s my recommendation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*z-9vW7b31nF9HJZgr1V9Vw.png" /></figure><p>Most modern applications use a <strong>hybrid approach</strong>: SSG/ISR for public pages, SSR for personalized dashboards, and CSR for highly interactive components.</p><p>Start with <strong>SSG or ISR for 80% of your pages</strong>, then selectively use SSR or CSR where needed. This balances performance, cost, and user experience.</p><p><strong>What rendering strategy do you use day-to-day?</strong> Drop a comment below — I’d love to hear what works for your projects!</p><p><em>If you found this helpful, consider following me for more deep dives into web development, React, and Next.js. Let’s build better web experiences together!</em> 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de7065a57205" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unveiling the Power of Code-Splitting with Webpack for React and Redux Applications]]></title>
            <link>https://rahuljain-dev.medium.com/unveiling-the-power-of-code-splitting-with-webpack-for-react-and-redux-applications-cc5a7cadf7d0?source=rss-e7c9b5635bbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc5a7cadf7d0</guid>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[lazy-loading]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[codesplit]]></category>
            <dc:creator><![CDATA[Rahul Jain]]></dc:creator>
            <pubDate>Sun, 13 Aug 2023 09:15:42 GMT</pubDate>
            <atom:updated>2023-08-13T09:17:33.302Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*I0QEEz1mX5uP4Edzi1xcnw.png" /></figure><p>In the realm of modern web development, speed and performance are paramount. Slow-loading web applications can drive users away and negatively impact user experience. This is where the concept of code-splitting comes into play, and when paired with a powerful tool like Webpack, it can drastically enhance the performance of React and Redux applications. In this comprehensive guide, we’ll unravel the magic behind code-splitting, explore its benefits, and embark on a journey to master code-splitting with Webpack in the context of React and Redux.</p><h3>Understanding Code-Splitting</h3><p>At its core, code-splitting is a technique that involves breaking down a large JavaScript bundle into smaller, more manageable chunks. These chunks, also known as bundles, are loaded asynchronously, allowing for faster initial page loads and better overall performance. Code-splitting ensures that only the necessary code is loaded when a specific feature or page is accessed, reducing the time it takes for the application to become interactive.</p><p>Webpack, a popular module bundler for JavaScript applications, offers built-in support for code-splitting. It provides a seamless way to create dynamic bundles that are loaded on demand, revolutionizing the way we optimize web applications.</p><h3>Benefits of Code-Splitting in React and Redux Applications</h3><ol><li><strong>Faster Load Times</strong>: With code-splitting, your application’s initial load time is significantly reduced. Users get to experience the core functionality of your app faster, leading to a positive user experience.</li><li><strong>Optimized Network Usage</strong>: Loading only the required code means reduced bandwidth usage. This is especially crucial for users on slow connections or mobile devices.</li><li><strong>Enhanced Performance</strong>: By loading only what’s needed, your application can allocate resources more efficiently, resulting in smoother animations and interactions.</li><li><strong>Better SEO</strong>: Faster load times lead to improved SEO rankings. Search engines prioritize websites that provide a seamless user experience.</li><li><strong>Caching Efficiency</strong>: Smaller bundles are more likely to be cached by browsers, further enhancing load times for returning users.</li></ol><h3>Code-Splitting in React and Redux: A Practical Example</h3><p>Let’s dive into a comprehensive example of code-splitting with Webpack in the context of a React and Redux application. Imagine you’re building a large e-commerce platform with various sections: product listings, user profiles, and shopping carts. Instead of bundling all the code into one massive file, we’ll use code-splitting to create separate bundles for each major section.</p><ol><li><strong>Setting Up Your Environment</strong></li></ol><p>Begin by setting up your project environment. Ensure you have Node.js and npm installed. Then, create a new React application:</p><pre>npx create-react-app learn-code-splitting</pre><p><strong>2. Implementing Code-Splitting</strong></p><p>In your React application, open the component that corresponds to the route you want to code-split. Let’s say it’s the Product Listing component.</p><pre>import React, { lazy, Suspense } from &#39;react&#39;;<br><br>const ProductListing = lazy(() =&gt; import(&#39;./ProductListing&#39;));<br><br>function App() {<br>  return (<br>    &lt;div&gt;<br>      {/* Other components */}<br>      &lt;Suspense fallback={&lt;div&gt;Loading...&lt;/div&gt;}&gt;<br>        &lt;ProductListing /&gt;<br>      &lt;/Suspense&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p><strong>3. Webpack Configuration for Code-Splitting</strong></p><p>Your Webpack configuration should already be optimized for code-splitting in a React application. The output section of the configuration file should look something like this:</p><pre>output: {<br>  filename: &#39;[name].[contenthash].js&#39;,<br>  chunkFilename: &#39;[name].[contenthash].js&#39;,<br>  // Other configurations<br>},</pre><h3><strong>Let’s delve deeper into the specifics of Webpack configuration to achieve effective code-splitting.</strong></h3><p>Webpack offers several ways to implement code-splitting, but one of the most common approaches is using dynamic imports with the import() function. When you dynamically import a module, Webpack recognizes it as a potential split point, creating a separate bundle for that module.</p><p>Here’s a breakdown of the Webpack configuration aspects that contribute to successful code-splitting:</p><p><strong>1. Output Configuration:</strong></p><p>The output configuration determines where Webpack outputs your bundles. When it comes to code-splitting, two key properties come into play: filename and chunkFilename.</p><ul><li>filename: This property defines the name of the bundle file for your main application code. Typically, you&#39;ll use [name] and [contenthash] placeholders to ensure cache-busting.</li><li>chunkFilename: This property specifies the name of the dynamically generated split chunks. These are the code-split bundles that result from dynamic imports. Again, using [name] and [contenthash] placeholders is recommended.</li></ul><pre>output: {<br>  filename: &#39;[name].[contenthash].js&#39;,<br>  chunkFilename: &#39;[name].[contenthash].js&#39;,<br>  // Other configurations<br>},</pre><p><strong>2. Webpack Mode:</strong></p><p>Webpack’s mode configuration option can impact how code-splitting behaves. In production mode, Webpack automatically performs aggressive optimizations, which can lead to more efficient code-splitting. It&#39;s recommended to set the mode accordingly:</p><pre>mode: &#39;production&#39;,</pre><p><strong>3. Optimization:</strong></p><p>Webpack’s optimization settings play a crucial role in code-splitting. The optimization.splitChunks configuration enables you to fine-tune how chunks are generated.</p><pre>optimization: {<br>  splitChunks: {<br>    chunks: &#39;all&#39;,<br>  },<br>},</pre><p>The above setting tells Webpack to consider all chunks for optimization. You can further customize the splitChunks settings to control factors such as the minimum chunk size, caching, and naming conventions.</p><p><strong>4. Code-Splitting with React Router:</strong></p><p>If you’re using React Router for routing in your application, you can integrate code-splitting for each route. React Router’s React.lazy() and Suspense API make this integration seamless.</p><pre>import { lazy, Suspense } from &#39;react&#39;;<br>import { BrowserRouter as Router, Route, Switch } from &#39;react-router-dom&#39;;<br><br>const Home = lazy(() =&gt; import(&#39;./components/Home&#39;));<br>const About = lazy(() =&gt; import(&#39;./components/About&#39;));<br><br>function App() {<br>  return (<br>    &lt;Router&gt;<br>      &lt;Suspense fallback={&lt;div&gt;Loading...&lt;/div&gt;}&gt;<br>        &lt;Switch&gt;<br>          &lt;Route exact path=&quot;/&quot; component={Home} /&gt;<br>          &lt;Route path=&quot;/about&quot; component={About} /&gt;<br>        &lt;/Switch&gt;<br>      &lt;/Suspense&gt;<br>    &lt;/Router&gt;<br>  );<br>}</pre><p>By configuring Webpack with the mentioned settings, you enable effective code-splitting in your React and Redux applications. This results in the creation of smaller bundles that load only when needed, improving overall application performance and user experience. Remember that fine-tuning these settings based on your project’s specific requirements will yield the best results.</p><h3><strong>Lets do more optimization</strong></h3><p>When a chunk generated by the React build command exceeds a certain size threshold, such as 500kb, it’s a good practice to configure Webpack to further split the bundle into smaller chunks. This optimization helps improve loading times, especially for users with slower network connections. Here’s how you could configure Webpack to handle this scenario:</p><p><strong>1. Set the Size Threshold:</strong></p><p>Start by specifying the size threshold for your chunks. In this case, you want to split chunks that are larger than 500kb. You can achieve this by configuring the performance option in your Webpack configuration:</p><pre>performance: {<br>  maxAssetSize: 500 * 1024, // 500kb in bytes<br>},</pre><p><strong>2. Configure Splitting:</strong></p><p>Next, you can configure Webpack to split chunks that exceed the specified size threshold. The optimization.splitChunks configuration allows you to customize how chunks are split. You can set parameters like minSize, which determines the minimum size of chunks that should be generated.</p><pre>optimization: {<br>  splitChunks: {<br>    chunks: &#39;all&#39;,<br>    minSize: 0, // Set to 0 to enforce splitting regardless of size<br>  },<br>},</pre><p>By setting minSize to 0, you ensure that even chunks smaller than 500kb are considered for splitting if they contribute to reducing the overall bundle size.</p><p><strong>3. Chunk Naming:</strong></p><p>To maintain consistent naming conventions and ensure cache-busting, adjust the chunkFilename in the output configuration:</p><pre>output: {<br>  // ...<br>  chunkFilename: &#39;[name].[contenthash].js&#39;,<br>},</pre><p>This ensures that the generated split chunks are named appropriately.</p><p><strong>4. Fallback Loading:</strong></p><p>When using dynamic imports with React’s React.lazy() and Suspense for code-splitting, it&#39;s important to provide a fallback loading mechanism for a seamless user experience:</p><pre>import React, { lazy, Suspense } from &#39;react&#39;;<br><br>const LargeComponent = lazy(() =&gt; import(&#39;./LargeComponent&#39;));<br><br>function App() {<br>  return (<br>    &lt;div&gt;<br>      &lt;Suspense fallback={&lt;div&gt;Loading...&lt;/div&gt;}&gt;<br>        &lt;LargeComponent /&gt;<br>      &lt;/Suspense&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>By configuring Webpack with the above settings, you ensure that chunks exceeding 500kb are further split into smaller chunks, improving loading times and user experience. However, remember that each project’s requirements may vary, so adjust these configurations based on your specific needs and performance testing.</p><h3>Hope you have learned the methodology</h3><p>Code-splitting is a game-changing technique that can significantly enhance the performance of React and Redux applications. When coupled with Webpack, it empowers developers to optimize load times, boost user experience, and create web applications that stand out in today’s competitive digital landscape.</p><p>By strategically breaking down your application’s code into smaller, manageable chunks and loading them on demand, you’re not only enhancing performance but also delivering a seamless user experience. As you embark on your journey to master code-splitting with Webpack, remember that your users’ satisfaction and engagement are at the heart of every optimization you make.</p><p>I’m here to support your learning journey every step of the way. If you come across any queries or uncertainties while exploring the concepts I’ve covered, feel free to drop a comment. I’m committed to providing prompt and thorough responses to all your questions.</p><p>In addition, I’m more than willing to delve even deeper into the intricacies of Webpack configuration if that’s what you’re seeking. If there’s a specific aspect or topic you’d like me to elaborate on, just let me know. Your feedback and engagement are invaluable, and they help me tailor my content to your needs.</p><p>Should you find yourself hungry for further insights beyond what’s covered here, I’m open to crafting additional articles that take you even further into the world of configuration optimization. Your learning experience matters to me, and I’m dedicated to ensuring you have the knowledge and tools you need to succeed.</p><p>Thank you for being a part of this journey, and I’m excited to assist you in your quest to master Webpack and elevate your web development skills. Your curiosity and commitment to learning are truly inspiring, and I’m here to provide the guidance you need to thrive.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc5a7cadf7d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Demystifying Optional Chaining: Simplifying JavaScript Nested Property Access]]></title>
            <link>https://rahuljain-dev.medium.com/demystifying-optional-chaining-simplifying-javascript-nested-property-access-1abe3053c9b7?source=rss-e7c9b5635bbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/1abe3053c9b7</guid>
            <category><![CDATA[nullish-coalescing]]></category>
            <category><![CDATA[handling-optional-chain]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[optional-chaining]]></category>
            <dc:creator><![CDATA[Rahul Jain]]></dc:creator>
            <pubDate>Wed, 02 Aug 2023 17:27:23 GMT</pubDate>
            <atom:updated>2023-08-02T17:28:52.837Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UkA6KD6Ma9Y2vgog" /><figcaption>Photo by <a href="https://unsplash.com/@mildanat?utm_source=medium&amp;utm_medium=referral">Anatvida Sukchanta</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>JavaScript, being a powerful and flexible language, allows developers to work with complex data structures. However, dealing with nested objects and optional properties can become cumbersome and error-prone. This is where Optional Chaining comes to the rescue, offering a cleaner and safer way to access deeply nested properties in JavaScript.</p><p>We’ll dive deeper into Optional Chaining, how it simplifies nested property access, and why it’s an essential feature for modern JavaScript development. We’ll also provide practical code examples to demonstrate its usage and highlight the benefits it brings to your codebase.</p><h3>What is Optional Chaining?</h3><p>Optional Chaining is a feature introduced in ECMAScript 2020 (ES11) to handle situations where an object may contain nested properties, and some of these properties might be optional or not present at all. Traditional property access, using the dot notation or square brackets, can lead to TypeError when trying to access a property that does not exist. Optional Chaining helps us gracefully handle such scenarios.</p><p>Using Optional Chaining, you can access deeply nested properties without worrying about the existence of intermediate properties. If any of the properties in the chain are undefined or null, the expression will short-circuit and return undefined, preventing any TypeError.</p><h3>Example Syntax:</h3><p>The syntax for Optional Chaining involves appending a question mark (?) to the property or method you want to access in a chain. Let&#39;s see how it works:</p><pre>const user = {<br>  name: &#39;Rahul Jain&#39;,<br>  address: {<br>    city: &#39;Jaipur&#39;,<br>    // Uncomment the line below to make the &#39;country&#39; property undefined<br>    // country: &#39;India&#39;,<br>  },<br>};<br><br>// Without Optional Chaining<br>const country = user.address.country; // May result in TypeError<br><br>// With Optional Chaining<br>const country = user.address?.country; // No TypeError, country will be undefined</pre><p>In the above example, if the ‘country’ property is not present in the ‘address’ object, the expression using Optional Chaining will return undefined, avoiding any runtime error.</p><h3>Handling Method Calls:</h3><p>Optional Chaining also works with method calls. If the method does not exist, the expression will return undefined without throwing any errors.</p><pre>const calculator = {<br>  add: (a, b) =&gt; a + b,<br>  // Uncomment the line below to make the &#39;subtract&#39; method undefined<br>  // subtract: (a, b) =&gt; a - b,<br>};<br><br>// Without Optional Chaining<br>const result = calculator.subtract(5, 2); // May result in TypeError<br><br>// With Optional Chaining<br>const result = calculator.subtract?.(5, 2); // No TypeError, result will be undefined</pre><h3>Combining Optional Chaining with Nullish Coalescing:</h3><p>Optional Chaining can be effectively combined with the Nullish Coalescing operator (??) to provide default values for undefined properties.</p><pre>const user = {<br>  name: &#39;Rahul Jain&#39;,<br>  address: {<br>    city: &#39;Jaipur&#39;,<br>    // Uncomment the line below to make the &#39;country&#39; property undefined<br>    // country: &#39;India&#39;,<br>  },<br>};<br><br>// Without Optional Chaining and Nullish Coalescing<br>const country = user.address.country || &#39;Unknown&#39;; // Not safe, will use &#39;Unknown&#39; for falsy values<br><br>// With Optional Chaining and Nullish Coalescing<br>const country = user.address?.country ?? &#39;Unknown&#39;; // Safe, will use &#39;Unknown&#39; for undefined or null</pre><h3>Real-world Use Cases:</h3><p>Optional Chaining becomes invaluable when dealing with data fetched from APIs or user inputs. Instead of writing verbose checks for each nested property, you can leverage Optional Chaining to streamline your code and make it more concise and readable.</p><p>Consider the following example where we fetch user data from an API:</p><pre>const fetchUserData = async () =&gt; {<br>  const response = await fetch(&#39;https://api.example.com/user/123&#39;);<br>  const data = await response.json();<br><br>  // Without Optional Chaining<br>  const name = data.name ? data.name : &#39;Unknown&#39;;<br>  const country = data.address &amp;&amp; data.address.country ? data.address.country : &#39;Unknown&#39;;<br><br>  // With Optional Chaining<br>  const name = data.name ?? &#39;Unknown&#39;;<br>  const country = data.address?.country ?? &#39;Unknown&#39;;<br>};</pre><h3>So far you have understood:</h3><p>Optional Chaining is a powerful feature that simplifies nested property access in JavaScript. By using the question mark (?) syntax, you can safely access nested properties without worrying about null or undefined values. This makes your code more robust, readable, and less error-prone.</p><p>As a best practice, use Optional Chaining in scenarios where nested properties might be optional or undefined, such as working with external data sources, APIs, and user inputs. Embrace this feature to enhance the maintainability and elegance of your JavaScript code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1abe3053c9b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Pure and Impure Functions in JavaScript: A Key to Efficient Code]]></title>
            <link>https://rahuljain-dev.medium.com/understanding-pure-and-impure-functions-in-javascript-a-key-to-efficient-code-96859f379f6e?source=rss-e7c9b5635bbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/96859f379f6e</guid>
            <category><![CDATA[javascript-pure-function]]></category>
            <category><![CDATA[pure-function]]></category>
            <category><![CDATA[impure]]></category>
            <category><![CDATA[impure-function]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[Rahul Jain]]></dc:creator>
            <pubDate>Tue, 01 Aug 2023 08:23:02 GMT</pubDate>
            <atom:updated>2023-08-01T08:49:37.337Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Xyo9YJ2n6yI7X70Bu7QHA.png" /></figure><p>When working with JavaScript, it is essential to grasp the concept of <strong>pure</strong> and <strong>impure functions</strong>. These two paradigms play a crucial role in maintaining code reliability, predictability, and reusability. By completing this article you will be able to differentiate between pure and impure functions, exploring their definitions, differences, and practical use cases.</p><h3>What are Pure Functions?</h3><p>A pure function is a fundamental concept in functional programming, wherein a function produces predictable output solely based on its input parameters. In other words, for the same set of input arguments, a pure function will always yield the same output without causing any side effects.</p><pre>// Pure function - calculate the area of a circle<br>function calcCircleArea(radius) {<br>  return Math.PI * radius * radius;<br>}<br><br>// Perform follow to execute the function<br>const radius = 5;<br>const area = calcCircleArea(radius);<br>console.log(`Circle area of radius ${radius} is ${area}`);</pre><blockquote><strong>Insight of the Pure Functions:</strong></blockquote><ol><li><strong>Deterministic:</strong> Pure functions exhibit determinism, meaning their behavior is entirely predictable. Given the same input, they will return the same output every time.</li><li><strong>No Side Effects: </strong>Pure functions do not modify any data outside their scope nor interact with the external world. They do not rely on or modify any global variables, making them isolated and self-contained.</li><li><strong>Referential Transparency:</strong> Due to their lack of side effects, pure functions are referentially transparent, meaning they can be replaced with their return value without altering the program’s behavior.</li></ol><blockquote><strong>Benefits of Pure Functions:</strong></blockquote><ol><li><strong>Testability: </strong>Since pure functions depend only on their input, they are easy to test. Unit tests can be written to verify their behavior without worrying about complex setups or external dependencies.</li><li><strong>Debugging:</strong> With their predictability, debugging pure functions is more straightforward, as the source of any errors can be traced directly to the input data.</li><li><strong>Memoization:</strong> Pure functions can be easily memoized, enabling caching of results for improved performance in repeated computations.</li></ol><h3>What are Impure Functions?</h3><p>In contrast to pure functions, impure functions have side effects and can produce different output for the same set of input parameters. These side effects could involve modifying external state, such as global variables, or performing I/O operations like reading/writing to files or making network requests.</p><pre>// Global variable<br>let counter = 0;<br><br>// Impure function - increment the global counter<br>function incrCounter() {<br>  counter++;<br>}<br><br>// Usage<br>incrCounter();<br>console.log(`Counter value: ${counter}`); // Output: &quot;Counter value: 1&quot;<br>incrCounter();<br>console.log(`Counter value: ${counter}`); // Output: &quot;Counter value: 2&quot;</pre><blockquote><strong>Insight of the Impure Functions:</strong></blockquote><ol><li>Side Effects: Impure functions modify state outside their scope or have an impact on the external environment.</li><li>Unpredictable Output: The return value of an impure function can vary for the same input, depending on the state of external entities at the time of execution.</li><li>Difficult to Reason: Impure functions can make the code more challenging to understand and debug due to their dependence on the program’s global state.</li></ol><blockquote><strong>Common Side Effects:</strong></blockquote><ul><li>Modifying global variables or data structures</li><li>Reading from or writing to files or databases</li><li>Network requests</li><li>Printing to the console or displaying pop-ups</li></ul><h4><strong><em>Choosing Between Pure and Impure Functions:</em></strong></h4><blockquote>It is essential to decide between pure and impure functions based on the specific requirements of your application.</blockquote><blockquote><strong>Use Pure Functions When:</strong></blockquote><ul><li>Predictable output is crucial.</li><li>Testability and debugging are essential.</li><li>You want to avoid side effects and make the code more maintainable.</li></ul><blockquote><strong>Use Impure Functions When:</strong></blockquote><ul><li>Interacting with the external environment is necessary.</li><li>Working with I/O operations or managing global state.</li><li>Performance optimizations using memoization or caching are required.</li></ul><h4>Hope you have found this useful:</h4><p>Understanding pure and impure functions in JavaScript is vital to writing efficient, reliable, and maintainable code. Pure functions promote predictability, testability, and reusability, while impure functions enable interaction with the external world and can be used for operations involving side effects. By leveraging these paradigms thoughtfully, developers can build robust applications and ensure the quality of their codebase.</p><p>In this enchanting world of programming, a balance between purity and impurity awaits your creative touch. Remember, every line of code you write shapes the destiny of your application. Embrace the art of crafting pure functions, while unleashing the potential of impure ones when the need arises.</p><p>So, go forth with confidence, fellow developers! May your codebase be a symphony of pure melodies and impure adventures, captivating users and fellow programmers alike. Like and share the magic of pure and impure functions, and together, let’s create a world of efficient and delightful JavaScript applications! Happy coding! ✨🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96859f379f6e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Function Composition in JavaScript: Unleashing the Power of Composition]]></title>
            <link>https://rahuljain-dev.medium.com/mastering-function-composition-in-javascript-unleashing-the-power-of-composition-60bcb582ada0?source=rss-e7c9b5635bbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/60bcb582ada0</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[function-composition]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Rahul Jain]]></dc:creator>
            <pubDate>Mon, 31 Jul 2023 11:44:05 GMT</pubDate>
            <atom:updated>2023-07-31T11:44:05.918Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Z7nP1G_NnO2eLVtUeN5uA.png" /><figcaption>Example of Function Composition</figcaption></figure><h3>Introduction</h3><p>JavaScript, with its versatile and expressive nature, allows developers to craft complex applications with ease. One of the language’s most powerful features is function composition, a functional programming concept that enables developers to combine multiple functions to create new, reusable, and composable functions. Function composition unlocks a world of possibilities, from cleaner and more maintainable code to enhanced productivity. In this article, we will explore the concept of function composition in JavaScript, understand its benefits, and learn how to effectively leverage it to write efficient and elegant code.</p><h3>Understanding Function Composition</h3><p>Function composition is the process of combining two or more functions to create a new function. The output of one function becomes the input of the next, forming a chain of functions that execute in a specific order. It follows the mathematical notion of composing functions, where the result of applying one function becomes the argument of another function. In JavaScript, we can achieve function composition using different techniques, such as using utility libraries or writing our own helper functions.</p><h3>Benefits of Function Composition</h3><ol><li>Code Reusability: Function composition allows us to create small, specialized functions that can be combined in various ways to create more complex operations. This promotes code reusability and helps avoid duplication, leading to a more maintainable and organized codebase.</li><li>Readability and Maintainability: By breaking down complex tasks into smaller, more focused functions, our code becomes more readable and easier to understand. Each function has a clear purpose, making it simpler to debug and maintain over time.</li><li>Declarative Programming: Function composition encourages declarative programming, where we express what we want to achieve without worrying about the step-by-step instructions. This leads to more concise and expressive code.</li><li>Immutability: Function composition often goes hand-in-hand with immutability, which is a fundamental concept in functional programming. Since each function creates a new value rather than modifying existing data, it helps prevent unintended side effects and bugs.</li></ol><h3>Function Composition Techniques</h3><p>1. Manual Composition:</p><pre>const add = (x) =&gt; x + 2;<br>const multiply = (x) =&gt; x * 3;<br>const subtract = (x) =&gt; x - 1;<br><br>const composedFunction = (x) =&gt; subtract(multiply(add(x)));</pre><p>2. Utility Libraries: Libraries like Lodash and Ramda offer convenient functions for function composition.</p><p>Using Lodash:</p><pre>const { flow } = require(&#39;lodash&#39;);<br>const composedFunction = flow(<br> add,<br> multiply,<br> subtract<br>);</pre><p>Using Ramda:</p><pre>const { compose } = require(&#39;ramda&#39;);<br>const composedFunction = compose(<br> subtract,<br> multiply,<br> add<br>);</pre><p>3. Custom Utility Function:</p><pre>const compose = (...funcs) =&gt; (x) =&gt; funcs.reduceRight((acc, func) =&gt; func(acc), x);<br><br>const composedFunction = compose(<br>  subtract,<br>  multiply,<br>  add<br>);</pre><h3>Conclusion</h3><p>Function composition is a powerful tool in a JavaScript developer’s toolkit. By breaking down complex tasks into smaller, composable functions, we can create more maintainable, reusable, and efficient code. Understanding the benefits of function composition and the various techniques to implement it will empower developers to write elegant and expressive code, leading to enhanced productivity and improved software quality. Embrace function composition in your JavaScript projects and unleash the true potential of functional programming. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60bcb582ada0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>