<?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 Thrishakannan on Medium]]></title>
        <description><![CDATA[Stories by Thrishakannan on Medium]]></description>
        <link>https://medium.com/@thrishakannan25?source=rss-0e9448c7c43c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*zOpK0ZJy9Zqk8bMK</url>
            <title>Stories by Thrishakannan on Medium</title>
            <link>https://medium.com/@thrishakannan25?source=rss-0e9448c7c43c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 16:47:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thrishakannan25/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Understanding React’s createPortal: A Simple Guide]]></title>
            <link>https://medium.com/@thrishakannan25/understanding-reacts-createportal-a-simple-guide-20ce2f6805d2?source=rss-0e9448c7c43c------2</link>
            <guid isPermaLink="false">https://medium.com/p/20ce2f6805d2</guid>
            <category><![CDATA[react-portal]]></category>
            <dc:creator><![CDATA[Thrishakannan]]></dc:creator>
            <pubDate>Wed, 29 May 2024 15:15:16 GMT</pubDate>
            <atom:updated>2024-05-29T15:17:04.974Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently used React’s createPortal to add an announcement bar in a Shopify theme, where our app &quot;<a href="https://apps.shopify.com/cornercart?utm_content=header-nav&amp;utm_medium=landing-page&amp;utm_source=usecorner-io">Corner Cart Drawer &amp; Free Gift</a>&quot; is installed. This technique allowed me to seamlessly integrate the announcement bar without disrupting the existing DOM structure.</p><p>React’s createPortal is a powerful tool that allows you to render components outside the main DOM hierarchy of the parent component. This can be incredibly useful for scenarios where you need to break out of the typical flow, such as rendering modals, tooltips, or any other component that should overlay other content. In this blog, we will dive into the basics of createPortal, its usage, and some practical examples to help you understand how it works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*Vt1VQIPqL2J1VJDlbt8IOw.png" /></figure><h3>What is createPortal?</h3><p>In React, createPortal allows you to render children into a different part of the DOM tree. While the component rendering might logically belong to one part of your app, visually it can appear somewhere else. This is especially useful for elements that need to appear above everything else, like modals and pop-ups.</p><h3>Syntax</h3><p>The createPortal function is straightforward to use. It takes two mandatory arguments:</p><ol><li>children: The React nodes you want to render.</li><li>domNode: The DOM node where the children should be rendered.</li></ol><p>It also accepts an optional key parameter which is useful for uniquely identifying the portal when rendering a list of portals.</p><pre>import { createPortal } from &#39;react-dom&#39;;<br><br>// Example usage:<br>createPortal(children, domNode, key?)</pre><h3>Basic Example</h3><p>Here’s a basic example to illustrate how createPortal works. Imagine you have a component where you want to render a piece of text directly into the body of the document.</p><pre>import React from &#39;react&#39;;<br>import { createPortal } from &#39;react-dom&#39;;<br><br>function MyComponent() {<br>  return (<br>    &lt;div style={{ border: &#39;2px solid black&#39; }}&gt;<br>      &lt;p&gt;This child is placed in the parent div.&lt;/p&gt;<br>      {createPortal(<br>        &lt;p&gt;This child is placed in the document body.&lt;/p&gt;,<br>        document.body<br>      )}<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default MyComponent;</pre><p>In this example:</p><ul><li>The first &lt;p&gt; tag is rendered within the parent &lt;div&gt;.</li><li>The second &lt;p&gt; tag is rendered directly into the document.body using a portal.</li></ul><h3>Practical Uses of createPortal</h3><h4>1. Rendering a Modal Dialog</h4><p>Modals are a common use case for portals. By rendering a modal outside the parent component’s hierarchy, you ensure it can overlay other components without being affected by parent component’s styles.</p><pre>import React, { useState } from &#39;react&#39;;<br>import { createPortal } from &#39;react-dom&#39;;<br><br>function Modal({ children, onClose }) {<br>  return createPortal(<br>    &lt;div className=&quot;modal&quot;&gt;<br>      &lt;div className=&quot;modal-content&quot;&gt;<br>        {children}<br>        &lt;button onClick={onClose}&gt;Close&lt;/button&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;,<br>    document.body<br>  );<br>}<br><br>function App() {<br>  const [isModalOpen, setIsModalOpen] = useState(false);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;button onClick={() =&gt; setIsModalOpen(true)}&gt;Open Modal&lt;/button&gt;<br>      {isModalOpen &amp;&amp; &lt;Modal onClose={() =&gt; setIsModalOpen(false)}&gt;Hello, I&#39;m a modal!&lt;/Modal&gt;}<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><h4>2. Integrating with Non-React DOM Nodes</h4><p>Portals can also help integrate React with existing non-React applications. For instance, if you have a legacy part of your app or a third-party library managing certain DOM nodes, you can use portals to render React components into those nodes.</p><pre>import React, { useRef, useEffect, useState } from &#39;react&#39;;<br>import { createPortal } from &#39;react-dom&#39;;<br><br>function MapComponent() {<br>  const containerRef = useRef(null);<br>  const [popupContainer, setPopupContainer] = useState(null);<br><br>  useEffect(() =&gt; {<br>    if (!containerRef.current) return;<br>    // Simulate creating a popup in a third-party map library<br>    const popupDiv = document.createElement(&#39;div&#39;);<br>    containerRef.current.appendChild(popupDiv);<br>    setPopupContainer(popupDiv);<br>  }, []);<br><br>  return (<br>    &lt;div ref={containerRef} style={{ width: &#39;100%&#39;, height: &#39;400px&#39; }}&gt;<br>      {popupContainer &amp;&amp; createPortal(&lt;p&gt;Hello from React!&lt;/p&gt;, popupContainer)}<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default MapComponent;</pre><h3>Caveats (warnings)</h3><p>While portals are powerful, there are a few caveats to keep in mind:</p><ul><li><strong>Event Bubbling</strong>: Events within portals propagate according to the React tree, not the DOM tree. This means event listeners on parent components will still catch events from within the portal.</li><li><strong>Accessibility</strong>: When creating modals, tooltips, or other overlays, ensure your implementation is accessible.</li></ul><h3>Conclusion</h3><p>React’s createPortal is a versatile feature that helps you render components outside of the main DOM hierarchy, making it perfect for modals, tooltips, and integrating with non-React environments. By understanding how to use createPortal, you can create more dynamic and responsive user interfaces in your React applications.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20ce2f6805d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing Project Structure in Preact]]></title>
            <link>https://medium.com/@thrishakannan25/optimizing-project-structure-in-preact-0885a3d1d8ee?source=rss-0e9448c7c43c------2</link>
            <guid isPermaLink="false">https://medium.com/p/0885a3d1d8ee</guid>
            <category><![CDATA[preact]]></category>
            <dc:creator><![CDATA[Thrishakannan]]></dc:creator>
            <pubDate>Tue, 28 May 2024 18:19:51 GMT</pubDate>
            <atom:updated>2024-05-28T18:19:51.943Z</atom:updated>
            <content:encoded><![CDATA[<p>As someone deeply invested in software development, I’ve come to appreciate the paramount importance of structuring our projects for long-term maintainability and scalability. In this post, let’s embark on a journey delving into the intricacies of organizing a Preact codebase with finesse, shedding light on the pivotal directories: pages and components.</p><h3>The Role of Pages: Where Routes and Components Converge</h3><p>In Preact development, the pages directory serves as the bedrock for defining the different routes of our application. Each page component housed within this directory encapsulates the UI specific to its corresponding route.</p><p>Consider the following directory structure:</p><pre>src/<br>└── pages/<br>    ├── Home.js<br>    ├── About.js<br>    ├── Contact.js<br>    └── ...</pre><p>Here, each file represents a distinct page component, responsible for rendering the content relevant to its route.</p><h3>Crafting Page Components: A Practical Example</h3><p>Let’s dive into creating a simple Home page component:</p><pre>// Home.js<br>import { h } from &#39;preact&#39;;<br><br>function Home() {<br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Welcome to our Website!&lt;/h1&gt;<br>      &lt;p&gt;Discover amazing features and services...&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default Home;</pre><p>Here, { h } is imported from preact. Within the function, {children} refers to the content passed to the Button component as its children. When the Button component is used elsewhere in the codebase, any content placed between the opening and closing tags of the Button component will be passed as children.</p><h3>The Architectural Blueprint: Structuring Your Preact Project</h3><p>To ensure a coherent project structure, consider the following hierarchy:</p><pre>src/<br>├── pages/<br>│   ├── Home.js<br>│   ├── About.js<br>│   ├── Contact.js<br>│   └── ...<br>├── components/<br>│   ├── Button.js<br>│   ├── Navbar.js<br>│   ├── Footer.js<br>│   └── ...<br>├── App.js<br>└── index.js</pre><p>In this layout, App.js emerges as the cornerstone, orchestrating routing and defining the application&#39;s layout, while index.js stands as the entry point of our endeavor.</p><h3>In Conclusion</h3><p>As seasoned developers, we recognize that an efficient project structure is fundamental to the success of our Preact applications. By delineating between pages and components and adhering to a structured approach, we lay the groundwork for codebases that are not only readable and maintainable but also primed for scalability.</p><p>Here’s to crafting Preact applications with elegance and efficiency!</p><p>Happy Coding !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0885a3d1d8ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Breaking Down the Core File in Preact — `index.jsx`]]></title>
            <link>https://medium.com/@thrishakannan25/breaking-down-the-core-file-in-preact-index-jsx-76ab067f8bf9?source=rss-0e9448c7c43c------2</link>
            <guid isPermaLink="false">https://medium.com/p/76ab067f8bf9</guid>
            <category><![CDATA[preactjs]]></category>
            <category><![CDATA[preact]]></category>
            <category><![CDATA[preact-router]]></category>
            <dc:creator><![CDATA[Thrishakannan]]></dc:creator>
            <pubDate>Sat, 25 May 2024 15:47:43 GMT</pubDate>
            <atom:updated>2024-05-25T15:47:43.514Z</atom:updated>
            <content:encoded><![CDATA[<h3>Breaking Down the Core File in Preact — `index.jsx`</h3><p>Welcome back to day two of our 30-day journey into Preact! Today, we’ll dissect the core file of a Preact application, index.jsx, to understand each statement and how it differs from a typical React setup. Let&#39;s dive right in!</p><h4>Importing Essentials</h4><pre><br>import { render } from &#39;preact&#39;;<br>import { LocationProvider, Router, Route } from &#39;preact-iso&#39;;<br><br>import { Header } from &#39;./components/Header.jsx&#39;;<br>import { Home } from &#39;./pages/Home/index.jsx&#39;;<br>import { NotFound } from &#39;./pages/_404.jsx&#39;;<br>import &#39;./style.css&#39;;<br><br>export function App() {<br>    return (<br>        &lt;LocationProvider&gt;<br>            &lt;Header /&gt;<br>            &lt;main&gt;<br>                &lt;Router&gt;<br>                    &lt;Route path=&quot;/&quot; component={Home} /&gt;<br>                    &lt;Route default component={NotFound} /&gt;<br>                &lt;/Router&gt;<br>            &lt;/main&gt;<br>        &lt;/LocationProvider&gt;<br>    );<br>}<br><br>render(&lt;App /&gt;, document.getElementById(&#39;app&#39;));</pre><ol><li>import { render } from &#39;preact&#39;;</li></ol><ul><li>This imports the render function from Preact. Similar to React’s react-dom, Preact uses its own render method to mount components to the DOM. The syntax is nearly identical, making the transition smooth.</li></ul><p>2. import { LocationProvider, Router, Route } from &#39;preact-iso&#39;;</p><ul><li>preact-iso is a library designed for isomorphic applications with Preact, enabling seamless client and server-side rendering.</li><li>LocationProvider manages the application&#39;s location state.</li><li>Router and Route handle the routing within the application, similar to React Router.</li></ul><p>3. Component Imports</p><ul><li>{ Header } from &#39;./components/Header.jsx&#39;;</li><li>{ Home } from &#39;./pages/Home/index.jsx&#39;;</li><li>{ NotFound } from &#39;./pages/_404.jsx&#39;;</li><li>These imports bring in custom components that will be used within the app. Header, Home, and NotFound are typical examples of components you’d use to structure an application.</li></ul><p>4. import &#39;./style.css&#39;;</p><ul><li>This imports the CSS file for global styles. In Preact, you can manage styles similarly to how you do in React, using either global CSS files or CSS-in-JS libraries.</li></ul><h4>The App Component</h4><ol><li>Function Declaration</li></ol><ul><li>export function App() { ... } defines and exports the App component. This is a functional component, similar to React’s functional components.</li></ul><p>2. LocationProvider</p><ul><li>Wrapping the application in LocationProvider ensures that the location state is available to all components, enabling dynamic routing.</li></ul><p>3. Header Component</p><ul><li>&lt;Header /&gt; is a custom component that likely contains navigation elements or a site header. It&#39;s placed outside of the Router so it appears on every page.</li></ul><p>4. Main and Router</p><ul><li>&lt;main&gt; contains the Router component, which manages the different routes in the application.</li><li>&lt;Router&gt; handles the routing logic.</li><li>&lt;Route path=&quot;/&quot; component={Home} /&gt; defines the root route, which renders the Home component.</li><li>&lt;Route default component={NotFound} /&gt; catches all undefined routes and renders the NotFound component.</li></ul><h3>Rendering the App</h3><p>render(&lt;App /&gt;, document.getElementById(&#39;app&#39;)); mounts the App component to the DOM. This is equivalent to React’s ReactDOM.render(&lt;App /&gt;, document.getElementById(&#39;app&#39;));, but uses Preact’s render method.</p><p>How It Works Together: The render function takes the App component and mounts it into the HTML element with the ID app. check the file index.html .</p><h3>Why Use Pages and Components Folders?</h3><h4>Components Folder</h4><ul><li>Purpose: To store reusable UI components that can be used across multiple pages or parts of the application.</li><li>Typical Files: Individual component files like Header.jsx, Footer.jsx, Button.jsx, and other UI elements.</li></ul><h4>Pages Folder</h4><ul><li>Purpose: To store page-specific components that represent different routes in the application.</li><li>Typical Files: Page components like Home.jsx, About.jsx, Contact.jsx, and other full-page views.</li></ul><h3>Conclusion</h3><p>Understanding the structure and purpose of the core files and folders in a Preact application is crucial for maintaining a clean and organized codebase. By separating components and pages, we ensure that our project remains modular, scalable, and easier to manage.</p><p>Stay tuned for tomorrow’s post, where we’ll dive deeper into customizing your Preact project. Follow me on <a href="https://www.linkedin.com/in/thrishakannan/">LinkedIn</a>, <a href="https://lnkd.in/gFEPsd_n">Medium</a>, and for daily updates and more coding tips.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76ab067f8bf9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Discovering Preact: A Journey into Lightweight JavaScript]]></title>
            <link>https://medium.com/@thrishakannan25/discovering-preact-a-journey-into-lightweight-javascript-39e779c46725?source=rss-0e9448c7c43c------2</link>
            <guid isPermaLink="false">https://medium.com/p/39e779c46725</guid>
            <category><![CDATA[preact]]></category>
            <category><![CDATA[preactjs]]></category>
            <dc:creator><![CDATA[Thrishakannan]]></dc:creator>
            <pubDate>Fri, 24 May 2024 15:29:04 GMT</pubDate>
            <atom:updated>2024-05-25T14:56:37.907Z</atom:updated>
            <content:encoded><![CDATA[<p>I’m a web developer, always juggling between optimizing performance and keeping my codebase clean. I’ve worked with React, and while it’s incredibly powerful, the hefty bundle size often slows things down. Then one day, I stumbled upon Preact — a lightweight alternative that promises the same power but at a fraction of the size. Curious, I decided to dive in and explore this new tool. Welcome to day one of my 30-day adventure into the world of Preact!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2KSOsW3awWQ7ujrd5axX4Q.png" /></figure><h4>What is Preact?</h4><p>Preact is a fast, lightweight JavaScript library for building user interfaces, offering a similar API to React but with a much smaller footprint. With Preact, you get all the benefits of React’s component-based architecture and virtual DOM, but in a package that’s only about 3 KB (gzip). This makes Preact an excellent choice for performance-critical applications, mobile web apps, and Progressive Web Apps (PWAs).</p><h4>Why Choose Preact?</h4><p>Here are some compelling reasons to consider Preact for your next project:</p><ol><li><strong>Small Size</strong>: Preact’s tiny size means faster load times and better performance, especially important for mobile users and slow networks.</li><li><strong>Familiar API</strong>: If you know React, you already know Preact. The API is nearly identical, making it easy to switch or integrate.</li><li><strong>Compatibility</strong>: With the preact/compat module, you can use many React libraries and components, ensuring a smooth transition.</li><li><strong>Performance</strong>: Preact’s performance optimizations, such as its small virtual DOM implementation, make it highly efficient for rendering.</li></ol><h4>Setting Up Your Development Environment</h4><p>Let’s get started by setting up a Preact project. Follow these simple steps:</p><ol><li><strong>Install Node.js</strong>: Ensure you have Node.js installed. You can download it from <a href="https://nodejs.org/">nodejs.org</a>.</li><li><strong>Create a New Preact Project</strong>: Use the Preact CLI to create a new project quickly.</li></ol><pre>npx preact-cli create default my-preact-app<br>cd my-preact-app<br>npm install<br>npm start<br><br>or<br><br>npm init preact<br>cd &lt;your preact-app name&gt;<br>npm run dev</pre><p>3. <strong>Project Structure</strong>: Familiarize yourself with the project structure. The default setup includes everything you need to start building.</p><pre>my-preact-app/<br>├── node_modules/<br>├── src/<br>│   ├── components/<br>│   │   └── app.js<br>│   ├── index.js<br>│   └── style/<br>├── template.html<br>├── .gitignore<br>├── package.json<br>└── README.md</pre><h4>Key Features of Preact</h4><ol><li><strong>Component-Based Architecture</strong>: Like React, Preact promotes the creation of reusable components, which makes your code more modular and maintainable.</li><li><strong>Virtual DOM</strong>: Preact’s virtual DOM ensures efficient updates, rendering only the parts of the UI that have changed.</li><li><strong>Event Handling</strong>: Handling events in Preact is straightforward and works similarly to React, making it easy to create interactive UIs.</li></ol><h4>A Simple Preact Component</h4><p>Here’s a quick example of a simple Preact component to get you started:</p><pre>import { h, render, Component } from &#39;preact&#39;;<br><br>class App extends Component {<br>  render() {<br>    return &lt;h1&gt;Hello, Preact!&lt;/h1&gt;;<br>  }<br>}<br><br>render(&lt;App /&gt;, document.body);</pre><p>In this example, we import h, render, and Component from Preact, define a simple App component, and render it to the document.body.</p><h4>Conclusion</h4><p>Preact is a powerful tool for developers who want the benefits of React’s ecosystem but need a lighter, faster alternative. Over the next 30 days, we will explore various aspects of Preact, from basic concepts to advanced techniques, and build real-world applications.</p><p>Stay tuned for tomorrow’s post, where we’ll dive into setting up your first Preact project in more detail. Follow me on <a href="https://www.linkedin.com/in/thrishakannan">LinkedIn</a> for daily updates and more coding tips.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39e779c46725" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>