<?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 Kavya S on Medium]]></title>
        <description><![CDATA[Stories by Kavya S on Medium]]></description>
        <link>https://medium.com/@kavya.explores?source=rss-83a2f21a9c07------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*HWAuCTAPAaAJLOs2</url>
            <title>Stories by Kavya S on Medium</title>
            <link>https://medium.com/@kavya.explores?source=rss-83a2f21a9c07------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 06:32:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kavya.explores/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[How to setup Page Loading during page change in Next.js?]]></title>
            <link>https://blog.coffeeinc.in/how-to-setup-page-loading-during-page-change-in-next-js-e7e12175bbed?source=rss-83a2f21a9c07------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7e12175bbed</guid>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Kavya S]]></dc:creator>
            <pubDate>Thu, 16 Nov 2023 13:15:22 GMT</pubDate>
            <atom:updated>2023-11-16T13:17:34.983Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tmK6a2k9DBTOe7Uw" /></figure><p>Next.js works with server side rendering to generate an optimized version of the page. While this method is great for SEO as the page comes pre-rendered, you may have noticed that the UI doesn’t get updated instantly when user navigates to another page (as it takes some time for page to load).</p><p>To improve the user experience, I will show you how we can add an event listener on route change. The event listener will listen for route changes and update the state.</p><p>First, let us create a state variable isPageLoading that will hold the current loading state.</p><pre>const [isPageLoading, setIsPageLoading] = useState(false);</pre><p>Then, let us import the Router from next/router.</p><pre>import Router from &#39;next/router&#39;;</pre><p>We can then call the event listener on the Router.</p><ul><li>We attach a listener for routeChangeStart for when the change of route is initiated. In that case, we will set the pageLoading as true.</li><li>We attach a listener for routeChangeComplete and routeChangeError for when the change of route is completed or there is some error. In that case, we will set the pageLoading as false.</li></ul><pre>Router.events.on(&#39;routeChangeStart&#39;, () =&gt; setIsPageLoading(true)); <br>Router.events.on(&#39;routeChangeComplete&#39;, () =&gt; setIsPageLoading(false)); <br>Router.events.on(&#39;routeChangeError&#39;, () =&gt; setIsPageLoading(false));</pre><p>These event listeners should be called in the useEffect. And once we are done with page loading, we will have to unmount the listeners. So your useEffect will look as follows:</p><pre>useEffect(() =&gt; {<br>    const routeEventStart = () =&gt; {<br>        setIsPageLoading(true);<br>    };<br>    const routeEventEnd = () =&gt; {<br>        setIsPageLoading(false);<br>    };<br><br>    Router.events.on(&#39;routeChangeStart&#39;, routeEventStart);<br>    Router.events.on(&#39;routeChangeComplete&#39;, routeEventEnd);<br>    Router.events.on(&#39;routeChangeError&#39;, routeEventEnd);<br>    return () =&gt; {<br>        Router.events.off(&#39;routeChangeStart&#39;, routeEventStart);<br>        Router.events.off(&#39;routeChangeComplete&#39;, routeEventEnd);<br>        Router.events.off(&#39;routeChangeError&#39;, routeEventEnd);<br>    };<br>}, []);</pre><p>Make sure to add this in your pages where you want to have a loading state. I have given a sample page below from the Houses Detail page in the <a href="https://blog.coffeeinc.in/how-to-setup-dynamic-meta-tags-for-seo-using-getserversideprops-in-next-js-9bad0ac9e9b0">dynamic meta tags</a> article:</p><pre>import React from &quot;react&quot;;<br>import { useRouter } from &quot;next/router&quot;;<br>import CoffeeHead from &quot;@/components/CoffeeHead&quot;;<br>import Loading from &quot;@/components/Loading&quot;;<br><br>const HouseDetail = ({ house, page_url }) =&gt; {<br>    const router = useRouter();<br>    const { id } = router.query;<br>    const [isPageLoading, setIsPageLoading] = useState(false);<br>    useEffect(() =&gt; {<br>        const routeEventStart = () =&gt; {<br>            setIsPageLoading(true);<br>        };<br>        const routeEventEnd = () =&gt; {<br>            setIsPageLoading(false);<br>        };<br>        Router.events.on(&#39;routeChangeStart&#39;, routeEventStart);<br>        Router.events.on(&#39;routeChangeComplete&#39;, routeEventEnd);<br>        Router.events.on(&#39;routeChangeError&#39;, routeEventEnd);<br>        return () =&gt; {<br>            Router.events.off(&#39;routeChangeStart&#39;, routeEventStart);<br>            Router.events.off(&#39;routeChangeComplete&#39;, routeEventEnd);<br>            Router.events.off(&#39;routeChangeError&#39;, routeEventEnd);<br>        };<br>    }, []);<br>    return (<br>        &lt;&gt;<br>            {isPageLoading ? (<br>                &lt;Loading /&gt;<br>            ) : (<br>                &lt;CoffeeHead<br>                    title={house.name}<br>                    description={`${house.name} was founded by ${house.founder} and represented by ${house.animal}.`}<br>                    image={house.image}<br>                    page_url={page_url}<br>                /&gt;<br>                &lt;a<br>                    href=&quot;#&quot;<br>                    className=&quot;block max-w-md p-6 bg-white border border-gray-200 rounded-lg shadow m-auto mt-6&quot;<br>                &gt;<br>                    &lt;h5 className=&quot;mb-2 text-2xl font-bold text-gray-900&quot;&gt;<br>                        {house.name}<br>                    &lt;/h5&gt;<br>                    &lt;p className=&quot;font-normal text-gray-700&quot;&gt;<br>                        Founded by {house.founder}<br>                    &lt;/p&gt;<br>                    &lt;p className=&quot;font-normal text-gray-700&quot;&gt;<br>                        House Animal: {house.animal}<br>                    &lt;/p&gt;<br>                &lt;/a&gt;<br>            )}<br>        &lt;/&gt;<br>    );<br>};<br>export default HouseDetail;<br>export const getServerSideProps = async (context) =&gt; {<br>    const { id } = context.query;<br>    const res = await fetch(<br>        `https://wizard-world-api.herokuapp.com/Houses/${id}`<br>    );<br>    const house = await res.json();<br>    house.image = `${process.env.NEXT_PUBLIC_SITE_URL}/Hogwarts-Houses.jpg`;<br>    const page_url = context.req.headers.host + `/houses/${id}`;<br>    <br>    return { props: { house, page_url } };<br>};</pre><h3>Bonus: Custom usePageLoading Hook</h3><p>Adding a event listener to each and every page’s useEffect is a repetitive task and is not something I prefer. So, I have create a custom hook to serve the same purpose.</p><pre>import Router from &#39;next/router&#39;;<br>import { useEffect, useState } from &#39;react&#39;;<br>export const usePageLoading = () =&gt; {<br>    const [isPageLoading, setIsPageLoading] = useState(false);<br><br>    useEffect(() =&gt; {<br>        const routeEventStart = () =&gt; {<br>            setIsPageLoading(true);<br>        };<br>        const routeEventEnd = () =&gt; {<br>            setIsPageLoading(false);<br>        };<br>        Router.events.on(&#39;routeChangeStart&#39;, routeEventStart);<br>        Router.events.on(&#39;routeChangeComplete&#39;, routeEventEnd);<br>        Router.events.on(&#39;routeChangeError&#39;, routeEventEnd);<br>        return () =&gt; {<br>            Router.events.off(&#39;routeChangeStart&#39;, routeEventStart);<br>            Router.events.off(&#39;routeChangeComplete&#39;, routeEventEnd);<br>            Router.events.off(&#39;routeChangeError&#39;, routeEventEnd);<br>        };<br>    }, []);<br>    return { isPageLoading };<br>};</pre><p>You can call this hook in the _app.js file in your pages folder and the loading state will be applied to all the pages.</p><pre>import &quot;@/styles/globals.css&quot;;<br>import { usePageLoading } from &quot;@/hooks/use-page-loading&quot;;<br>import Loading from &quot;@/components/Loading&quot;;<br><br>export default function App({ Component, pageProps }) {<br>    const { isPageLoading } = usePageLoading();<br>    return isPageLoading ? &lt;Loading /&gt; : &lt;Component {...pageProps} /&gt;;<br>}</pre><p>There you have it! We have added page loading with a custom hook to our Next.js SSR pages.</p><p>Drop a comment if you have any questions.</p><p><em>This page is part of the Next.js playbook, which is in the works at Coffee. Drop a mail to</em> <em>if you want to get on the waitlist.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7e12175bbed" width="1" height="1" alt=""><hr><p><a href="https://blog.coffeeinc.in/how-to-setup-page-loading-during-page-change-in-next-js-e7e12175bbed">How to setup Page Loading during page change in Next.js?</a> was originally published in <a href="https://blog.coffeeinc.in/">Coffee Byte</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with WordPress: Essentials to keep in mind]]></title>
            <link>https://blog.coffeeinc.in/getting-started-with-wordpress-things-to-keep-in-mind-65ab9fc20faf-992a5038799d?source=rss-83a2f21a9c07------2</link>
            <guid isPermaLink="false">https://medium.com/p/992a5038799d</guid>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[wordpress]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Kavya S]]></dc:creator>
            <pubDate>Fri, 27 Oct 2023 21:27:59 GMT</pubDate>
            <atom:updated>2023-11-27T13:46:01.634Z</atom:updated>
            <content:encoded><![CDATA[<p>WordPress is a great platform if you are looking to get started with a website as it provides a extensive content management system. Using WordPress is generally user-friendly, but there are certain considerations to keep in mind to ensure a smooth and secure experience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*6p8oWJriADMErVDq.jpeg" /></figure><p>You may find yourself bogged down with a slow website or security vulnerabilities if you do not pay attention to certain aspects of your website. In this article, we are going to look at 8 essential things to keep in mind when working with WordPress.</p><h3>1. Choose the right Hosting Provider</h3><p>We have a wide range of options to install WordPress, from shared hosting to cloud hosting. Depending on the scope of your requirement and the plugins you use for your website, you will need to make a choice.</p><h4>Shared Hosting</h4><p>Starting out, you can choose to go with a shared hosting provider like GoDaddy or Bluehost. These platforms provide a cPanel interface with one-click installation and a management interface for updates and direct login. Shared hosting is a good start if you are only going to use few plugins.</p><h4>Cloud hosting</h4><p>As the number of plugins increase on your website, you may find your website slow down in loading. If the higher tiers of shared hosting plan do not serve your requirement, you can opt in for a cloud hosting provider like <a href="https://m.do.co/c/11eaea435186">Digital Ocean</a>. With the 1GB or 2GB droplet, you will find a much more optimized load time for WordPress. The use of Cloud hosting however requires you to install WordPress through the command line.</p><h4>AWS EC2</h4><p>As your requirements scale, you may find yourself with a hugh number of user visits and will need to scale your server dynamically. It is then you can opt in for a higher end cloud server like AWS EC2 with RDS for the database. Both your DB server and WordPress server can then be arhitected to use separate resources.</p><h3>2. Securing your installation</h3><p>WordPress is one of the most commonly used self-hosted CMS systems. Having being around for quite a while, it has its fair share of users and people trying to get into the system. As more people try to hack the system, vulnerabilities are more likely to be exploited. So, it becomes important to secure your installations by not making use of default preferences.</p><h4>Table Prefix</h4><p>Consider changing the default database table prefix from “wp_” to something more unique. This adds an extra layer of security by making it more difficult for potential attackers to guess table names.</p><h4>.htaccess and wp-config.php Security</h4><p>After installation, make sure that your .htaccess and wp-config.php files are secure. These files contain sensitive information and play a crucial role in the security of your WordPress site.</p><h4>Install a Security Plugin</h4><p>Consider installing a security plugin, such as <a href="https://wordpress.org/plugins/wordfence/">Wordfence</a> or <a href="https://wordpress.org/plugins/sucuri-scanner/">Sucuri</a>, immediately after installation to enhance your site’s protection against potential threats.</p><h3>3. Access Credentials</h3><p>Avoid using the default “admin” username for the administrator account. Choose a unique username and a strong, complex password. This helps protect your site from brute-force attacks. Further, make sure to provide a valid email account for the admin account, so it is easier for you to recover password if you forget it.</p><p>Limiting login attempts in WordPress is a good security practice to prevent brute force attacks. A brute force attack involves trying multiple username and password combinations until the correct one is found. To enhance security and protect your WordPress site, you can use a plugin that limits the number of login attempts.</p><h3>4. File Permissions</h3><p>Ensure that file and directory permissions are set correctly. Directories should have a permission of 755, and files should have a permission of 644. Incorrect permissions can lead to security vulnerabilities.</p><h3>5. Update Permalinks</h3><p>Set your preferred permalink structure early in the installation process. Go to “Settings” &gt; “Permalinks” and choose a structure that is both SEO-friendly and reflective of your content structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/0*8sOqBdkQNw_KvJvu.png" /></figure><h4>Plain Permalinks</h4><p>The default Plain Permalink also called the Ugly Permalink looks like this:</p><p><a href="http://example.com/?p=N">http://example.com/?p=N</a></p><p>with p as the parameter and N is the unique ID of the post or page in the database.</p><p>WordPress comes preinstalled with this setting. It works on all server environments. It is not user-friendly and also not optimized for search engines.</p><h4>Pretty Permalinks</h4><p>Pretty Permalinks are SEO-friendly and attractive. They usually contain several words such as the title of the post or page, post category, tag name, etc. You can use Keywords in the URL to make your content readable by search engines. Pretty Permalinks also help others get an understanding of what the content of the page or post is by reading the URL.</p><p>Pretty Permalinks look like this:</p><p><a href="http://example.com/2012/post-name/">http://example.com/2012/post-name/</a></p><p>or</p><p><a href="http://example.com/2012/12/30/post-name">http://example.com/2012/12/30/post-name</a></p><p><strong>We would recommend to toggle the Pretty Permalinks option so that you have a more optimized URL.</strong></p><h3>6. Backup</h3><p>Regularly back up your WordPress site, including both files and the database. Many hosting providers offer automated backup solutions, or you can use plugins like UpdraftPlus or BackupBuddy. Before making any major changes or installing additional plugins and themes, perform a backup. This ensures that you can restore your site if something goes wrong.</p><h3>7. Keep Your Hosting Environment Updated:</h3><p>Ensure that your hosting environment (PHP version, MySQL, server software) is up to date and compatible with the latest WordPress requirements. Upgrading the PHP version for a WordPress website is a good practice as it can bring performance improvements, security enhancements, and compatibility with the latest technologies.</p><p>As of writing this article, the recommended stable version of PHP is 7.4. However, it is better to prepare for the latest PHP version, which is 8.2. This ensures that you are safe form any vulnerabilities discovered in the older versions.</p><h3>8. Stay Informed</h3><p>Keep yourself informed about WordPress security best practices and updates. Follow the official WordPress blog and forums for the latest information. You can check the latest version of WordPress release on this website: <a href="https://wordpress.org/news/category/releases/">https://wordpress.org/news/category/releases/</a>.</p><p>As of writing this article, the latest version of WordPress is 6.3.2.</p><h3>Conclusion</h3><p>In conclusion, while WordPress offers a robust content management system for building websites, it’s crucial to navigate the platform with a focus on security, performance, and best practices. By paying attention to the above 8 points when using WordPress, you can set a strong foundation for a secure, efficient, and well-configured website.</p><p>Regularly reviewing and updating your site in line with best practices will contribute to a positive experience for both you and your visitors.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=992a5038799d" width="1" height="1" alt=""><hr><p><a href="https://blog.coffeeinc.in/getting-started-with-wordpress-things-to-keep-in-mind-65ab9fc20faf-992a5038799d">Getting Started with WordPress: Essentials to keep in mind</a> was originally published in <a href="https://blog.coffeeinc.in/">Coffee Byte</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to send mail to users directly from Next.js using Resend?]]></title>
            <link>https://blog.coffeeinc.in/how-to-send-mail-to-users-directly-from-next-js-using-resend-9c558fc767e6?source=rss-83a2f21a9c07------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c558fc767e6</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Kavya S]]></dc:creator>
            <pubDate>Wed, 04 Oct 2023 22:05:53 GMT</pubDate>
            <atom:updated>2023-10-13T11:42:29.174Z</atom:updated>
            <content:encoded><![CDATA[<p>Next.js provides us a very versatile frontend, which can be used standalone to serve most of our requirements for a website. With built-in provisions to leverage server side rendering and create APIs in the project structure itself, we can expand the capabilities of our Next.js app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*naoBQnoo5FhIoA68lUrKBg.jpeg" /></figure><p>In this article, we will explore <a href="http://resend.com/">Resend</a>, the email API for developers and integrate with our app. We will create a simple contact form, which upon submit, will send an email to our inbox with the submitted information. This integration is very useful when we want to get enquiries, waitlist, or any other kind of form information and have it directly delivered to our inbox.</p><h3>Our Next.js App</h3><p>I am going to create a simple Next.js app with a contact form using yarn create next-app.</p><pre>yarn create next-app</pre><p>For the project configuration, I have used the following settings. I have chosen to use tailwind for styling and the src directory to keep our code organized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*2vcPGFN3KYfdpwQqnk7q1w.png" /></figure><h4>Creating a contact form</h4><p>I am going to keep things simple and create a contact form which prompts for name and email.</p><p>Let us update the index.js page component as follows:</p><pre>import { useState } from &quot;react&quot;;<br>import Head from &quot;next/head&quot;;<br><br>export default function Home() {<br>    const [name, setName] = useState(&quot;&quot;);<br>    const [email, setEmail] = useState(&quot;&quot;);<br>    const [loading, setLoading] = useState(false);<br><br>    const handleSubmit = () =&gt; {<br>      console.log(&quot;Call send API here&quot;)<br>    }<br>    return (<br>        &lt;main<br>            className={`flex flex-col items-center p-24 min-h-screen`}<br>        &gt;<br>            &lt;Head&gt;<br>                &lt;title&gt;Contact Me | Coffeed&lt;/title&gt;<br>            &lt;/Head&gt;<br><br>            &lt;div className=&quot;relative flex flex-col gap-4 &quot;&gt;<br>                &lt;div className=&quot;flex flex-col place-items-center gap-4&quot;&gt;<br>                    &lt;h1 className={`m-0 text-center text-3xl`}&gt;Contact Me&lt;/h1&gt;<br>                &lt;/div&gt;<br>                &lt;form<br>                    className=&quot;mt-6 flex flex-col max-w-xl gap-4 z-10&quot;<br>                    onSubmit={handleSubmit}<br>                &gt;<br>                    &lt;label htmlFor=&quot;name&quot; className=&quot;sr-only&quot;&gt;<br>                        Name<br>                    &lt;/label&gt;<br>                    &lt;input<br>                        id=&quot;name&quot;<br>                        name=&quot;name&quot;<br>                        type=&quot;text&quot;<br>                        autoComplete=&quot;name&quot;<br>                        required<br>                        value={name}<br>                        className=&quot;rounded-md bg-white/5 px-3.5 py-2.5 text-white ring-1 ring-inset focus:ring-blue-600 text-sm md:w-96&quot;<br>                        placeholder=&quot;Name&quot;<br>                        onChange={(e) =&gt; setName(e.target.value)}<br>                    /&gt;<br>                    &lt;label htmlFor=&quot;email-address&quot; className=&quot;sr-only&quot;&gt;<br>                        Email address<br>                    &lt;/label&gt;<br>                    &lt;input<br>                        id=&quot;email-address&quot;<br>                        name=&quot;email&quot;<br>                        type=&quot;email&quot;<br>                        autoComplete=&quot;email&quot;<br>                        required<br>                        value={email}<br>                        className=&quot;rounded-md bg-white/5 px-3.5 py-2.5 text-white ring-1 ring-inset focus:ring-blue-600 text-sm md:w-96&quot;<br>                        placeholder=&quot;Email&quot;<br>                        onChange={(e) =&gt; setEmail(e.target.value)}<br>                    /&gt;<br>                    &lt;button<br>                        type=&quot;submit&quot;<br>                        className=&quot;flex justify-center rounded-md bg-blue-600 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-500&quot;<br>                    &gt;<br>                        {loading ? (<br>                            &lt;div<br>                                style={{<br>                                    borderTopColor: &quot;transparent&quot;,<br>                                }}<br>                                className=&quot;w-6 h-6 border-4 border-white border-solid rounded-full animate-spin&quot;<br>                            &gt;&lt;/div&gt;<br>                        ) : (<br>                            &quot;Submit&quot;<br>                        )}<br>                    &lt;/button&gt;<br>                &lt;/form&gt;<br>            &lt;/div&gt;<br>        &lt;/main&gt;<br>    );<br>}</pre><p>I have used tailwind for styling and created a simple form to get the name and email from the user. We will trigger the send mail API call onSubmit of the form.</p><p>Let us set up Resend and the required APIs in Next.js to proceed further.</p><h3>Getting Started with Resend</h3><p>Head over to <a href="https://resend.com/login">resend.com</a> and log in to your account. You can create a new one using your email or Github.</p><p>Resend supports sending out mails to users only if you own and verify your domain on the platform. This allows you to send out mails from any email id using that domain name. For example, if I am to send a mail to users from noreply@coffeed.com, I have to add the coffeed.com domain to Resend and then add the respective domain name records to verify that I own the domain.</p><h4>Add your domain</h4><p>Go to Domains and click on Add Domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-nRehdVfXWzzDdy29-FLLw.png" /></figure><p>Enter your domain name and select region. The default “us-east-1” is free and works for our use-case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-rTG_jHb6yrlPn9ZaK-3jQ.png" /><figcaption>Enter your domain name</figcaption></figure><p>Once you add your domain, you will be shown a set of DNS records, which you should update at your domain service provider. Once you add the MX and 2 TXT records to your DNS, you can click on “Verify DNS Records” verify your domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uP-O5F0bCK9brX884eW28w.png" /></figure><p>Verifying a domain is essential to ensuring the deliverability of your emails. Once you verify a domain, you will be granted permission to send emails.</p><h4>Create an API key</h4><p>API Keys are secret tokens used to authenticate your requests.</p><ol><li>Navigate to API Keys on the sidebar.</li><li>Click Create API Key.</li><li>Give your API Key a name.</li><li>Select Sending access as the permission and choose the specific domain you want restrict access.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2XByMkhbJ_OjNZMVxer4kQ.png" /><figcaption>Add API Key</figcaption></figure><p>There is also the “Full access” permission but for security, it is better to use “Sending access” permission restricted to a single domain. Add this API key generated in the .env file as RESEND_API_KEY variable.</p><h3>Adding Resend​ to your Next.js App</h3><p>Now let us head back to our project and add the resend sdk library. Run the following command in the terminal:</p><pre>yarn add resend​</pre><h4>1. Add an email template</h4><p>Start by creating a new folder for email templates in the components folder in the src directory. Add a new email template called contact-form.jsx in src/components/email/ folder.</p><pre>export const EmailTemplate = ({<br>  name,<br>  email<br>}) =&gt; (<br>  &lt;div&gt;<br>    &lt;p&gt;Hello Kavya,&lt;/p&gt;<br>    &lt;p&gt;<br>        {name} has submitted the contact form on your website. Their<br>        email is {email}!<br>    &lt;/p&gt;<br>    &lt;p&gt;<br>        Regards,<br>        &lt;br /&gt;<br>        Coffee<br>    &lt;/p&gt;<br>  &lt;/div&gt;<br>);​</pre><p>I have created a simple template to get the name and email and have used HTML to stylize the body of the email. As you can see, this is a React component, so you are free to use and customize the design by making use of any of the React components you have designed in your project.</p><h4>2. Create an API to send email</h4><p>Create an API file called send.js under pages/api/. We get the name and email from the request body and call the sendEmail function from the resend library with our EmailTemplate.</p><pre>const resend = new Resend(process.env.RESEND_API_KEY);<br><br>const data = await resend.sendEmail({<br>    from: `${process.env.FROM_EMAIL}`,<br>    to: `${process.env.TO_EMAIL}`,<br>    subject: &quot;🎉New submission to your contact form!&quot;,<br>    html: &quot;&quot;,<br>    react: EmailTemplate({ name, email })<br>});</pre><p>The following variables should be declared in the .env file:</p><ul><li>RESEND_API_KEY — API key generated in the previous section in the Resend admin.</li><li>FROM_EMAIL — the email address, from which the mail is to be shown to be sent from. It should be from the domain verified in the Resend admin.</li><li>TO_EMAIL — the email, to which the mail should be sent to. In this case, I am sending the mail to my email id.</li></ul><pre>import { EmailTemplate } from &#39;../../components/email/contact-form&#39;;<br>import { Resend } from &#39;resend&#39;;<br><br>const resend = new Resend(process.env.RESEND_API_KEY);<br><br>export default async (req, res) =&gt; {<br>  try {<br>    const { name, email } = JSON.parse(req.body);<br><br>    const data = await resend.sendEmail({<br>        from: `${process.env.FROM_EMAIL}`,<br>        to: `${process.env.TO_EMAIL}`,<br>        subject: &quot;🎉New submission to your contact form!&quot;,<br>        html: &quot;&quot;,<br>        react: EmailTemplate({ name, email })<br>    });<br><br>    res.status(200).json(data);<br>  } catch (error) {<br>    res.status(400).json(error);<br>  }<br>};</pre><p>You can alternatively set the to to the submitted email id so that an email is sent directly to the user upon submission.</p><h4>3. Trigger Email on Form Submit</h4><p>We can create the handleSubmit function and call the api/send API to trigger the email with name and email as parameters in the body.</p><pre>const [name, setName] = useState(&quot;&quot;);<br>const [email, setEmail] = useState(&quot;&quot;);<br>const [loading, setLoading] = useState(false);<br><br>const handleSubmit = async (e) =&gt; {<br>    setLoading(true);<br>    e.preventDefault();<br><br>    if (name == &quot;&quot; &amp;&amp; email == &quot;&quot;) {<br>        setLoading(false);<br>        alert(&quot;Please enter both name &amp; email id&quot;);<br>        return false;<br>    }<br><br>    await fetch(&quot;/api/send&quot;, {<br>        method: &quot;POST&quot;,<br>        body: JSON.stringify({ name, email }),<br>    })<br>        .then((res) =&gt; res.json())<br>        .then((data) =&gt; {<br>            setLoading(false);<br>            if (data &amp;&amp; data.id) {<br>                alert(`Thank you for your interest ${name}! We will get back to you soon!`);<br>                setName(&quot;&quot;);<br>                setEmail(&quot;&quot;);<br>            } else {<br>                alert(&quot;Apologies! Please try again.&quot;);<br>            }<br>        })<br>        .catch((err) =&gt; {<br>            setLoading(false);<br>            alert(&quot;Ooops! unfortunately some error has occurred.&quot;);<br>        });<br>    return true;<br>};</pre><p>With that, you have connected Resend to your Next.js app. Here is the final code of the index page:</p><pre><br>import { useState } from &quot;react&quot;;<br>import Head from &quot;next/head&quot;;<br><br>export default function Home() {<br>    const [name, setName] = useState(&quot;&quot;);<br>    const [email, setEmail] = useState(&quot;&quot;);<br>    const [loading, setLoading] = useState(false);<br><br>    const handleSubmit = async (e) =&gt; {<br>        setLoading(true);<br>        e.preventDefault();<br><br>        if (name == &quot;&quot; &amp;&amp; email == &quot;&quot;) {<br>            setLoading(false);<br>            alert(&quot;Please enter both name &amp; email id&quot;);<br>            return false;<br>        }<br><br>        await fetch(&quot;/api/send&quot;, {<br>            method: &quot;POST&quot;,<br>            body: JSON.stringify({ name, email }),<br>        })<br>            .then((res) =&gt; res.json())<br>            .then((data) =&gt; {<br>                setLoading(false);<br>                if (data &amp;&amp; data.id) {<br>                    alert(`Thank you for your interest ${name}! We will get back to you soon!`);<br>                    setName(&quot;&quot;);<br>                    setEmail(&quot;&quot;);<br>                } else {<br>                    alert(&quot;Apologies! Please try again.&quot;);<br>                }<br>            })<br>            .catch((err) =&gt; {<br>                setLoading(false);<br>                alert(&quot;Ooops! unfortunately some error has occurred.&quot;);<br>            });<br>        return true;<br>    };<br>    return (<br>        &lt;main<br>            className={`flex flex-col items-center p-24 min-h-screen`}<br>        &gt;<br>            &lt;Head&gt;<br>                &lt;title&gt;Contact Me | Coffeed&lt;/title&gt;<br>            &lt;/Head&gt;<br><br>            &lt;div className=&quot;relative flex flex-col gap-4 &quot;&gt;<br>                &lt;div className=&quot;flex flex-col place-items-center gap-4&quot;&gt;<br>                    &lt;h1 className={`m-0 text-center text-3xl`}&gt;Contact Me&lt;/h1&gt;<br>                &lt;/div&gt;<br>                &lt;form<br>                    className=&quot;mt-6 flex flex-col max-w-xl gap-4 z-10&quot;<br>                    onSubmit={handleSubmit}<br>                &gt;<br>                    &lt;label htmlFor=&quot;name&quot; className=&quot;sr-only&quot;&gt;<br>                        Name<br>                    &lt;/label&gt;<br>                    &lt;input<br>                        id=&quot;name&quot;<br>                        name=&quot;name&quot;<br>                        type=&quot;text&quot;<br>                        autoComplete=&quot;name&quot;<br>                        required<br>                        value={name}<br>                        className=&quot;rounded-md bg-white/5 px-3.5 py-2.5 text-white ring-1 ring-inset focus:ring-blue-600 text-sm md:w-96&quot;<br>                        placeholder=&quot;Name&quot;<br>                        onChange={(e) =&gt; setName(e.target.value)}<br>                    /&gt;<br>                    &lt;label htmlFor=&quot;email-address&quot; className=&quot;sr-only&quot;&gt;<br>                        Email address<br>                    &lt;/label&gt;<br>                    &lt;input<br>                        id=&quot;email-address&quot;<br>                        name=&quot;email&quot;<br>                        type=&quot;email&quot;<br>                        autoComplete=&quot;email&quot;<br>                        required<br>                        value={email}<br>                        className=&quot;rounded-md bg-white/5 px-3.5 py-2.5 text-white ring-1 ring-inset focus:ring-blue-600 text-sm md:w-96&quot;<br>                        placeholder=&quot;Email&quot;<br>                        onChange={(e) =&gt; setEmail(e.target.value)}<br>                    /&gt;<br>                    &lt;button<br>                        type=&quot;submit&quot;<br>                        className=&quot;flex justify-center rounded-md bg-blue-600 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-500&quot;<br>                    &gt;<br>                        {loading ? (<br>                            &lt;div<br>                                style={{<br>                                    borderTopColor: &quot;transparent&quot;,<br>                                }}<br>                                className=&quot;w-4 h-4 border-2 border-white border-solid rounded-full animate-spin&quot;<br>                            &gt;&lt;/div&gt;<br>                        ) : (<br>                            &quot;Submit&quot;<br>                        )}<br>                    &lt;/button&gt;<br>                &lt;/form&gt;<br>            &lt;/div&gt;<br>        &lt;/main&gt;<br>    );<br>}<br></pre><p>On submitting the form, the mail will be sent to the TO_EMAIL set in the .env file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*gz3lKCbeBLz9nbZn4njpPg.png" /><figcaption>Contact form email submission</figcaption></figure><p>You can further make use of the email API and integrate it for other use-cases to get notified directly to your inbox.</p><p><em>This page is part of the Next.js playbook, which is in the works at Coffee. Drop a mail to </em><a href="/service/mailto:coffee@coffeeinc.in"><em>coffee@coffeeinc.in</em></a><em> if you want to get on the waitlist.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c558fc767e6" width="1" height="1" alt=""><hr><p><a href="https://blog.coffeeinc.in/how-to-send-mail-to-users-directly-from-next-js-using-resend-9c558fc767e6">How to send mail to users directly from Next.js using Resend?</a> was originally published in <a href="https://blog.coffeeinc.in/">Coffee Byte</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to setup dynamic meta tags for SEO using getServerSideProps in Next.js?]]></title>
            <link>https://blog.coffeeinc.in/how-to-setup-dynamic-meta-tags-for-seo-using-getserversideprops-in-next-js-9bad0ac9e9b0?source=rss-83a2f21a9c07------2</link>
            <guid isPermaLink="false">https://medium.com/p/9bad0ac9e9b0</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[harry-potter]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Kavya S]]></dc:creator>
            <pubDate>Fri, 22 Sep 2023 15:22:56 GMT</pubDate>
            <atom:updated>2023-09-26T08:29:16.712Z</atom:updated>
            <content:encoded><![CDATA[<p>In a previous article, we discussed about <a href="https://medium.com/coffeed/how-to-implement-meta-tags-for-better-seo-in-next-js-9042c45e2a1">leveraging the inbuilt SEO features of Next.js</a> for pages using the next/head library. We learnt on how we can add meta tags to our page to generate site previews and embeds for our pages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WXZ0b6lNmyAvdgSoa5jMrw.jpeg" /></figure><p>Working with meta tags on pages with listing content like home, product catalog, etc. is straightforward. We can preset this values and need not rely on fetched content for the page title.</p><p>However, in cases, where you have dynamic page title like category listing page, product detail page, etc., it would be useful to update the title dynamically. You can access the parameters from the url, and fetch data to update the Head dynamically, but because this is retrieved on the client side, it will be undefined when the link is shared.</p><p>To overcome this, we can make use of server side rendering and get the dynamic details to be retrieved at the server end rather than on the client end. In this article, we are going to create a basic Next.js app to fetch the <strong>Houses of Hogwarts</strong>. I will create a listing and detail page and show you how to make use of getServerSideProps to fetch data and send it to the page.</p><p><strong>Note: </strong>This article makes use of the pages router.</p><h3>Getting Started</h3><p><em>(you can alternatively make use of your own project and skip to the “Fetching Houses Detail Data” section if you already have a listing and a detail page).</em></p><p>We will create a Next.js project to display a list of houses of Hogwarts and on clicking each house, we can view details about it. We will make use of the following free API: <a href="https://wizard-world-api.herokuapp.com/Houses">https://wizard-world-api.herokuapp.com/Houses</a></p><p>Create a new Next.js project using:</p><pre>yarn create next-app</pre><p>For the project configuration, I have used the following settings. I have chosen to use tailwind for styling and the src directory to keep our code organized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*Z6gNOsP9u2WmphgakcHw9A.png" /></figure><h3>Creating the listing page</h3><p>For the listing page, we will fetch data from the API and list it in the UI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bDb2s4yt019g9VQcQAtKmg.png" /><figcaption>Displaying the list of houses and its founders</figcaption></figure><p>Now the traditional way of fetching data in a React application is to make use of the useEffect hook to call the fetch function.</p><pre>import { useEffect, useState } from &quot;react&quot;;<br>import CoffeeHead from &quot;@/components/CoffeeHead&quot;;<br>import Link from &quot;next/link&quot;;<br><br>export default function Home() {<br>    const [housesData, setHousesData] = useState([]);<br><br>    const fetchData = async () =&gt; {<br>        const res = await fetch(<br>            &quot;https://wizard-world-api.herokuapp.com/Houses&quot;<br>        );<br>        const data = await res.json();<br><br>        setHousesData(data);<br>    };<br>    useEffect(() =&gt; {<br>        fetchData();<br>    }, []);<br><br>    return (<br>        &lt;&gt;<br>            &lt;CoffeeHead<br>                title={&quot;Houses of Hogwarts&quot;}<br>                description={&quot;A Next.js app to list the houses of Hogwarts&quot;}<br>                image={`${process.env.NEXT_PUBLIC_SITE_URL}/Hogwarts-Houses.jpg`}<br>                page_url={process.env.NEXT_PUBLIC_SITE_URL}<br>            /&gt;<br>            &lt;h1 className=&quot;text-2xl font-bold text-center my-4&quot;&gt;<br>                Houses of Hogwarts<br>            &lt;/h1&gt;<br><br>            &lt;ul className=&quot;space-y-2 max-w-md m-auto&quot;&gt;<br>                {housesData.map((house) =&gt; (<br>                    &lt;li<br>                        key={house.id}<br>                        className=&quot;flex flex-col p-3 bg-white text-black border rounded&quot;<br>                    &gt;<br>                            &lt;p&gt;{house.name}&lt;/p&gt;<br>                            &lt;p className=&quot;text-sm text-gray-600&quot;&gt;<br>                                Founder: {house.founder}<br>                            &lt;/p&gt;<br>                    &lt;/li&gt;<br>                ))}<br>            &lt;/ul&gt;<br>        &lt;/&gt;<br>    );<br>}</pre><p>I have made use of the CoffeeHead component from the meta-tags article and because we know this is the home page, I have statically set the values for the title, description, image_url and page_url.</p><p>For the page_url and the image_url, I have retrieved the NEXT_PUBLIC_SITE_URL from the .env file so that I can account for the change in the url upon deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*rgLwFNmZ00MY4ahrSa0BEQ.png" /><figcaption>Home meta tags</figcaption></figure><h3>Link to the Listing Detail Page</h3><p>Dealing with the static listing page is easier when compared to the dynamic detail page. First, let us link the listing item to the detail page. We can do this by replacing li with Link to the detail page.</p><pre>&lt;Link<br>    key={house.id}<br>    href={`/houses/${house.id}`}<br>    className=&quot;flex flex-col p-3 bg-white text-black border rounded&quot;<br>&gt;<br>    &lt;p&gt;{house.name}&lt;/p&gt;<br>    &lt;p className=&quot;text-sm text-gray-600&quot;&gt;<br>        Founder: {house.founder}<br>    &lt;/p&gt;<br>&lt;/Link&gt;</pre><p>Here we have set the href to the houses detail page and we are passing the house.id to the page as a parameter</p><h3>Creating the Houses Detail page</h3><p>Let us create a detail page by making use of the dynamic routes feature that Next.js has provided us. Create a folder called houses in the pages folder and add a file called [id].js. This is the detail page.</p><p>First let us retrieve and display the id of the house passed as a parameter in the router. We do this by making use of the useRouter hook.</p><pre>import { useRouter } from &quot;next/router&quot;;<br>import React from &quot;react&quot;;<br><br>const HouseDetail = () =&gt; {<br>    const router = useRouter();<br>    const { id } = router.query;<br>    return &lt;div&gt;House ID: {id}&lt;/div&gt;;<br>};<br><br>export default HouseDetail;</pre><p>On clicking any of the houses, you will now see a detail page with like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*t9cBvTM62nPHKzZ0F3WZ1A.png" /><figcaption>Houses Detail page</figcaption></figure><h3>Fetching Houses Detail Data</h3><p>We can go with the traditional way of making use of the fetch function in the useEffect hook like we did for the home page. But since the useEffect hook is called on the client side, the page title and details will be undefined on page load or share. It will only render in the browser, which will not be useful to search engines or when the page is shared.</p><p>So, we will need to make use of getServerSideProps function and fetch our data on the server side.</p><pre>export const getServerSideProps = async (context) =&gt; {<br>    const { id } = context.query;<br><br>    const res = await fetch(<br>        `https://wizard-world-api.herokuapp.com/Houses/${id}`<br>    );<br>    const house = await res.json();<br>    house.image = `${process.env.NEXT_PUBLIC_SITE_URL}/Hogwarts-Houses.jpg`;<br><br>    const page_url = context.req.headers.host + `/houses/${id}`;<br>    <br>    return { props: { house, page_url } };<br>};</pre><p>I retrieve the id using the context and then fetch the data from the API. I also dynamically generate the page url using host from the request header. The house and page_url are then passed as props to the Page component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HjDPDUBGdMd6GBsuBva5TQ.png" /><figcaption>Houses Detail page</figcaption></figure><p>Here is the entire code for the detail page:</p><pre>import CoffeeHead from &quot;@/components/CoffeeHead&quot;;<br>import { useRouter } from &quot;next/router&quot;;<br>import React from &quot;react&quot;;<br><br>const HouseDetail = ({ house, page_url }) =&gt; {<br>    const router = useRouter();<br>    const { id } = router.query;<br>    return (<br>        &lt;&gt;<br>            &lt;CoffeeHead<br>                title={house.name}<br>                description={`${house.name} was founded by ${house.founder} and represented by ${house.animal}.`}<br>                image={house.image}<br>                page_url={page_url}<br>            /&gt;<br><br>            &lt;a<br>                href=&quot;#&quot;<br>                className=&quot;block max-w-md p-6 bg-white border border-gray-200 rounded-lg shadow m-auto mt-6&quot;<br>            &gt;<br>                &lt;h5 className=&quot;mb-2 text-2xl font-bold text-gray-900&quot;&gt;<br>                    {house.name}<br>                &lt;/h5&gt;<br>                &lt;p className=&quot;font-normal text-gray-700&quot;&gt;<br>                    Founded by {house.founder}<br>                &lt;/p&gt;<br>                &lt;p className=&quot;font-normal text-gray-700&quot;&gt;<br>                    House Animal: {house.animal}<br>                &lt;/p&gt;<br>            &lt;/a&gt;<br>        &lt;/&gt;<br>    );<br>};<br><br>export default HouseDetail;<br><br>export const getServerSideProps = async (context) =&gt; {<br>    const { id } = context.query;<br><br>    const res = await fetch(<br>        `https://wizard-world-api.herokuapp.com/Houses/${id}`<br>    );<br>    const house = await res.json();<br>    house.image = `${process.env.NEXT_PUBLIC_SITE_URL}/Hogwarts-Houses.jpg`;<br><br>    const page_url = context.req.headers.host + `/houses/${id}`;<br>    <br>    return { props: { house, page_url } };<br>};</pre><p>You will see that the meta tags are generated on the server side and rendered in the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*SmL0aEtrY2ksf4qIBk3M1A.png" /></figure><p>There you have it! Dynamically generated meta tags by making using of the SSR feature of Next.js.</p><p>If you want to know more about getServerSideProps, check out this page: <a href="https://nextjs.org/docs/pages/api-reference/functions/get-server-side-props">https://nextjs.org/docs/pages/api-reference/functions/get-server-side-props</a></p><p>Drop a comment if you have any questions.</p><p><em>This page is part of the Next.js playbook, which is in the works at Coffee. Drop a mail to </em><a href="/service/mailto:coffee@coffeeinc.in"><em>coffee@coffeeinc.in</em></a><em> if you want to get on the waitlist.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9bad0ac9e9b0" width="1" height="1" alt=""><hr><p><a href="https://blog.coffeeinc.in/how-to-setup-dynamic-meta-tags-for-seo-using-getserversideprops-in-next-js-9bad0ac9e9b0">How to setup dynamic meta tags for SEO using getServerSideProps in Next.js?</a> was originally published in <a href="https://blog.coffeeinc.in/">Coffee Byte</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to enable Native Sharing in your React/Next.js app?]]></title>
            <link>https://blog.coffeeinc.in/how-to-enable-native-sharing-in-your-react-next-js-app-9cb24b3964fb?source=rss-83a2f21a9c07------2</link>
            <guid isPermaLink="false">https://medium.com/p/9cb24b3964fb</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Kavya S]]></dc:creator>
            <pubDate>Tue, 19 Sep 2023 17:48:39 GMT</pubDate>
            <atom:updated>2023-09-25T13:43:23.968Z</atom:updated>
            <content:encoded><![CDATA[<p>Sharing content on the web has become an essential part of modern online experiences. Providing a seamless way for users to share articles, images, and other types of content across various social media platforms increases user engagement and helps spread the word.</p><p>react-web-share is a powerful library that simplifies the process of implementing web sharing functionality in your React applications. In this tutorial, we’ll explore how to use react-web-share in a Next.js project.</p><h3>Prerequisites</h3><p>Before we get started, make sure you have the following prerequisites in place:</p><ol><li>A Next.js project set up.</li><li>npm or yarn available on PATH.</li></ol><h3>Installing react-web-share</h3><p>To use react-web-share in your Next.js project, you need to install it first. Open your project directory in the terminal and run the following command:</p><pre>yarn add react-web-share</pre><p>Once the installation is complete, you can import and use react-web-share in your components.</p><h3>Using react-web-share</h3><p>Now, let’s walk through the steps to use react-web-share in your Next.js project.</p><h4>Step 1: Import react-web-share</h4><p>Create a new file called ShareButton.js in your components folder. In the React component file, import the necessary modules:</p><pre>import { RWebShare } from &quot;react-web-share&quot;;</pre><h4>Step 2: Implement the Share Button</h4><p>You can create a share button that, when clicked, opens the native sharing dialog for the user. Here’s an example of a simple button component:</p><pre>import { RWebShare } from &quot;react-web-share&quot;;<br><br>const ShareButton = ({ title, text, url }) =&gt; {<br>    return (<br>        &lt;RWebShare<br>            data={{<br>                text: text,<br>                title: title,<br>                url: url,<br>            }}<br>        &gt;<br>            &lt;button&gt;Share&lt;/button&gt;<br>        &lt;/RWebShare&gt;<br>    );<br>};<br>export default ShareButton;</pre><p>react-web-share takes 3 main parameters:</p><ul><li>title — used for subject/title in apps, which support it.</li><li>content — used for the body of the message in apps, which support it.</li><li>url — used for copy link</li></ul><p>You can send these parameters from the page where you want to use the ShareButton</p><h4>Step 3: Use the ShareButton</h4><p>Now, you can use the ShareButton component in your Next.js application. Here’s an example of how to do this in a page component:</p><pre>import React from &quot;react&quot;;<br>import ShareButton from &quot;../components/ShareButton&quot;;<br><br>const post = {<br>    title: &quot;Showcasing the Share button&quot;,<br>    content:<br>        &quot;Coffeed is a publication run by Coffee (coffeeinc.in) to bring you a weekly dose of inspiration, experiments and guidance to build out your ideas.&quot;,<br>    url: &quot;https://blog.coffeeinc.in&quot;<br>};<br>const ShareCoffeed = () =&gt; {<br>    return (<br>        &lt;div&gt;<br>            &lt;h1&gt;{post.title}&lt;/h1&gt;<br>            &lt;p&gt;{post.content}&lt;/p&gt;<br>            &lt;ShareButton<br>                title={post.title}<br>                text={post.content}<br>                url={post.url}<br>            /&gt;<br>        &lt;/div&gt;<br>    );<br>};<br>export default ShareCoffeed;</pre><p>In this example, replace {post.title}, {post.content}, and {post.url} with your actual title, content and url data.</p><h4>Step 4: Styling (Optional)</h4><p>You can style the ShareButton component to match your application’s design by adding CSS or using a CSS framework like Tailwind CSS or Bootstrap.</p><h4>Step 5: Testing</h4><p>Now, when a user clicks the “Share” button, the native sharing dialog will open, allowing them to share your content on various social media platforms or through other sharing channels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EKmegt1adjprU_c181pIZg.png" /><figcaption>Share on windows</figcaption></figure><h3>Conclusion</h3><p>Implementing web sharing functionality in your Next.js application using react-web-share is a straightforward process. This library simplifies the complex task of interacting with native sharing dialogs, making it easier for your users to share your content with their network.</p><p>By following the steps outlined in this tutorial and customizing the code to your needs, you can enhance the social sharing experience of your web application. Happy sharing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9cb24b3964fb" width="1" height="1" alt=""><hr><p><a href="https://blog.coffeeinc.in/how-to-enable-native-sharing-in-your-react-next-js-app-9cb24b3964fb">How to enable Native Sharing in your React/Next.js app?</a> was originally published in <a href="https://blog.coffeeinc.in/">Coffee Byte</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to implement meta tags for better SEO in Next.js?]]></title>
            <link>https://blog.coffeeinc.in/how-to-implement-meta-tags-for-better-seo-in-next-js-9042c45e2a1?source=rss-83a2f21a9c07------2</link>
            <guid isPermaLink="false">https://medium.com/p/9042c45e2a1</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[seo]]></category>
            <dc:creator><![CDATA[Kavya S]]></dc:creator>
            <pubDate>Wed, 06 Sep 2023 14:21:27 GMT</pubDate>
            <atom:updated>2023-10-12T12:22:07.804Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fp0WMBxsh1718LVFz3H9vw.png" /></figure><p>When starting out with a new website, it is good to have one key aspect sorted out of the box: the meta tags. Not only the meta tags serve to inform your users on the site title in their browsers, but it also provides information to search engines when your site is being indexed.</p><p>Further, some of these tags also can be used to customize the site preview when sharing to social platforms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*dwiwZXEv9Ug292VvNhe2wg.png" /><figcaption>Site preview on twitter</figcaption></figure><p>Starting out it would be frustrating to see the site favicon and title. So you would end up with something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*Z_BabldTVZoxlb_fpatEpQ.png" /></figure><p>Or even worse, with no title tag, it defaults to the site url and you have this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*BOO6ZoWnnzaNEdJasx9zpQ.png" /></figure><p>I will help you customize this title and we will even go a step further and customize many of the other available meta tags. With Next.js, we can customize the &lt;head&gt; tags in each and every page of the website and leverage the best of server side rendered pages.</p><h3>Getting started</h3><p>Ideally, you would already have your Next.js app setup. If not, you can use the following command to bootstrap your new app:</p><pre>yarn create next-app</pre><p>Head on over to any of your pages in the pages folder. Here for example I am going to work with the index page. We are going to be using the Head component from next/head</p><pre>import Head from &#39;next/head&#39;</pre><p>Then we can use the head component in our page as follows:</p><pre>&lt;Head&gt;<br>  &lt;title&gt;Home | My awesome app&lt;/title&gt;<br>&lt;/Head&gt;</pre><p>In between the &lt;Head&gt;&lt;/Head&gt; tags we can make use of the meta tags just like a normal html page. The added advantage of this is that this page title can be dynamically generated by making use of variables in the page.</p><p>Here is the full code of the index page:</p><pre>import Head from &#39;next/head&#39;<br><br>export default function Home() {<br>  return (<br>    &lt;&gt;<br>      &lt;Head&gt;<br>          &lt;title&gt;Home | My awesome app&lt;/title&gt;<br>      &lt;/Head&gt;<br>      &lt;p&gt;Hello Universe!&lt;/p&gt;<br>    &lt;/&gt;<br>  )<br>}</pre><p>Now, if you check the app in the browser, you will find the title has been updated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*MQq8_zUjYUBp-CrahV8E0w.png" /></figure><h3>Digging in deeper</h3><p>Now that we have added the title tag, below are listed a few of the other tags we can add in the Head section. Let’s go in deeper to setup more of these tags in the page and optimize our on-page SEO.</p><h4>1. Meta description</h4><p>Page description should be between 160–200 characters.</p><pre>&lt;meta name=&quot;description&quot; content=&quot;Describe in 160-200 characters about <br>    my awesome app&quot; /&gt;</pre><h4>2. Open Graph Tags</h4><p>Open graph tags are used by facebook to render the site preview.</p><ul><li>og:type — type of the page: “website” or “article”</li><li>og:title — title of the page — can be same as &lt;title&gt; tag</li><li>og:description — description of the page — Can be same as the meta description</li><li>og:url — url of the page</li><li>og:image — link to the image to shown in the site preview</li></ul><pre>&lt;meta key=&quot;og:type&quot; property=&quot;og:type&quot; content={&quot;website&quot;} /&gt;<br>&lt;meta key=&quot;og:title&quot; property=&quot;og:title&quot; content={&quot;Title of my page&quot;} /&gt;<br>&lt;meta<br>    key=&quot;og:description&quot;<br>    property=&quot;og:description&quot;<br>    content={&quot;Description of my page&quot;}<br>/&gt;<br>&lt;meta<br>    key=&quot;og:url&quot;<br>    property=&quot;og:url&quot;<br>    content={&quot;site url&quot;}<br>/&gt;<br>&lt;meta key=&quot;og:image&quot; property=&quot;og:image&quot; content={&quot;Link to cover image&quot;} /&gt;</pre><p>Read more about Meta’s og tags <a href="https://developers.facebook.com/docs/sharing/webmasters/">here</a>.</p><h4>3. Twitter tags</h4><p>These tags are used to generate a preview in twitter.</p><ul><li>twitter:card — The card type</li><li>twitter:site — your twitter <a href="http://twitter.com/username">@username</a></li><li>twitter:title — Title of content (max 70 characters)</li><li>twitter:description— Description of content (maximum 200 characters)</li><li>twitter:image — URL of image to use in the card. Images must be less than 5MB in size.</li></ul><pre>&lt;meta property=&quot;twitter:card&quot; content=&quot;summary_large_image&quot; /&gt;<br>&lt;meta property=&quot;twitter:site&quot; content={&quot;@twitter_handle&quot;} /&gt;<br>&lt;meta property=&quot;twitter:title&quot; content={&quot;Title of the page&quot;} /&gt;<br>&lt;meta property=&quot;twitter:description&quot; content={&quot;Description of the page&quot;} /&gt;<br>&lt;meta property=&quot;twitter:image&quot; content={&quot;Link to image preview&quot;} /&gt;</pre><p>Read more about twitter cards markup <a href="https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/markup">here</a>.</p><h3>Bringing it all together</h3><p>Now that you have a better understanding of the meta tags that you can use, you can bring it all together on your page like this:</p><pre>&lt;Head&gt;<br>    &lt;title&gt;Home | My awesome app&lt;/title&gt;<br>    &lt;meta key=&quot;og:type&quot; property=&quot;og:type&quot; content={&quot;website&quot;} /&gt;<br>    &lt;meta key=&quot;og:title&quot; property=&quot;og:title&quot; content={&quot;Title of my page&quot;} /&gt;<br>    &lt;meta<br>        key=&quot;og:description&quot;<br>        property=&quot;og:description&quot;<br>        content={&quot;Description of my page&quot;}<br>    /&gt;<br>    &lt;meta<br>        key=&quot;og:url&quot;<br>        property=&quot;og:url&quot;<br>        content={&quot;URL of the page&quot;}<br>    /&gt;<br>    &lt;meta key=&quot;og:image&quot; property=&quot;og:image&quot; content={&quot;Link to cover image&quot;} /&gt;<br>    &lt;meta property=&quot;twitter:card&quot; content=&quot;summary_large_image&quot; /&gt;<br>    &lt;meta property=&quot;twitter:site&quot; content={&quot;@twitter_handle&quot;} /&gt;<br>    &lt;meta property=&quot;twitter:title&quot; content={&quot;Title of the page&quot;} /&gt;<br>    &lt;meta property=&quot;twitter:description&quot; content={&quot;Description of the page&quot;} /&gt;<br>    &lt;meta property=&quot;twitter:image&quot; content={&quot;Link to image preview&quot;} /&gt;<br>&lt;/Head&gt;</pre><p>There you go! Now your site is supercharged with meta tags and organic SEO.</p><h3>Bonus</h3><p>If you plan to use the same title, description and image for all the platforms, you can make use of the following custom component:</p><pre>import Head from &#39;next/head&#39;;<br><br>const CoffeeHead = ({<br>    title,<br>    description,<br>    image,<br>    page_url,<br>}) =&gt; {<br>    return (<br>        &lt;Head&gt;<br>            &lt;title&gt;{title}&lt;/title&gt;<br>            &lt;meta name=&quot;title&quot; content={title} /&gt;<br>            &lt;meta name=&quot;description&quot; content={description} /&gt;<br>            &lt;meta key=&quot;og:type&quot; property=&quot;og:type&quot; content={&quot;website&quot;} /&gt;<br>            &lt;meta key=&quot;og:title&quot; property=&quot;og:title&quot; content={title} /&gt;<br>            &lt;meta<br>                key=&quot;og:description&quot;<br>                property=&quot;og:description&quot;<br>                content={description}<br>            /&gt;<br>            &lt;meta<br>                key=&quot;og:url&quot;<br>                property=&quot;og:url&quot;<br>                content={page_url}<br>            /&gt;<br>            &lt;meta key=&quot;og:image&quot; property=&quot;og:image&quot; content={image} /&gt;<br>            &lt;meta property=&quot;twitter:card&quot; content=&quot;summary_large_image&quot; /&gt;<br>            &lt;meta property=&quot;twitter:site&quot; content={process.env.SOCIAL_HANDLE} /&gt;<br>            &lt;meta property=&quot;twitter:title&quot; content={title} /&gt;<br>            &lt;meta property=&quot;twitter:description&quot; content={description} /&gt;<br>            &lt;meta property=&quot;twitter:image&quot; content={image} /&gt;<br>        &lt;/Head&gt;<br>    );<br>};<br><br>export default CoffeeHead;</pre><p>Now include the CoffeeHead component in your page like below:</p><pre>import CoffeeHead from &#39;components/CoffeeHead&#39;;<br><br>export default function Home() {<br>  return (<br>    &lt;&gt;<br>      &lt;CoffeeHead<br>          title=&quot;Home | My awesome app&quot;<br>          description=&quot;Describing my awesome app within 200 characters&quot;<br>          image=&quot;https://i.pinimg.com/474x/33/05/02/330502e36c568fe40122856d8467823c.jpg&quot;<br>          page_url={&quot;https://myawesomeapp.com&quot;}<br>         /&gt;<br>      &lt;p&gt;Hello Universe!&lt;/p&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><p>Hope that helped you kickstart your on page SEO.</p><p><em>This page is part of the Next.js playbook, which is in the works at Coffee. Drop a mail to </em><a href="/service/mailto:coffee@coffeeinc.in"><em>coffee@coffeeinc.in</em></a><em> if you want to get on the waitlist.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9042c45e2a1" width="1" height="1" alt=""><hr><p><a href="https://blog.coffeeinc.in/how-to-implement-meta-tags-for-better-seo-in-next-js-9042c45e2a1">How to implement meta tags for better SEO in Next.js?</a> was originally published in <a href="https://blog.coffeeinc.in/">Coffee Byte</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Supercharge your Front-end App hosted in Vercel with Web Analytics?]]></title>
            <link>https://blog.coffeeinc.in/how-to-supercharge-your-front-end-app-hosted-in-vercel-with-web-analytics-f518e00a30ca?source=rss-83a2f21a9c07------2</link>
            <guid isPermaLink="false">https://medium.com/p/f518e00a30ca</guid>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[vercel]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Kavya S]]></dc:creator>
            <pubDate>Wed, 16 Aug 2023 14:17:38 GMT</pubDate>
            <atom:updated>2023-08-28T08:13:39.397Z</atom:updated>
            <content:encoded><![CDATA[<p>Vercel has come to be a very reliable hosting platform for front-end projects. If you are making use of Vercel for hosting your frontend app, then you can supercharge your app with “Privacy-friendly, real-time traffic insights”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*b5yAT2FtlxtZg6RG.png" /></figure><p>Through the use of Web Analytics, you can get insights into the visitors of your website with metrics like page views &amp; visitors, top referrers, and demographic details such as countries, operating systems, and browser specifics.</p><p>Let’s get started with Vercel Web Analytics.</p><h3>1. Enable Web Analytics on the Dashboard</h3><p>Head to your Vercel dashboard and select a project. Click on the “Analytics” tab and click on “Next” in the popup and select “Enable”. The Free plan includes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*pXtUnZpk6ycRqKLV" /></figure><h3>2. Add @vercel/analytics to your project</h3><p>Once you have enabled Web analytics, head over to your frontend project and add @vercel/analytics using your package manager like yarn.</p><pre>yarn add @vercel/analytics</pre><p>Vercel will be waiting for data, which we will send by initializing the package in the next step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*bMAEQX7h35CB3N-4" /><figcaption>Awaiting Data…</figcaption></figure><h3>3. Import &lt;Analytics /&gt; component in your front-end app</h3><p>Now that you have added the package, import the Analytics component in the main layout of your project from @vercel/analytics/react. I have given an example below, including Analytics in a Next.js project.</p><pre>import { Analytics } from &#39;@vercel/analytics/react&#39;;<br><br>function MyFrontendApp({ Component, pageProps }) {<br>  return (<br>    &lt;&gt;<br>      &lt;Component {...pageProps} /&gt;<br>      &lt;Analytics /&gt;<br>    &lt;/&gt;<br>  );<br>}<br><br>export default MyFrontendApp;</pre><h3>4. Deploy your app to Vercel</h3><p>As I mentioned at the start of the post, this analytics package works with Vercel. So, make sure to deploy your project to Vercel and you will see the analytics page of your project get updated with stats.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*2gPFlZsuPAfVHDTc" /><figcaption>Analytics Dashboard</figcaption></figure><p>If you want more specific instructions based on the front-end framework you have used, check out the <a href="https://vercel.com/docs/analytics/quickstart">Vercel Web Analytics documentation</a>.</p><p>And there you have it, your front-end app supercharged with Analytics from Vercel. You will get a live feed of page views and visitors on your website including the number of active people online. Let me know in the comments if you found this useful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f518e00a30ca" width="1" height="1" alt=""><hr><p><a href="https://blog.coffeeinc.in/how-to-supercharge-your-front-end-app-hosted-in-vercel-with-web-analytics-f518e00a30ca">How to Supercharge your Front-end App hosted in Vercel with Web Analytics?</a> was originally published in <a href="https://blog.coffeeinc.in/">Coffee Byte</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>