<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aneesh</title>
    <description>The latest articles on DEV Community by Aneesh (@varadan13).</description>
    <link>https://dev.to/varadan13</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F688017%2F7be4af06-6402-4583-86ab-ff1fec1518f5.png</url>
      <title>DEV Community: Aneesh</title>
      <link>https://dev.to/varadan13</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/varadan13"/>
    <language>en</language>
    <item>
      <title>Understanding useSyncExternalStore Through Some Examples</title>
      <dc:creator>Aneesh</dc:creator>
      <pubDate>Sat, 21 Jun 2025 13:19:41 +0000</pubDate>
      <link>https://dev.to/varadan13/understanding-usesyncexternalstore-through-some-examples-4m7c</link>
      <guid>https://dev.to/varadan13/understanding-usesyncexternalstore-through-some-examples-4m7c</guid>
      <description>&lt;p&gt;useSyncExternalStore is a React Hook that lets you subscribe to an external store.&lt;/p&gt;

&lt;p&gt;First, let’s create a useOnlineStatus hook which automatically tracks whether the user’s device is online or offline.&lt;/p&gt;

&lt;p&gt;useOnlineStatus&lt;br&gt;
To use useSyncExternalStore and create useOnlineStatus, we need the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A store&lt;/li&gt;
&lt;li&gt;A subscribe function that invokes a callback provided by React when the state inside the store changes&lt;/li&gt;
&lt;li&gt;A function that returns a snapshot of the current state from the store&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s create the store:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
let currentNetworkStatus = {
    online: navigator.onLine,
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s create the subscribe function:&lt;/p&gt;

&lt;p&gt;The requirement for this function is that it accepts a callback, listens for state changes within the store, and returns a function that, when invoked, unsubscribes from listening to state changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(callback) =&amp;gt; {
        const update = () =&amp;gt; {
            const newStatus = { online: navigator.onLine };
            if (newStatus.online !== currentNetworkStatus.online) {
                currentNetworkStatus = newStatus;
                callback();
            }
        };
        window.addEventListener("online", update);
        window.addEventListener("offline", update);
        return () =&amp;gt; {
            window.removeEventListener("online", update);
            window.removeEventListener("offline", update);
        };
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s create the snapshot function:&lt;/p&gt;

&lt;p&gt;This function will just return the latest state from the store.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;() =&amp;gt; currentNetworkStatus.online
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s pack the subscribe fn and the snapshot fn into an object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const network = {
    getSnapshot: () =&amp;gt; currentNetworkStatus,
    subscribe: (callback) =&amp;gt; {
        const update = () =&amp;gt; {
            const newStatus = { online: navigator.onLine };
            if (newStatus.online !== currentNetworkStatus.online) {
                currentNetworkStatus = newStatus;
                callback();
            }
        };
        window.addEventListener("online", update);
        window.addEventListener("offline", update);
        return () =&amp;gt; {
            window.removeEventListener("online", update);
            window.removeEventListener("offline", update);
        };
    },
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now finally the useOnlineStatus:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const useOnlineStatus = () =&amp;gt; {

    const globalState = useSyncExternalStore(
        (cb) =&amp;gt; network.subscribe(cb),
        () =&amp;gt; network.getSnapshot()
    );

    return globalState
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, let’s construct a usePageFocus hook that returns true if the page is focused and false if it is not.&lt;/p&gt;

&lt;p&gt;usePageFocus&lt;br&gt;
Following what we did for useOnlineStatus.&lt;/p&gt;

&lt;p&gt;Let’s first create a store:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
let focusState = {
  focused: document.hasFocus(),
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s create the subscribe fn:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(callback) =&amp;gt; {
    const update = () =&amp;gt; {
      const newFocus = { focused: document.hasFocus() };
      if (newFocus.focused !== focusState.focused) {
        focusState = newFocus;
        callback();
      }
    };

    window.addEventListener("focus", update);
    window.addEventListener("blur", update);

    return () =&amp;gt; {
      window.removeEventListener("focus", update);
      window.removeEventListener("blur", update);
    };
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s create the snapshot fn:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;() =&amp;gt; focusState.focused
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, bringing it all together, first by packing the snapshot fn and subscribe fn into an object and then creating the hook.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const pageFocus = {
  getSnapshot: () =&amp;gt; focusState,
  subscribe: (callback) =&amp;gt; {
    const update = () =&amp;gt; {
      const newFocus = { focused: document.hasFocus() };
      if (newFocus.focused !== focusState.focused) {
        focusState = newFocus;
        callback();
      }
    };

    window.addEventListener("focus", update);
    window.addEventListener("blur", update);

    return () =&amp;gt; {
      window.removeEventListener("focus", update);
      window.removeEventListener("blur", update);
    };
  },
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, the usePageFocus hook:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const usePageFocus = () =&amp;gt; {

    const globalState = useSyncExternalStore(
        (cb) =&amp;gt; pageFocus.subscribe(cb),
        () =&amp;gt; pageFocus.getSnapshot()
    );

    return globalState
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, moving onto the mother of all hooks in this blog, the useGlobalState hook&lt;/p&gt;

&lt;p&gt;useGlobalState hook&lt;/p&gt;

&lt;p&gt;This hook works similar to the zustand api. For example:&lt;/p&gt;

&lt;p&gt;we can create a hook to work with the loggedInUser state in a single file and then import it into any component without using providers or having us prop drill the state and state setter function into components.&lt;/p&gt;

&lt;p&gt;Example implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const useLoggedInUser = () =&amp;gt; {
    const [loggedInUser, setLoggedInUser] = useGlobalState("loggedInUser", {})

    return [loggedInUser, setLoggedInUser]
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So let’s now build the useGlobalState.&lt;/p&gt;

&lt;p&gt;under the hood it is all useSyncExternalStore&lt;/p&gt;

&lt;p&gt;Let’s continue the way we built usePageFocus and useOnlineStatus.&lt;/p&gt;

&lt;p&gt;First the store:&lt;/p&gt;

&lt;p&gt;We can implement the store like a simple Map.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const store = new Map();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s implement the subscribe function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const subscribeToStore = (key, listener) =&amp;gt; {
    const entry = store.get(key);
    if (!entry) return () =&amp;gt; { };
    entry.listeners.add(listener);
    return () =&amp;gt; entry.listeners.delete(listener);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function allows components to subscribe to changes in specific pieces of global state and get notified when that state changes.&lt;/p&gt;

&lt;p&gt;The second param in the above function will be directly passed by React when specific pieces of global state changes, all thanks to useSyncExternalStore magic.&lt;/p&gt;

&lt;p&gt;Now let’s implement the getSnapShot function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const getSnapshotFromStore = (key) =&amp;gt; {
    const entry = store.get(key)
    return entry?.value
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let’s put all these pieces together to create the magic hook useGlobalState:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const useGlobalState = (key, initialValue) =&amp;gt; {

    initializeStateInStore(key, initialValue);

    const globalState = useSyncExternalStore(
        (cb) =&amp;gt; subscribeToStore(key, cb),
        () =&amp;gt; getSnapshotFromStore(key)
    );

    return [globalState, (newValue) =&amp;gt; setStateInStore(key, newValue)]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that there are two function in the useGlobalState that we have not yet seen in this blog: initializeStateInStore, setStateInStore&lt;/p&gt;

&lt;p&gt;initializeStateInStore is used to add an entry into the map as and when we initialize a new state and it is implemented like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const initializeStateInStore = (key, initial) =&amp;gt; {
    if (!store.has(key)) {
        store.set(key, {
            value: initial,
            listeners: new Set(),
        })
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;setStateInStore is a function that changes values in the global store and notifies all subscribers and it is implemented like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const setStateInStore = (key, newValue) =&amp;gt; {
    const entry = store.get(key)
    if (entry) {
        entry.value = newValue;
        entry.listeners.forEach((fn) =&amp;gt; fn());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So there we have it the useGlobalState function.&lt;/p&gt;

&lt;p&gt;So that’s it for today, guys. We’ve looked at some example usages of useSyncExternalStore in React.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Polyfill for Array.isArray</title>
      <dc:creator>Aneesh</dc:creator>
      <pubDate>Sat, 21 Jun 2025 13:09:48 +0000</pubDate>
      <link>https://dev.to/varadan13/polyfill-for-arrayisarray-38ei</link>
      <guid>https://dev.to/varadan13/polyfill-for-arrayisarray-38ei</guid>
      <description>&lt;p&gt;The below code provides a fallback implementation for Array.isArray() in environments where it might not be available (older browsers or JavaScript environments).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;nativeIsArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isArray&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;toString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nativeIsArray&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;isArray&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;isArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;[object Array]&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>howto</category>
      <category>tooling</category>
    </item>
    <item>
      <title>Polyfill for a function to check if a value is a string!</title>
      <dc:creator>Aneesh</dc:creator>
      <pubDate>Sat, 21 Jun 2025 13:08:35 +0000</pubDate>
      <link>https://dev.to/varadan13/polyfill-for-a-function-to-check-if-a-value-is-a-string-351d</link>
      <guid>https://dev.to/varadan13/polyfill-for-a-function-to-check-if-a-value-is-a-string-351d</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;toString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;isString&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;isString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;[object String]&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>howto</category>
      <category>tooling</category>
    </item>
    <item>
      <title>How I Optimized Huys Kitchen's Website by Serving Images with Exact Size</title>
      <dc:creator>Aneesh</dc:creator>
      <pubDate>Thu, 08 Feb 2024 04:26:58 +0000</pubDate>
      <link>https://dev.to/varadan13/how-i-optimized-huys-kitchens-website-by-serving-images-with-exact-size-51em</link>
      <guid>https://dev.to/varadan13/how-i-optimized-huys-kitchens-website-by-serving-images-with-exact-size-51em</guid>
      <description>&lt;p&gt;In the world of web development, optimizing website performance is a key factor for user satisfaction. Recently, I took on the challenge of enhancing the performance of &lt;a href="https://www.huyskitchen.com.au/"&gt;Huys Kitchen's website&lt;/a&gt; by focusing on image optimization. This blog post details the tools I used, the steps taken, and the remarkable results achieved.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tools Utilized:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;PageSpeed Index:&lt;/strong&gt;&lt;br&gt;
To gauge the website's performance and identify areas for improvement, I employed the &lt;a href="https://pagespeed.web.dev/"&gt;PageSpeed Index&lt;/a&gt;. This tool provided valuable insights and a performance report that served as a benchmark for the optimization process.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ImageMagick CLI Tool:&lt;/strong&gt;&lt;br&gt;
For image resizing, I turned to the powerful &lt;a href="https://www.imagemagick.org/script/index.php"&gt;ImageMagick CLI tool&lt;/a&gt;. This versatile tool allows for efficient manipulation of images, making it an ideal choice for our optimization efforts.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Performance Assessment Before Optimization:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before diving into the optimization process, I conducted a thorough performance analysis using PageSpeed Index. The initial report can be viewed &lt;a href="https://pagespeed.web.dev/analysis/https-www-huyskitchen-com-au/dfkizz69ko?form_factor=mobile"&gt;here&lt;/a&gt;. This served as a baseline to measure the impact of the changes made.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Optimization Steps:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The primary focus of the optimization was on resizing images to match the exact dimensions they were rendered on the page. To accomplish this, I utilized the ImageMagick CLI tool to efficiently resize and serve images tailored to their display requirements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance Assessment After Optimization:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The results post-optimization were nothing short of impressive. The updated performance report can be accessed &lt;a href="https://pagespeed.web.dev/analysis/https-www-huyskitchen-com-au/ridynt0021?form_factor=mobile"&gt;here&lt;/a&gt;. Witnessing the improvements firsthand, it became evident that serving images with exact dimensions significantly enhanced the website's load time and overall user experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Optimizing a website involves a combination of strategic choices and the right tools. In the case of Huys Kitchen, focusing on image optimization using the ImageMagick CLI tool proved to be a game-changer. The journey from the initial performance analysis to implementing changes and witnessing the positive impact on load times emphasizes the importance of meticulous optimization in delivering a seamless online experience.&lt;/p&gt;

&lt;p&gt;update&lt;/p&gt;

&lt;p&gt;This is the performance report I got after minifying the javascript and css files (report)[&lt;a href="https://pagespeed.web.dev/analysis/https-www-huyskitchen-com-au/zgvki2mqrr?form_factor=desktop"&gt;https://pagespeed.web.dev/analysis/https-www-huyskitchen-com-au/zgvki2mqrr?form_factor=desktop&lt;/a&gt;]&lt;/p&gt;

</description>
      <category>performance</category>
      <category>web</category>
      <category>html</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Enhancing SEO with Slugs: A Better Approach for URL Composition</title>
      <dc:creator>Aneesh</dc:creator>
      <pubDate>Wed, 24 Jan 2024 08:52:50 +0000</pubDate>
      <link>https://dev.to/varadan13/enhancing-seo-with-slugs-a-better-approach-for-url-composition-1kjb</link>
      <guid>https://dev.to/varadan13/enhancing-seo-with-slugs-a-better-approach-for-url-composition-1kjb</guid>
      <description>&lt;p&gt;In the world of web development, constructing URLs plays a crucial role in creating user-friendly and search engine optimized applications. When it comes to displaying details of objects from a database, choosing the right field for URL composition becomes a critical decision. In this blog post, we'll explore why using slugs is a superior option compared to other fields, using the example of a MongoDB database storing place details.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Challenge: Choosing the Right Field
&lt;/h2&gt;

&lt;p&gt;Consider a MongoDB database with a place object containing properties such as name, address, id, otherdetails, and images. Traditionally, developers might opt to use the id or name fields for URL composition. However, each approach has its drawbacks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using &lt;code&gt;id&lt;/code&gt;: SEO Unfriendly
&lt;/h3&gt;

&lt;p&gt;While using the id seems logical for ensuring a unique URL, it lacks meaning. Search engines prefer URLs that provide context and relevance to the content. A URL with just an arbitrary ID does little to enhance SEO.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using name: Potential Pitfalls
&lt;/h3&gt;

&lt;p&gt;On the other hand, using the name field seems more user-friendly, as it provides a meaningful URL. However, names can be problematic. They might contain spaces, special characters, and varying capitalization. URLs with such elements are not considered best practice, as they can lead to inconsistencies and SEO challenges.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution: Introducing Slugs
&lt;/h2&gt;

&lt;p&gt;To address these challenges, a better solution is to introduce a new field in the place object called a slug. A slug is a URL-friendly version of a string, typically generated by transforming the original string into a format that eliminates spaces, special characters, and capitalization issues.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages of Using Slugs
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;SEO-Friendly URLs&lt;/strong&gt;: Slugs provide URLs that are meaningful, descriptive, and optimized for search engines.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Consistency&lt;/strong&gt;: Since slugs are generated algorithmically, they ensure consistency and predictability in URLs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;User Experience&lt;/strong&gt;: Slugs contribute to a better user experience by creating clean and readable URLs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Avoiding Special Character Issues&lt;/strong&gt;: Slugs eliminate the problems associated with special characters and capitalization in URLs.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;In conclusion, using slugs for URL composition in web applications, particularly when dealing with database objects like places, is a wise choice. It strikes a balance between meaningful URLs for users and SEO-friendly practices for search engines. By implementing slugs, developers can create a more polished and professional web experience. So, the next time you're faced with the decision of which field to use in your URLs, consider the benefits that slugs bring to the table.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>A Simple Way to Expose Internal Component State in React</title>
      <dc:creator>Aneesh</dc:creator>
      <pubDate>Wed, 11 Oct 2023 15:28:29 +0000</pubDate>
      <link>https://dev.to/varadan13/a-simple-way-to-expose-internal-component-state-in-react-16nh</link>
      <guid>https://dev.to/varadan13/a-simple-way-to-expose-internal-component-state-in-react-16nh</guid>
      <description>&lt;p&gt;Consider a scenario where you have a DatePicker component with its internal state, and you want to provide a way for external components to access this state. This can be achieved by creating a callback function, often referred to as a prop, to allow external components to interact with the DatePicker. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;DatePicker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;maxDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;maxDateValue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;log&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;consumeDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;consumeDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Expose the initial value&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Date picker value...&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Container&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Calendar&lt;/span&gt;
        &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vl&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="nx"&gt;consumeDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vl&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Expose the updated value&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;minDate&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;maxDate&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;maxDate&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Container&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the DatePicker component provides a consumeDate prop that external components can use to access the internal state of the component. This approach facilitates sharing the component's state and opens the door to numerous possibilities.&lt;/p&gt;

&lt;p&gt;Here's how this works:&lt;/p&gt;

&lt;p&gt;The consumeDate prop is passed to the DatePicker component, which is a function that can be defined in any parent component.&lt;/p&gt;

&lt;p&gt;Inside the DatePicker component, this function is called during initialization and whenever the date value changes. This allows external components to observe the initial and updated values.&lt;/p&gt;

&lt;p&gt;The onChange event of the Calendar component triggers the update of the internal state (value) in the DatePicker. It also calls consumeDate, exposing the new value.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>README : add viewport meta tag</title>
      <dc:creator>Aneesh</dc:creator>
      <pubDate>Thu, 14 Sep 2023 05:12:25 +0000</pubDate>
      <link>https://dev.to/varadan13/readme-add-viewport-meta-tag-15kb</link>
      <guid>https://dev.to/varadan13/readme-add-viewport-meta-tag-15kb</guid>
      <description>&lt;p&gt;&lt;strong&gt;What happens without the viewport meta tag?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some mobile devices and other narrow screens render pages in a virtual window or viewport, which is usually wider than the screen, and then shrink the rendered result down so it can all be seen at once. Users can then pan and zoom to see different areas of the page. For example, if a mobile screen has a width of 640px, pages might be rendered with a virtual viewport of 980px, and then it will be shrunk down to fit into the 640px space.&lt;/p&gt;

&lt;p&gt;This mechanism is not so good for pages that are optimized for narrow screens using media queries — if the virtual viewport is 980px, for example, media queries that kick in at 640px or 480px or less will never be used, limiting the effectiveness of such responsive design technique.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is the purpose of the viewport meta tag?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The viewport meta tag mitigates this problem of virtual viewport on narrow screen devices.&lt;/p&gt;

&lt;p&gt;The width=device-width part sets the width of the page to follow the screen width of the device (which will vary depending on the device).&lt;/p&gt;

&lt;p&gt;The initial-scale=1.0 part sets the initial zoom level when the page is first loaded by the browser.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Mastering the Art of Flash Card Study: A Fun and Effective Learning Technique</title>
      <dc:creator>Aneesh</dc:creator>
      <pubDate>Wed, 13 Sep 2023 07:00:21 +0000</pubDate>
      <link>https://dev.to/varadan13/mastering-the-art-of-flash-card-study-a-fun-and-effective-learning-technique-3kgf</link>
      <guid>https://dev.to/varadan13/mastering-the-art-of-flash-card-study-a-fun-and-effective-learning-technique-3kgf</guid>
      <description>&lt;p&gt;Flash cards are simple tools that can be created using paper and pen or digitally through software like PowerPoint. They offer a dynamic and engaging way to learn, making the process not only efficient but also enjoyable. In this blog post, we will explore how to use flash cards effectively for studying and why they are a valuable addition to your study routine.&lt;/p&gt;

&lt;p&gt;Creating Flash Cards&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Choose Your Format:&lt;/strong&gt; Flash cards can be made on paper or digitally using software like PowerPoint. Both methods have their advantages. Paper cards are tactile and can be carried anywhere, while digital cards offer the convenience of easy access and customization.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Question and Answer:&lt;/strong&gt; The fundamental principle of a flash card is to have a question on one side and the answer on the other. Keep your questions clear and concise.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Utilize PowerPoint:&lt;/strong&gt; If you're using PowerPoint, create a default slide layout where you put the question in the title field and the answer in the text field. To enhance the learning experience, you can animate the slides so that the question appears first and then reveal the answer when you're ready.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The Benefits of Flash Card Study&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Active Learning:&lt;/strong&gt; Flash cards turn passive reading into an active learning experience. Instead of passively reading through pages of text, you engage with the material by recalling and testing your knowledge.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enhanced Memorization:&lt;/strong&gt; Flash cards are particularly effective for memorizing essential facts and concepts. For instance, questions like "How do we represent pseudo-classes in CSS?" are ideal for flash cards. You don't need to include all the intricate details; the goal is to capture the basics.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Spaced Repetition:&lt;/strong&gt; Revisiting flash cards at intervals helps reinforce your memory. It leverages the concept of spaced repetition, which optimizes learning by reviewing material at increasing intervals over time. This method improves long-term retention.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Focus on Outlines:&lt;/strong&gt; While learning, it's essential to understand the fundamental concepts. Flash cards can help you remember the outlines of what you've studied, even if you forget the finer details. This ability to recall the basics is valuable when tackling complex subjects.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;Incorporating flash cards into your study routine can make the learning process more enjoyable and efficient. They promote active learning, enhance memorization of essential facts, and leverage spaced repetition to improve retention. Remember that the main purpose of flash cards is to capture basic facts and outlines. Understanding the fundamental concepts and allowing your brain to forget them, only to revisit and relearn them, is a powerful technique for long-term retention.&lt;/p&gt;

&lt;p&gt;So, whether you're a student preparing for exams or someone looking to expand your knowledge, consider incorporating flash cards into your learning toolkit. They're a simple yet effective way to make your study sessions more engaging and productive. Happy learning!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>A simple way to deal with closure over a stale state in React code</title>
      <dc:creator>Aneesh</dc:creator>
      <pubDate>Fri, 08 Sep 2023 08:08:19 +0000</pubDate>
      <link>https://dev.to/varadan13/a-simple-way-to-deal-with-closure-over-a-stale-state-in-react-code-3hjh</link>
      <guid>https://dev.to/varadan13/a-simple-way-to-deal-with-closure-over-a-stale-state-in-react-code-3hjh</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;stateA&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setStateA&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;A&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;setInterval&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;stateA&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;A&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;doSomethingElse&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;60000&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code stateA is a React state which can change based on user actions but the reference to stateA withint the callback of setInterval remains always set to the value "A" which is problematic. &lt;/p&gt;

&lt;p&gt;Why does this happen? The setInterval callback captures the value of stateA when it is created, and it does not automatically update when stateA changes. This is known as a closure over a stale state.&lt;/p&gt;

&lt;p&gt;We can tackle this issue by using a ref. Here is how.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;stateA&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setStateA&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;A&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stateARef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;stateARef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;stateA&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;setInterval&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;stateARef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;A&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;doSomethingElse&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;60000&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What is happening here?&lt;/p&gt;

&lt;p&gt;In this version, we create a stateARef using React.useRef(), and then immediately assign the current value of stateA to stateARef.current. By doing this, we ensure that stateARef.current always reflects the latest value of stateA, even within the setInterval callback.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to detect if a website is running on a webview?</title>
      <dc:creator>Aneesh</dc:creator>
      <pubDate>Fri, 08 Sep 2023 07:22:00 +0000</pubDate>
      <link>https://dev.to/varadan13/how-to-detect-if-a-website-is-running-on-a-webview-36dl</link>
      <guid>https://dev.to/varadan13/how-to-detect-if-a-website-is-running-on-a-webview-36dl</guid>
      <description>&lt;p&gt;Step 1 - Customise the userAgent string of the webview. Below is an example from React-Native&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;WebView&lt;/span&gt;
  &lt;span class="na"&gt;userAgent&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;web-view-user-agent-123&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;   
  &lt;span class="na"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;WEBVIEW&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; 
  &lt;span class="na"&gt;automaticallyAdjustContentInsets&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="na"&gt;source&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we're setting the UserAgent to "web-view-user-agent-123". This is the UserAgent that will be sent with HTTP requests made by the WebView.&lt;/p&gt;

&lt;p&gt;Step 2 - read this userAgent string in the client side code of the website.&lt;/p&gt;

&lt;p&gt;We can read the userAgent string in the client side code of the website by&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userAgent&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;web-view-user-agent-123&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;the website is embedded in a webview&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;the website is not in a webview&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Conclusion:&lt;/p&gt;

&lt;p&gt;This simple yet powerful technique can be used in various scenarios, such as tracking user activity, implementing custom logic, or providing a personalized experience to users within your WebView. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Possible reasons for slow page transitions in NextJS</title>
      <dc:creator>Aneesh</dc:creator>
      <pubDate>Thu, 31 Aug 2023 04:29:08 +0000</pubDate>
      <link>https://dev.to/varadan13/possible-reasons-for-slow-page-transitions-in-nextjs-33dp</link>
      <guid>https://dev.to/varadan13/possible-reasons-for-slow-page-transitions-in-nextjs-33dp</guid>
      <description>&lt;p&gt;Page transitions in Next.js can take longer than expected for several reasons. It's important to analyze and address potential bottlenecks to optimize the performance of your Next.js application. Here are some common reasons and possible solutions:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Slow Server-Side Rendering (SSR) or Generation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If your pages have complex rendering logic, require heavy data fetching, or involve a lot of dynamic content, they might take longer to render. Consider optimizing your data fetching methods, using memoization, and improving your server's response time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inefficient Data Fetching:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Data fetching methods like &lt;code&gt;getServerSideProps&lt;/code&gt;, &lt;code&gt;getStaticProps&lt;/code&gt;, or &lt;code&gt;useEffect&lt;/code&gt; on the client-side can impact performance. Ensure that you're only fetching the data that's essential for the initial view and avoid unnecessary fetching or computations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Large Assets:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Large images, videos, or other media assets can slow down page loading. Optimize and compress your assets to reduce their size and improve loading times.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Slow API Calls:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If your page relies on external APIs, slow responses from these APIs can delay page rendering. Consider implementing caching strategies, error handling, and loading indicators to provide a better user experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript Bundle Size:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A large JavaScript bundle can slow down client-side rendering. Use code splitting and dynamic imports to load only the necessary JavaScript for a specific page. Additionally, minify and gzip your JavaScript files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Client-Side Rendering (CSR) Delays:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you heavily rely on CSR, it might take time for JavaScript to execute and render on the client side, especially if the client has slower devices or limited resources. Consider using server-side rendering or static site generation for better performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Third-Party Libraries:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Third-party libraries can impact your page performance. Evaluate whether all libraries are necessary and if there are lighter alternatives that can be used.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Poorly Optimized CSS:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Large or unoptimized CSS files can slow down page rendering. Use techniques like critical CSS, CSS minification, and CSS-in-JS to optimize your styles.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Network Latency:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;High network latency can affect the time it takes to load assets, data, and resources. Use CDNs and server locations closer to your target audience to reduce network latency.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Server Load and Scaling:&lt;/strong&gt;&lt;br&gt;
If your server is overloaded or not appropriately scaled, it can lead to slow rendering times. Monitor your server's performance, and consider using tools like load balancers and autoscaling.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Simple custom hook to figure out which state change triggered an effect in React</title>
      <dc:creator>Aneesh</dc:creator>
      <pubDate>Thu, 17 Aug 2023 06:05:37 +0000</pubDate>
      <link>https://dev.to/varadan13/simple-custom-hook-to-figure-which-state-change-triggered-an-effect-in-react-1d82</link>
      <guid>https://dev.to/varadan13/simple-custom-hook-to-figure-which-state-change-triggered-an-effect-in-react-1d82</guid>
      <description>&lt;p&gt;In React applications, the useEffect hook is a powerful tool for handling side effects and component lifecycle events. However, sometimes you might find it useful to know which specific props triggered an useEffect callback. This can be particularly handy when dealing with optimizations or debugging. In this blog post, we'll explore a custom hook named useWhichPropsChanged that allows you to easily identify the props responsible for triggering an useEffect call.&lt;/p&gt;

&lt;p&gt;The Custom Hook - useWhichPropsChanged:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useWhichPropsChanged&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;initialProps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;propsRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;initialProps&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentProps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pKeys&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;propsRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;pKeys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;ele&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;propsRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;ele&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;currentProps&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;ele&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`prop &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;ele&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; has changed...`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="nx"&gt;propsRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;currentProps&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the Hook in a Component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;propsRequiredForSomeApiCall&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;whichPropsChanged&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useWhichPropsChanged&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;propsRequiredForSomeApiCall&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;whichPropsChanged&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;propsRequiredForSomeApiCall&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// Perform some API call or other side effects&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;propsRequiredForSomeApiCall&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&amp;gt;&amp;lt;/&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How It Works:&lt;br&gt;
The useWhichPropsChanged hook utilizes React's useRef to store a reference to the previous props. The returned function takes the current props as an argument and iterates over the keys of the stored props. If the current value of a prop differs from the stored value, a log message is generated indicating which prop has changed. After processing, the stored props are updated to match the current props, allowing for future comparisons.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
