<?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 Darshana Prachi on Medium]]></title>
        <description><![CDATA[Stories by Darshana Prachi on Medium]]></description>
        <link>https://medium.com/@prachirai?source=rss-cf2f865b371a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jkfqz2tolk1iF1qQVzLE0A.jpeg</url>
            <title>Stories by Darshana Prachi on Medium</title>
            <link>https://medium.com/@prachirai?source=rss-cf2f865b371a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 09:43:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@prachirai/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[Why You Might Not Need an Effect: Optimizing React Components]]></title>
            <link>https://prachirai.medium.com/why-you-might-not-need-an-effect-optimizing-react-components-703792738ba3?source=rss-cf2f865b371a------2</link>
            <guid isPermaLink="false">https://medium.com/p/703792738ba3</guid>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[react-optimization]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[useeffect]]></category>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Darshana Prachi]]></dc:creator>
            <pubDate>Fri, 10 May 2024 04:43:33 GMT</pubDate>
            <atom:updated>2024-05-10T04:43:33.940Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*wPMawgFUvHkTa_JvXt3xjg.png" /></figure><p>In modern React development, the useEffect Hook is a powerful tool. However, it’s often overused or misused, leading to unnecessary complexity and potential performance issues. Instead of always reaching for useEffect, there are alternatives worth considering. This article explores those alternatives and provides practical coding examples.</p><h3>Common Misuse Cases</h3><h3>1. Synchronizing State</h3><p>A common use case is synchronizing state variables. But React’s onChange and other event handlers can handle most state updates directly.</p><p>Incorrect Example:</p><pre>import { useState, useEffect } from &#39;react&#39;;<br><br>function Counter() {<br>  const [count, setCount] = useState(0);<br>  const [double, setDouble] = useState(0);<br><br>  useEffect(() =&gt; {<br>    setDouble(count * 2); // Side effect to compute double<br>  }, [count]);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Increment&lt;/button&gt;<br>      &lt;p&gt;Count: {count}&lt;/p&gt;<br>      &lt;p&gt;Double: {double}&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Optimized Solution:</p><pre>import { useState } from &#39;react&#39;;<br><br>function Counter() {<br>  const [count, setCount] = useState(0);<br><br>  const double = count * 2; // Compute directly without useEffect<br><br>  return (<br>    &lt;div&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Increment&lt;/button&gt;<br>      &lt;p&gt;Count: {count}&lt;/p&gt;<br>      &lt;p&gt;Double: {double}&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h3>2. Fetching Data</h3><p>Fetching data in useEffect is necessary but can often be simplified by using a data-fetching library like react-query or even React&#39;s new Server Components.</p><p>Incorrect Example:</p><pre>import { useState, useEffect } from &#39;react&#39;;<br><br>function UserProfile({ userId }) {<br>  const [profile, setProfile] = useState(null);<br>  useEffect(() =&gt; {<br>    async function fetchProfile() {<br>      const response = await fetch(`/api/users/${userId}`);<br>      const data = await response.json();<br>      setProfile(data);<br>    }<br>    fetchProfile();<br>  }, [userId]);<br>  return profile ? &lt;div&gt;{profile.name}&lt;/div&gt; : &lt;p&gt;Loading...&lt;/p&gt;;<br>}</pre><p>Optimized Solution with React Server Components:</p><pre>// components/UserProfile.server.js<br>import React from &#39;react&#39;;<br><br>export default async function UserProfile({ userId }) {<br>  const response = await fetch(`https://api.example.com/users/${userId}`);<br>  const profile = await response.json();<br><br>  return &lt;div&gt;{profile.name}&lt;/div&gt;;<br>}</pre><p>Usage in the Client Component:</p><pre>// components/App.client.js<br>import UserProfile from &#39;./UserProfile.server&#39;;<br><br>function App({ userId }) {<br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;User Profile&lt;/h1&gt;<br>      &lt;UserProfile userId={userId} /&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><h3>3. Form Inputs and Debounced Updates</h3><p>Instead of debouncing updates through useEffect, handle it directly via controlled input components.</p><p>Incorrect Example:</p><pre>import { useState, useEffect } from &#39;react&#39;;<br><br>function Search() {<br>  const [query, setQuery] = useState(&#39;&#39;);<br>  const [debouncedQuery, setDebouncedQuery] = useState(query);<br>  useEffect(() =&gt; {<br>    const timer = setTimeout(() =&gt; {<br>      setDebouncedQuery(query);<br>    }, 300);<br>    return () =&gt; clearTimeout(timer);<br>  }, [query]);<br>  return &lt;input value={query} onChange={(e) =&gt; setQuery(e.target.value)} /&gt;;<br>}</pre><p>Optimized Solution with a Custom Hook:</p><pre>import { useState } from &#39;react&#39;;<br>import useDebounce from &#39;./useDebounce&#39;;<br><br>function Search() {<br>  const [query, setQuery] = useState(&#39;&#39;);<br>  const debouncedQuery = useDebounce(query, 300);<br>  return &lt;input value={query} onChange={(e) =&gt; setQuery(e.target.value)} /&gt;;<br>}</pre><p>The useDebounce custom Hook would encapsulate the debouncing logic:</p><pre>import { useState, useEffect } from &#39;react&#39;;<br><br>function useDebounce(value, delay) {<br>  const [debouncedValue, setDebouncedValue] = useState(value);<br>  useEffect(() =&gt; {<br>    const timer = setTimeout(() =&gt; setDebouncedValue(value), delay);<br>    return () =&gt; clearTimeout(timer);<br>  }, [value, delay]);<br>  return debouncedValue;<br>}<br>export default useDebounce;</pre><h3>4. Resetting All State When a Prop Changes</h3><p>When navigating between different items, resetting state variables like form fields or filters is important. An inefficient way to handle this reset is by using the useEffect hook to manually clear the state based on the prop change. However, this results in an extra render cycle and leads to unnecessary complexity.</p><p>Incorrect Example:</p><pre>import { useState, useEffect } from &#39;react&#39;;<br><br>export default function ItemDetails({ itemId }) {<br>  const [input, setInput] = useState(&#39;&#39;);<br>  // 🔴 Inefficient: Resets state with an effect<br>  useEffect(() =&gt; {<br>    setInput(&#39;&#39;); // Clear the input field when itemId changes<br>  }, [itemId]);<br><br>  return &lt;input value={input} onChange={(e) =&gt; setInput(e.target.value)} /&gt;;<br>}</pre><p>Instead of relying on effects, we can use the key prop to trigger a reset automatically. By splitting the component into two and passing a unique key prop to the inner component, React will treat it as a new instance, ensuring all internal state is reset.</p><p>Optimized Solution:</p><pre>export default function ItemDetails({ itemId }) {<br>  return &lt;ItemForm itemId={itemId} key={itemId} /&gt;;<br>}<br><br>function ItemForm({ itemId }) {<br>  // ✅ State resets on key change automatically<br>  const [input, setInput] = useState(&#39;&#39;);<br>  return (<br>    &lt;div&gt;<br>      &lt;h2&gt;Details for Item {itemId}&lt;/h2&gt;<br>      &lt;input value={input} onChange={(e) =&gt; setInput(e.target.value)} /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h3>Conclusion</h3><p>React’s useEffect is valuable but often misapplied. In many cases, using alternative approaches like event handlers, libraries like react-query, or custom hooks can provide cleaner, more maintainable solutions. For more insights, check out <a href="https://react.dev/learn/you-might-not-need-an-effect">React&#39;s guide</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=703792738ba3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My journey as a developer at Kodadot]]></title>
            <link>https://blog.kodadot.xyz/my-journey-as-a-developer-at-kodadot-b2b1d48afc9f?source=rss-cf2f865b371a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2b1d48afc9f</guid>
            <category><![CDATA[kodadot]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[women-in-tech]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Darshana Prachi]]></dc:creator>
            <pubDate>Mon, 08 May 2023 22:32:14 GMT</pubDate>
            <atom:updated>2023-05-16T11:04:00.365Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Srb5n6QRsmm5MDv1zlddaQ.png" /></figure><p>A year ago, I never thought that I’d be the top contributing and only early female developer on a thriving <a href="https://kodadot.xyz/">open source NFT gallery project</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WMhOKTtlOJNQWYtzhF3CLw.png" /></figure><p>Back in August 2020, I had no background in blockchain, web3, or NFTs when I began contributing to the <a href="https://github.com/kodadot/nft-gallery">Kodadot space</a>. Although I had prior experience in developing web apps, I had never delved into a web3-related project before, and I was completely clueless about it. Despite this, I decided to give it a shot, and I haven’t stopped contributing since. At the start of my journey, I didn’t realize that even though I was the <a href="https://www.linkedin.com/in/darshana-prachi/">only female</a> developer on the project, I had a support system in place. I received guidance and encouragement from several individuals who were committed to seeing me succeed in an unfamiliar environment. Thanks to <a href="https://twitter.com/yangWao">Yangwao</a> <a href="https://twitter.com/vikiival]">Vikiival</a> and RoiLeo.</p><p>With time, I became more self-assured and developed confidence in my technical abilities. However, I came to realize that having faith in my technical skills did not imply that I saw myself as an expert with all the right answers at my fingertips. Rather, building technical confidence meant being confident in my capability to tackle new technical challenges using the tools and abilities I had acquired.</p><p>I also took the following steps to make sure I was setting up for success:</p><ol><li>I became a member of <a href="https://discord.com/invite/PxEyQhW4NK">Kodadot’s Discord</a> community with the intention of establishing connections with peers and acquiring knowledge and insights.</li><li>My top priority was effective communication, so I made it a point to message individuals on <a href="https://discord.com/invite/PxEyQhW4NK">Discord</a> whenever I required a second opinion or feedback on my ideas. They were always willing to assist me with any queries I had. Also, I make it a point to regularly monitor <a href="https://github.com/kodadot/nft-gallery">Github</a> issues and respond to comments to clarify any uncertainties I may have.</li><li>To understand how other developers resolved challenging and diverse issues, I reviewed the pull requests they submitted.</li><li>I invested numerous hours in studying technical documentation and reading articles pertaining to web3 and blockchain to acquire a comprehensive understanding of the project and the subject matter.</li></ol><p>Although I am not proficient in the technical jargon related to web3, I feel confident in my ability to address the project’s issues and enhance <a href="https://kodadot.xyz/">KodaDot</a> for its users. Despite the fact that web3 development seems to be a male-dominated field (which, in my opinion, it currently is), there are numerous opportunities for female developers to participate. With perseverance, we can achieve anything we set our minds to, even if it appears insurmountable and challenging at first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2ZR-DGQcsOu0iTISyJUJJQ.png" /><figcaption>KodaDot — NFT marketplace</figcaption></figure><p>Reflecting on my growth and progress over the past year has been incredibly fulfilling. I transformed from someone who was apprehensive about facing novel challenges and exploring uncharted territories to someone who now embraces them and feels self-assured while doing so.</p><p>To gain further insights on Kodadot, you can either follow their <a href="https://twitter.com/KodaDot">Twitter</a> account or join their <a href="https://t.me/kodadot_eco">Telegram</a> group.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2b1d48afc9f" width="1" height="1" alt=""><hr><p><a href="https://blog.kodadot.xyz/my-journey-as-a-developer-at-kodadot-b2b1d48afc9f">My journey as a developer at Kodadot</a> was originally published in <a href="https://blog.kodadot.xyz/">KodaDot Frontier</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Skeleton Widget Without Any Package in Flutter]]></title>
            <link>https://prachirai.medium.com/skeleton-widget-without-any-package-in-flutter-f1c01fa671a0?source=rss-cf2f865b371a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1c01fa671a0</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[custom-skeleton-flutter]]></category>
            <category><![CDATA[skeleton-flutter]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter-loader]]></category>
            <dc:creator><![CDATA[Darshana Prachi]]></dc:creator>
            <pubDate>Tue, 10 Jan 2023 06:47:07 GMT</pubDate>
            <atom:updated>2023-01-10T06:47:37.635Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Fluuter Skeleton" src="https://cdn-images-1.medium.com/max/746/1*1ml5BnKtEpjfm7EiNf1emA.png" /></figure><p>As much as everyone loves using packages for features because it makes our lives as software developers easy, it is also highly inconvenient at times because of the lack of control you have over the code, the headache of trying to change the user interface and most importantly, the added size it adds to your build. So sometimes it is much easier to make your own component.</p><p>In this article, we will be making a flutter skeleton or loader widget from scratch without using any external package or module.</p><h4>Code:</h4><p>skeleton.dart</p><pre>import &#39;package:flutter/material.dart&#39;;<br><br>class Skeleton extends StatefulWidget {<br>  final double height;<br>  final double width;<br>  final String type;<br>  const Skeleton(<br>      {super.key, this.height = 20, this.width = 20, this.type = &#39;square&#39;});<br><br>  @override<br>  State&lt;Skeleton&gt; createState() =&gt; _SkeletonState();<br>}<br><br>class _SkeletonState extends State&lt;Skeleton&gt;<br>    with SingleTickerProviderStateMixin {<br>  late AnimationController _controller;<br>  late Animation gradientPosition;<br><br>  @override<br>  void initState() {<br>    super.initState();<br>    _controller = AnimationController(<br>        duration: const Duration(milliseconds: 1500), vsync: this);<br><br>    gradientPosition = Tween&lt;double&gt;(<br>      begin: -3,<br>      end: 10,<br>    ).animate(<br>      CurvedAnimation(parent: _controller, curve: Curves.linear),<br>    )..addListener(() {<br>        setState(() {});<br>      });<br><br>    _controller.repeat();<br>  }<br><br>  @override<br>  void dispose() {<br>    _controller.dispose();<br>    super.dispose();<br>  }<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Container(<br>      width: widget.width,<br>      height: widget.height,<br>      decoration: BoxDecoration(<br>          borderRadius: widget.type == &#39;circle&#39;<br>              ? BorderRadius.circular(50)<br>              : BorderRadius.circular(0),<br>          gradient: LinearGradient(<br>              begin: Alignment(gradientPosition.value, 0),<br>              end: const Alignment(-1, 0),<br>              colors: const [Colors.black12, Colors.black26, Colors.black12])),<br>    );<br>  }<br>}</pre><p>It’s small and you have full control over the UI that you want to have. You can also give it a type circle param, to show the skeleton loader in a circle.</p><p><strong>To use it:</strong></p><pre>Skeleton(height: 35, width: 35, type: &#39;circle&#39;)<br>Skeleton(height: 35, width: 35) // default is square</pre><p>Feel free to leave any comments for improvement.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1c01fa671a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Caching with Redis in a simple Next.js App]]></title>
            <link>https://prachirai.medium.com/caching-with-redis-in-a-simple-next-js-app-505ce42c648c?source=rss-cf2f865b371a------2</link>
            <guid isPermaLink="false">https://medium.com/p/505ce42c648c</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[redis]]></category>
            <dc:creator><![CDATA[Darshana Prachi]]></dc:creator>
            <pubDate>Thu, 04 Nov 2021 19:09:26 GMT</pubDate>
            <atom:updated>2021-11-04T19:09:26.496Z</atom:updated>
            <content:encoded><![CDATA[<p>Caching is an important optimization technique and having an in-memory cache can definitely improve the performance. In this article, we will be creating a simple Next.js app and cache the open dog-api data with Redis.</p><h3>Step 1: Creating Next.js app</h3><p>To create Next app, run</p><pre>npx create-next-app caching-redis</pre><p>Now to start the app, run</p><pre>npm run dev</pre><h3>Step 2: Measuring performance</h3><p>We will be using Next.js built in tools for performance measurement. Inside your <strong>_app.js </strong>file add the following content.</p><pre>import &#39;../styles/globals.css&#39;;</pre><pre>export function reportWebVitals(metric) {<br>  if (metric.label === &#39;custom&#39;) {<br>    console.log(metric);<br>  }<br>}<br>function MyApp({ Component, pageProps }) {<br>  return &lt;Component {...pageProps} /&gt;<br>}</pre><pre>export default MyApp</pre><p>Now if you reload your page, you’ll see something like this on console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pmAAfhrCdXYPAL8C" /></figure><p>Here, value is defining how long it took the page, in milliseconds, to hydrate on Next.js. Right now, since we don’t have anything, it is almost negligible.</p><h3>Step 3: Integrating open dog API</h3><p>In the <strong>index.js</strong> file, paste the following content. We are using the open dog api to fetch a list of Hound dogs.</p><p>We are fetching data inside <strong>getServerSideProps </strong>and passing that to the component through props.</p><p>After adding some minimal styles, result will be something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3gR_mcg6o3R1_AK4" /></figure><p>In the console, you will now see that the <strong>value </strong>has increased to 597ms, as now the data is being fetched from the server every time you reload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dg3gsaXmhJnqHlvu" /></figure><h3>Step 4: Installing Redis</h3><p>In this article, we will be using Redis as an in-memory cache where we will be storing the response of the API.</p><p>To install Redis, we will use Docker containers, because its very simple to use.</p><pre>docker run -p 6379:6379 --name my-redis -d redis</pre><p>6379 is the default port for Redis. You have a running instance of Redis locally and accessible at port 6379.</p><h3>Step 5: Caching the API response</h3><p>We will be using Redis as a middleware, where we first check if the data exists on Redis, if yes, we send that to the props, if not, we fetch from the server. This way is often called checking for a ‘cache hit-miss’.<br>We are going to install 2 packages, one is the good old <a href="https://www.npmjs.com/package/redis">redis</a> and the other one is <a href="https://www.npmjs.com/package/bluebird">bluebird</a> , which will promisify all Redis methods.</p><p>Copy and replace your <strong>index.js</strong> file with the following code</p><pre>import Image from &quot;next/image&quot;;<br>import styles from &quot;../styles/Home.module.css&quot;;<br>import redis from &quot;redis&quot;;<br>import bluebird from &quot;bluebird&quot;;</pre><pre>function Home({ dogImages }) {<br>  return (<br>    &lt;div className={styles.home}&gt;<br>      {dogImages.map((url, index) =&gt; {<br>        return (<br>          &lt;div key={index} className={styles.dogs}&gt;<br>            &lt;Image<br>              src={url}<br>              height=&quot;200&quot;<br>              width=&quot;200&quot;<br>              alt=&quot;dogs&quot;<br>              layout=&quot;fixed&quot;<br>            /&gt;<br>          &lt;/div&gt;<br>        );<br>      })}<br>    &lt;/div&gt;<br>  );<br>}</pre><pre>const fetchData = async (url) =&gt; {<br>  const query = await fetch(url);<br>  return await query.json();<br>};</pre><pre>export const getServerSideProps = async () =&gt; {<br>  bluebird.promisifyAll(redis.RedisClient.prototype);<br>  const cache = redis.createClient();<br>  let data = {};<br>  await cache.existsAsync(&quot;dogs&quot;).then(async (reply) =&gt; {<br>    if (reply !== 1) {<br>      // cache miss, need to fetch<br>      data = await fetchData(&quot;https://dog.ceo/api/breed/hound/images&quot;);<br>      await cache.set(&quot;dogs&quot;, JSON.stringify(data));<br>      console.log(&quot;getting dogs from server&quot;, data.message);<br>    } else {<br>      // cache hit, will get data from redis<br>      data = JSON.parse(await cache.getAsync(&quot;dogs&quot;));<br>      console.log(&quot;getting dogs from redis&quot;, data.message);<br>    }<br>  });<br>  return {<br>    props: {<br>      dogImages: data.message,<br>    },<br>  };<br>};</pre><pre>export default Home;</pre><p>Notice how with using bluebird, we effectively promisified the methods, so instead of <strong>cache.exists</strong> we use, <strong>cache.existsAsync.</strong></p><p>Now if you reload the app and check the console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WehqGQ-SPOOj-6uM" /></figure><p>The value has dropped to 538ms. Now, its not much, but it will provide considerable optimization in a large app and the time would be more visible.</p><h3>Additional Context</h3><p>For the scope of this article, I did not handle any cache invalidation. For that, you can also set an expiry time once saving the response on Redis, so that the response is always updated.</p><p>You can find the code for this on my <a href="https://github.com/prachi00/Redis-cache-nextjs">github here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=505ce42c648c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Improve your pull requests with Github templates]]></title>
            <link>https://prachirai.medium.com/improve-your-pull-requests-with-github-templates-e351db951e11?source=rss-cf2f865b371a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e351db951e11</guid>
            <category><![CDATA[template]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Darshana Prachi]]></dc:creator>
            <pubDate>Sun, 25 Jul 2021 16:40:12 GMT</pubDate>
            <atom:updated>2021-07-25T16:40:12.568Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7t9TEB5-fLgs_QTOoEMYJA.png" /></figure><p>Adding a pull request template is a great practice as the project contributors will automatically see the pull request template rules you have added. It will also save you and your team a lot of time.</p><h3>Adding the template</h3><ol><li>Navigate to your GitHub repository in which you want to add the PR template and click on <strong>Add file -&gt; Create new file</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/0*5e78jVBFfVh25G0-" /></figure><p>2. In the input box, name your file, write pull_request_template<em>.</em>md.<br>If you also want your template to be visible in your repository, place your file inside a directory by naming the pull request template like this docs<em>/</em>pull_request_template<em>.</em>md, where <strong>docs</strong> is the name of your directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZgZDOtF49GI7Kngi" /></figure><p>3. Now, in the body of your file add the content you want for your template.</p><p>For my project, I am going to add the following points to my template. You can add, remove according to your requirements.</p><pre>### Summary<br>&lt;!-- Provide a detailed summary of your PR. --&gt;</pre><pre>### Screenshot or Video<br>&lt;!-- Add photos related to your feature --&gt;</pre><pre>### What kind of change does this PR introduce?<br>- [ ] Bugfix<br>- [ ] Feature<br>- [ ] Refactors</pre><pre>### Checklist<br>- Tested on <br>  - [ ] **Chrome**<br>  - [ ] **Safari**<br>  - [ ] **Mobile**<br>- [ ] Added appropriate **tests**<br>- [ ] Added necessary comments<br>- [ ] Removed dead code</pre><p>4. At the bottom of your file, add the appropriate commit message and commit the new file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f1VjPIe2oDy9fqF8" /></figure><p>5. In your repository, you can now view the template you just made inside the <strong>docs</strong> directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/0*_0x_UK7QAHSs8DAc" /></figure><p>Preview</p><p>Now if any of the project contributors make a pr, they can see it in action , and hence, it would be easier for the PR reviewers to check the PR as they wouldn’t have to check for the minor changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BPCSIRBggUEXFS2g" /></figure><p>Feel free to contact me for any doubts or improvements.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e351db951e11" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Highlight specific part of a component in React]]></title>
            <link>https://prachirai.medium.com/highlight-specific-part-of-a-component-in-react-75898fe89760?source=rss-cf2f865b371a------2</link>
            <guid isPermaLink="false">https://medium.com/p/75898fe89760</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Darshana Prachi]]></dc:creator>
            <pubDate>Sun, 11 Jul 2021 09:53:54 GMT</pubDate>
            <atom:updated>2021-07-11T09:54:35.231Z</atom:updated>
            <content:encoded><![CDATA[<p>There are a lot of libraries available on the internet like Intro.js, Joyride to create guided tours or onboarding on your website. However, after using all these libraries and wasting a LOT of time on this, I realised that none one them provide full autonomy over the UI, which was my use case. I was given a task to make the onboarding tour flow for new users. In this, a part of the screen is highlighted and a message is shown that pops out. I was stuck for quite some time on trying to figure out how to do this.</p><p>So I decided to write a custom hook called <strong>useHighlight</strong>, that will highlight a specific part of the component.</p><h3>What will the hook do?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*ZEt8npd3zg3-__ge" /><figcaption>demo</figcaption></figure><p>The hook <strong>useHighlight</strong> will accept a reference (ID) to an element and then will highlight that portion of your page.</p><p>Let’s look at the code now.</p><p>First, we are going to add a button, on clicking which our element will be highlighted. Next, we are going to assume that the most interesting part of our website is on the left side, hence, highlight the left part of the screen and have an overlay on the right part, so that the interesting part of our website really pops out. So we are going to divide our screen in two parts, left and right.</p><pre>&lt;button <em>onClick</em>={onHighlightElement}&gt;<br>  Highlight<br> &lt;/button&gt;<br> &lt;div <em>className</em>=&quot;App&quot;&gt;<br>  &lt;div <em>className</em>=&quot;card&quot; <em>id</em>=&quot;leftSide&quot;&gt;<br>     &lt;h3&gt;Introduce users to your product&lt;/h3&gt;<br>  &lt;/div&gt;<br> &lt;div <em>className</em>=&quot;right&quot;&gt;Not important content&lt;/div&gt;<br>&lt;/div&gt;</pre><pre>.App {<br> text-align: center;display: flex;<br> flex-direction: row;<br>}<br>.right {<br> background: #2f80ed;width: 70%;<br>}<br>.card {<br> background: #fff;height: 100vh;width: 30%;<br>}</pre><p>Now time to start writing the hook</p><p>Our hook is going to expose 2 functions, called removeHighlightEl, highlightElement and 1 boolean variable for knowing if highlight state is on. To use the hook in App.js:</p><pre>const {isHighlight, highlightElement, removeHighlightEl} = useHighLight();</pre><p>Inside our hook, useHighlight</p><pre>import { useState } from &quot;react&quot;;<br>import &quot;./styles.css&quot;;<br>export const useHighLight = () =&gt; {<br>const [isHighlight, setIsHighlight] = useState(false);</pre><pre>const setOverlayOnElement = (elem, id) =&gt; {<br>  const rect = elem.getBoundingClientRect();<br>  const x = rect.left;<br>  const y = rect.top;<br>  const w = rect.width;<br>  const h = rect.height;<br>  const overlay = document.createElement(&quot;div&quot;);<br>  overlay.setAttribute(&quot;id&quot;, id);<br>  overlay.style.width = `${w}px`;<br>  overlay.style.height = `${h}px`;<br>  overlay.style.top = `${y}px`;<br>  overlay.style.left = `${x}px`;<br>  overlay.style.position = &quot;absolute&quot;;<br>  elem.classList.add(&quot;overlayActive&quot;);<br>  document.body.appendChild(overlay);<br> }</pre><pre>const highlightElement = (targetID) =&gt; {<br>  const elem = document.getElementById(targetID);<br>  if (elem) {<br>  setOverlayOnElement(elem, &quot;overlayID&quot;);<br>  setIsHighlight(true);<br>  }<br>};</pre><pre>const removeHighlightElement = (targetID) =&gt; {<br>  const elem = document.getElementById(targetID);<br>  const myobj = document.getElementById(&quot;overlayID&quot;);<br>  elem.classList.remove(&quot;overlayActive&quot;);<br>  myobj.remove();<br>  setIsHighlight(false);<br>};</pre><pre>return {<br>  highlightElement,<br>  removeHighlightElement,<br>  isHighlight<br> };<br>};</pre><p>First, <strong>highlightElement</strong> function is getting called, it is accepting the ID of the element (‘leftSide’). Function <strong>setOverlayOnElement</strong> next, is finding the dimensions of the element being passed. Next, it is manually creating a HTML element called overlay, whose dimensions matches that of our element and is positioned on top of our ‘leftSide’ element by giving position ‘absolute’.</p><pre>elem.classList.add(&quot;overlayActive&quot;);</pre><p>The above line is adding a class overlayActive to our ‘leftSide’ id div.</p><p>Don’t forget to add overlayActive css in App.css file</p><pre>.overlayActive {<br>  z-index: 1;<br> }</pre><p><strong>removeHighlightElement</strong> element gets called when we click on the remove highlight button on the screen. It is just removing the class and the manual overlay element we created in the <strong>setOverlayOnElement</strong> function.</p><p>Now, for the final step, we are going to the add the background overlay div in our App.js file.</p><pre>{isHighlight &amp;&amp; &lt;div <em>className</em>={&quot;overlay&quot;} /&gt;}</pre><p>isHighlight is a boolean variable which gets true when you click on highlight element and is exposed by the hook.</p><p>Css for the background overlay, to be added in the App.css file:</p><pre>.overlay {<br>  background: rgba(0, 0, 0, 0.5);<br>  position: fixed;<br>  width: 100%;<br>  height: 100%;<br>  top: 0;<br>  right: 0;<br>  z-index: 1;<br>}</pre><p>After adding this, our App.js content will look something like this.</p><pre>import &quot;./styles.css&quot;;<br>import { useHighLight } from &quot;./useHighlight&quot;;</pre><pre>export default function App() {<br>const {<br>isHighlight,<br>highlightElement,<br>removeHighlightElement<br>} = useHighLight();</pre><pre>const onHighlightElement = () =&gt; {<br>highlightElement(&quot;leftSide&quot;);<br>};</pre><pre>const onRemoveHighlightElement = () =&gt; {<br>removeHighlightElement(&quot;leftSide&quot;);<br>};</pre><pre>return (<br>&lt;&gt;<br> {isHighlight &amp;&amp; &lt;div <em>className</em>={&quot;overlay&quot;} /&gt;}<br> &lt;button <em>onClick</em>={onHighlightElement}&gt;Highlight&lt;/button&gt;<br> &lt;div <em>className</em>=&quot;App&quot;&gt;<br>   &lt;div <em>className</em>=&quot;card&quot; <em>id</em>=&quot;leftSide&quot;&gt;<br>   &lt;h3&gt;Introduce users to your product&lt;/h3&gt;<br>   {isHighlight &amp;&amp; (<br>   &lt;button <em>onClick</em>={onRemoveHighlightElement}&gt;Remove Highlight&lt;/button&gt;<br>   )}<br>   &lt;/div&gt;<br>  &lt;div <em>className</em>=&quot;right&quot;&gt;Not important content&lt;/div&gt;<br> &lt;/div&gt;<br>&lt;/&gt;<br>);<br>}</pre><p>Yay! Now, the interesting part of our app is highlighted. I have also made a <a href="https://codesandbox.io/embed/angry-forest-h48jw">Codesandbox</a> with this code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75898fe89760" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making a PWA app with Next.js]]></title>
            <link>https://prachirai.medium.com/making-a-pwa-app-with-next-js-a5009331f833?source=rss-cf2f865b371a------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5009331f833</guid>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[pwa]]></category>
            <dc:creator><![CDATA[Darshana Prachi]]></dc:creator>
            <pubDate>Sun, 11 Jul 2021 09:49:01 GMT</pubDate>
            <atom:updated>2021-07-11T09:49:01.323Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UUVIRPbMkDR3YLnFe_9kZA.png" /></figure><h3>What is a PWA?</h3><p>In simple words, a <strong>PWA (Progressive Web App)</strong> is a website with all the benefits of an app. You can install a PWA app on your phone or download it from your web browser on your laptop. It is fast and lightweight.</p><p>In this article, we are going to see how you can make your Next.js app a PWA.</p><p>In our Next.js app, firstly we are going to install the package <strong>next-pwa</strong>.</p><pre>npm i next-pwa</pre><h3>Setup PWA</h3><p>Now, we have to edit our config file. The configuration that we will add will make our application create the required service worker files during the compilation.</p><p>Open next.config.js file and add the below code to it.</p><p>const withPWA = require(&#39;next-pwa&#39;) module.exports = withPWA({ <br> pwa: { dest: &#39;public&#39; } <br>})</p><p>inside next.config.js</p><p>With this, the required service worker files will be generated in the <strong>public</strong> folder.</p><h3>Creating the manifest file</h3><p>To specify the PWA app’s properties, we have to define the properties in a manifest.json file. Create a manifest.json file and paste the below content into it.</p><pre>{<br>    &quot;short_name&quot;: &quot;Next App&quot;,<br>    &quot;name&quot;: &quot;Next App&quot;,<br>    &quot;icons&quot;: [<br>      {<br>        &quot;src&quot;: &quot;favicon.ico&quot;,<br>        &quot;sizes&quot;: &quot;64x64 32x32 24x24 16x16&quot;,<br>        &quot;type&quot;: &quot;image/x-icon&quot;<br>      },<br>      {<br>        &quot;src&quot;: &quot;logo1.png&quot;,<br>        &quot;type&quot;: &quot;image/png&quot;,<br>        &quot;sizes&quot;: &quot;192x192&quot;<br>      },<br>      {<br>        &quot;src&quot;: &quot;logo2.png&quot;,<br>        &quot;type&quot;: &quot;image/png&quot;,<br>        &quot;sizes&quot;: &quot;512x512&quot;<br>      }<br>    ],<br>    &quot;start_url&quot;: &quot;.&quot;,<br>    &quot;display&quot;: &quot;standalone&quot;,<br>    &quot;theme_color&quot;: &quot;#21125e&quot;,<br>    &quot;background_color&quot;: &quot;#ffffff&quot;<br>  }</pre><p>Feel free to edit your own app name, logos and colours to it. You can also search for a manifest generator online and use that to create your json.</p><h3>Adding meta tags</h3><p>Our application must have some meta tags to give information about our app. To specify meta tags , in your <strong>_app.js</strong> file, specify a <strong>&lt;Head&gt;</strong> element, which is imported from <strong>“next/head”.</strong></p><pre>import Head from &quot;next/head&quot;;</pre><p>Now insert the following content in it.</p><pre>&lt;Head&gt;<br>      &lt;meta <em>charset</em>=&#39;utf-8&#39; /&gt;<br>      &lt;meta <em>http-equiv</em>=&#39;X-UA-Compatible&#39; <em>content</em>=&#39;IE=edge&#39; /&gt;<br>      &lt;meta <em>name</em>=&#39;viewport&#39; <em>content</em>=&#39;width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no&#39; /&gt;<br>      &lt;meta <em>name</em>=&#39;description&#39; <em>content</em>=&#39;Description&#39; /&gt;<br>      &lt;title&gt;Next.js PWA&lt;/title&gt;<br>      &lt;link <em>rel</em>=&#39;manifest&#39; <em>href</em>=&#39;/manifest.json&#39; /&gt;<br>      &lt;link <em>href</em>=&#39;/favicon-16x16.png&#39; <em>rel</em>=&#39;icon&#39; <em>type</em>=&#39;image/png&#39; <em>sizes</em>=&#39;16x16&#39; /&gt;<br>      &lt;link <em>href</em>=&#39;/favicon-32x32.png&#39; <em>rel</em>=&#39;icon&#39; <em>type</em>=&#39;image/png&#39;    <em>sizes</em>=&#39;32x32&#39; /&gt;<br>      &lt;link <em>rel</em>=&#39;apple-touch-icon&#39; <em>href</em>=&#39;/logo1.png&#39;&gt;&lt;/link&gt;<br>      &lt;meta <em>name</em>=&#39;theme-color&#39; <em>content</em>=&#39;#21125e&#39; /&gt;<br> &lt;/Head&gt;</pre><p>Remember to also add some favicons in the public folder as well, so that you can use them here.</p><p>After this, run this command to see your PWA in action</p><pre>npm run dev</pre><p>On web, you’ll see a download icon in the search bar with an install button, that will install the PWA app on your laptop</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*heeiNUvpkcz1qC47" /></figure><p>On a mobile device, you’ll see an <strong>add to home screen</strong> button that will install the PWA on your phone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*sYGj7NNTLH5MBuRW" /></figure><p>You can see the live demo <a href="https://next-js-pwa-app.vercel.app/">here</a>.<br>You can also find the whole code on my github <a href="https://github.com/Prachi00/next.js-PWA-app">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5009331f833" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>