<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Pratham Dupare</title>
    <description>The latest articles on Forem by Pratham Dupare (@prathamdupare).</description>
    <link>https://forem.com/prathamdupare</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1400056%2F13042db0-3dfe-4246-b424-4f2e0121b2ca.jpeg</url>
      <title>Forem: Pratham Dupare</title>
      <link>https://forem.com/prathamdupare</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/prathamdupare"/>
    <language>en</language>
    <item>
      <title>How I got a Software Developer Job without CS degree or Bootcamp!</title>
      <dc:creator>Pratham Dupare</dc:creator>
      <pubDate>Mon, 27 Jan 2025 05:15:02 +0000</pubDate>
      <link>https://forem.com/prathamdupare/how-i-got-a-software-developer-job-without-cs-degree-or-bootcamp-132h</link>
      <guid>https://forem.com/prathamdupare/how-i-got-a-software-developer-job-without-cs-degree-or-bootcamp-132h</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;code&gt;How I Went from a Non-CS Background to Landing a Job as a Software Engineer&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Starting Out: The Dream of Becoming a Scientist
&lt;/h3&gt;

&lt;p&gt;It all started in my third year at IISER Bhopal, one of India’s premier institutions for scientific education and research. Since childhood, I had always wanted to become a scientist, and IISER seemed like the perfect place to make that happen. However, things took an unexpected turn when, due to my not-so-great grades, I was assigned Mathematics as my major instead of Physics, which I was genuinely passionate about.&lt;/p&gt;

&lt;p&gt;At this point, software development was not even on my radar — I didn’t even know what coding was. A year later, my lack of interest in Mathematics made things worse. I failed several courses, couldn’t pass the re-exams, and ultimately had to take a year off. It was a rough time, and I felt really lost.&lt;/p&gt;

&lt;h2&gt;
  
  
  Discovering a New Interest
&lt;/h2&gt;

&lt;p&gt;During that year off, I started getting interested in Linux. I tinkered with it, customized it, and started learning basic bash scripting. This was my first taste of programming, and it piqued my curiosity. When I got back to college, I realized I couldn’t keep going down the same path. Since I enjoyed working with Linux, I thought, “Why not try programming?”&lt;/p&gt;

&lt;p&gt;The next question was: what type of programming?&lt;/p&gt;

&lt;h2&gt;
  
  
  Researching My Options
&lt;/h2&gt;

&lt;p&gt;I researched the field and found that getting into software development without a degree was rare but possible. One of the videos I watched introduced me to an open-source guide called &lt;a href="https://www.theodinproject.com" rel="noopener noreferrer"&gt;The Odin Project&lt;/a&gt;. This community-maintained project follows a “learn by doing” approach, which was perfect for me.&lt;/p&gt;

&lt;p&gt;Now, I had a direction. I was fortunate to still be in college, with only one or two courses per semester and fixed meal timings, giving me the time I needed to focus on programming. I set a routine: I’d wake up, work out, have breakfast, and head to the library by 8 a.m. I’d spend my entire day there coding and learning, trying to complete &lt;em&gt;The Odin Project&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Of course, it wasn’t all smooth sailing. There were exams, days of low motivation, and setbacks. But I loved every bit of the journey. I enjoyed solving problems and felt I could pursue this long-term.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building Skills and Projects
&lt;/h2&gt;

&lt;p&gt;It took me about a year and a half to complete &lt;em&gt;The Odin Project&lt;/em&gt;. Along the way, I gained knowledge in full-stack development — HTML, CSS, JavaScript, React, Node.js — and other skills like using the command line, deployment, and Vim, my beloved code editor.&lt;/p&gt;

&lt;p&gt;After that, it was time to showcase my skills by building projects and applying for jobs. I didn’t stop learning. While many others were stuck on React, I learned Next.js and created projects, even building websites for some of my college professors.&lt;/p&gt;

&lt;h2&gt;
  
  
  Applying for Jobs and Freelancing
&lt;/h2&gt;

&lt;p&gt;I started working on my LinkedIn profile and applied everywhere: LinkedIn, Wellfound (formerly AngelList Talent), Internshala. Most applications went unanswered, and some that did had tasks I couldn’t complete. So, I began posting on LinkedIn, sharing things I was working on or found interesting.&lt;/p&gt;

&lt;p&gt;I knew I needed experience and a solid resume to stand out, so I started freelancing. I landed a few gigs on Upwork and won two online hackathons — one solo and one with developer friends I met on Discord. I also maintained a blog and wrote on Medium.&lt;/p&gt;

&lt;h2&gt;
  
  
  Focusing on Data Structures and Algorithms (DSA)
&lt;/h2&gt;

&lt;p&gt;Eventually, I started getting interviews but struggled with data structures and algorithms (DSA), which I hadn’t focused on much. After some failed interviews, I spent a month working on DSA.&lt;/p&gt;

&lt;p&gt;Then, out of nowhere, an HR intern from a startup in Bhopal messaged me. I sent over my resume, and after about 10–15 days, they called me in for an interview. Fortunately, I got in! I was offered a Software Developer Intern position, which would convert into a full-time role once I finished college. The role allows me to work remotely until then.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Journey Ahead
&lt;/h2&gt;

&lt;p&gt;Maybe I got lucky, but as they say, “The harder you work, the luckier you get.” I know there’s still a lot to learn and areas where I need to grow. I’m committed to continuous learning, freelancing, building hobby projects, and picking up new languages.&lt;/p&gt;

&lt;p&gt;I recently joined the Medium Partner Program, so if you enjoyed my story, consider giving it a clap!&lt;/p&gt;

&lt;h2&gt;
  
  
  Connect with Me
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;GitHub&lt;/li&gt;
&lt;li&gt;Instagram&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thank you for reading my story!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>My dev workflow - Linux, Hyprland ,Neovim and Tmux.</title>
      <dc:creator>Pratham Dupare</dc:creator>
      <pubDate>Mon, 27 Jan 2025 05:04:04 +0000</pubDate>
      <link>https://forem.com/prathamdupare/my-dev-workflow-linux-hyprland-neovim-and-tmux-59lb</link>
      <guid>https://forem.com/prathamdupare/my-dev-workflow-linux-hyprland-neovim-and-tmux-59lb</guid>
      <description>&lt;p&gt;Disclaimer: This is not a guide on how I rice my Window manager, what terminal I use, it's purely how I use my tools.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;The time has come for me to share my developer workflow and how I use my tools to become a PRO developer!&lt;/p&gt;

&lt;h3&gt;
  
  
  What I Don't Focus On
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;GPU-rendered terminals (e.g., &lt;em&gt;Alacritty&lt;/em&gt;).&lt;/li&gt;
&lt;li&gt;Ricing my desktop or color schemes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What Matters
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Speed&lt;/li&gt;
&lt;li&gt;Lower mental overhead&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Tools I Use for the Perfect Developer Workflow
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Linux&lt;/strong&gt; (of course!)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Window Manager&lt;/strong&gt;: Hyprland (with animations disabled)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Terminal&lt;/strong&gt;: foot (since I use Wayland)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Terminal Multiplexer&lt;/strong&gt;: Tmux&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you’re using Mac, great! Try to replicate this setup and find tools that make you fast and productive. If you use Windows, consider upgrading your RAM and playing some games; that's all I can suggest.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Window Management
&lt;/h3&gt;

&lt;p&gt;Most common Linux distros come with GNOME or KDE Plasma, which are excellent and a big reason for Linux’s recent improvements. However, I prefer not to use them because I don't want to rely on the mouse to manage windows. I prefer a window manager to streamline my workflow.&lt;/p&gt;

&lt;h4&gt;
  
  
  Tiling Window Manager
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F81zdjphr47dmenyk5zl8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F81zdjphr47dmenyk5zl8.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A tiling window manager automatically tiles and splits your windows, allowing you to quickly view and manage your open applications. I have set my &lt;code&gt;ALT&lt;/code&gt; key as the main modifier, and use the following shortcuts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Alt + 1&lt;/code&gt; to switch to my browser on the 1st workspace.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Alt + 2&lt;/code&gt; to switch to my terminal on the 2nd workspace.&lt;/li&gt;
&lt;li&gt;And so on, with workspaces typically maximized.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This setup allows me to quickly switch between tasks without worrying about window positions.&lt;/p&gt;

&lt;p&gt;I can cycle through windows using &lt;code&gt;Alt + HJKL&lt;/code&gt;, similar to Vim. Focused windows have highlighted borders, making navigation straightforward.&lt;/p&gt;

&lt;h3&gt;
  
  
  Terminal Workflow
&lt;/h3&gt;

&lt;p&gt;In my terminal, I use &lt;code&gt;tmux&lt;/code&gt;, a terminal multiplexer that lets you split your terminal into multiple panes. This setup eliminates the need to switch between workspaces just to work on another terminal. It also helps me avoid multiple displays, which can be distracting and bad for posture.&lt;/p&gt;

&lt;h4&gt;
  
  
  Using Tmux
&lt;/h4&gt;

&lt;p&gt;Tmux has a prefix key (&lt;code&gt;Ctrl + a&lt;/code&gt; in my case) that triggers tmux commands. For example, after pressing the prefix key, you can switch between panes using numbers or navigate to the next pane with &lt;code&gt;prefix + n&lt;/code&gt;. Tmux also keeps sessions alive, so if you accidentally close the terminal window, you can resume your work by running &lt;code&gt;tmux a&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Programming
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy80du3gor3vibpej5tr2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy80du3gor3vibpej5tr2.jpg" alt="Image description" width="417" height="121"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For programming, I use Neovim instead of VS Code.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why Neovim?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;VS Code is bloated and slow.&lt;/li&gt;
&lt;li&gt;Neovim runs in the terminal.&lt;/li&gt;
&lt;li&gt;I prefer Vim motions for efficient text editing.&lt;/li&gt;
&lt;li&gt;I don’t use the mouse (more on this later).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Inside a Codebase
&lt;/h3&gt;

&lt;p&gt;When starting work, I navigate to the desired directory and run &lt;code&gt;nvim .&lt;/code&gt;, which opens Neovim in that directory (similar to VS Code’s &lt;code&gt;code .&lt;/code&gt;).&lt;/p&gt;

&lt;h4&gt;
  
  
  Opening a File
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqxnropw0qu156csfpbh2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqxnropw0qu156csfpbh2.png" alt="Image description" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Moving Between Files
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5xxmvaixddm0xhqq3npf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5xxmvaixddm0xhqq3npf.png" alt="Image description" width="800" height="435"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To manage multiple open files, I use the Harpoon plugin, developed by The Primeagen. Harpoon lets me mark frequently used files and switch between them easily without cluttering my workspace. It also saves cursor positions, enhancing productivity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This setup enables an exceptionally fast workflow and keeps development exciting. There is always room for improvement, and I’ve tailored my workflow to work best for me through experimentation and learning. The key is to try new things, step out of your comfort zone, and develop unique skills that make you a great developer.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>hyprland</category>
      <category>productivity</category>
      <category>terminal</category>
    </item>
    <item>
      <title>One Screen for Productivity</title>
      <dc:creator>Pratham Dupare</dc:creator>
      <pubDate>Mon, 27 Jan 2025 04:56:06 +0000</pubDate>
      <link>https://forem.com/prathamdupare/one-screen-for-productivity-g1g</link>
      <guid>https://forem.com/prathamdupare/one-screen-for-productivity-g1g</guid>
      <description>&lt;p&gt;You might have seen many people in productivity videos using multiple or wide-angle screens, and it might feel straightforward to believe that using multiple displays might improve productivity. However, it’s actually the opposite. How so?&lt;/p&gt;

&lt;p&gt;The best analogy I can think of is typing on a keyboard. The main reason people use touch typing to type fast is that it doesn’t make you look down at the keyboard while you're focused on the task. It makes you much faster than looking down. Looking at a secondary or multiple screens is similar. But what’s the proof of it, you might ask.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Benefits
&lt;/h2&gt;

&lt;p&gt;You may have seen people wearing hoodies or hats while they focus on something. This is beneficial because of how our brain works: when focused on one “not-big” area, it becomes alert and reduces distractions. I’m not saying you’ll definitely have distractions on other screens, but using a single screen can reduce eye and brain fatigue by minimizing the need to switch and process information across different places.&lt;/p&gt;

&lt;p&gt;In a podcast by Andrew Huberman called "Optimizing Workspace for Productivity, Focus, &amp;amp; Creativity," he discusses the benefits of narrow vision. Huberman recommends practicing either narrowing or broadening your visual focus. Narrow screens, like those on laptops, help us stay focused by limiting our visual area and keeping distractions at bay. Looking at a smaller screen is like putting "invisible blinders" on, similar to a horse’s blinders, which keep it looking straight ahead.&lt;/p&gt;

&lt;p&gt;This keeps our gaze steady and focused, allowing us to concentrate better. When using large monitors, our eyes tend to roam beyond this focus area, making it harder to stay attentive. Smaller screens keep our eyes in “focused mode,” which is ideal for paying attention to details. Simple tricks like cupping hands around the eyes or wearing a hat to block side vision also help keep us focused.&lt;/p&gt;

&lt;p&gt;I don’t recommend using smaller screens like a phone or tablet for work, as the font size on these devices might defeat the purpose by straining your eyes with small fonts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ergonomics
&lt;/h2&gt;

&lt;p&gt;Ergonomic research suggests that a single screen positioned directly in front of the user at eye level and within a 40–70 cm range promotes visual comfort and reduces neck strain. Dual screens, though useful for multitasking, often require side-to-side head movement, increasing neck and shoulder muscle load. Using a single screen helps maintain a stable head posture, minimizing muscle strain and enhancing ergonomic comfort.&lt;/p&gt;

&lt;h3&gt;
  
  
  Taking It One Step Further
&lt;/h3&gt;

&lt;p&gt;Now that we’ve discussed the benefits, the question remains: how to optimize this for a faster workflow?&lt;/p&gt;

&lt;p&gt;There are many ways to take this to the next level:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Using Keyboard Shortcuts to Move Between Windows or Workspaces
&lt;/h3&gt;

&lt;p&gt;Just like with typing, you can use the same skill to move quickly between windows or workspaces by pressing shortcut keys. Whatever operating system you’re using, there’s always an option to set quick shortcuts to achieve this.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Using a Tiling Window Manager or Extension
&lt;/h3&gt;

&lt;p&gt;A tiling window manager arranges open windows into non-overlapping tiles, keeping everything visible and organized on one screen. This setup, popular with Linux users, maximizes screen space and reduces the need to switch between windows. Non-Linux users can achieve similar results with tools like Microsoft PowerToys (Windows) or Rectangle (macOS), making workflows faster and more efficient.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Experiment
&lt;/h3&gt;

&lt;p&gt;This varies from person to person, but the key is to create a workflow tailored to your own needs and habits. This makes it both interesting and challenging. It’s like creating your computer’s identity, one that’s unique to you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Situations Where a Multi/Wide Setup Can Be Useful
&lt;/h2&gt;

&lt;p&gt;As we discussed, using a single screen can be very helpful for productivity, ergonomics, and other aspects. However, there are still some situations where a multi-monitor setup can be useful:&lt;/p&gt;

&lt;p&gt;As open-minded individuals, let’s consider these valid and important use cases:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Creative &amp;amp; Design Work&lt;/strong&gt;: Designers and video editors can separate their workspace from tools and previews, improving workflow.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Gaming &amp;amp; Entertainment&lt;/strong&gt;: Gamers and media consumers use wide screens for immersive gaming, and streamers can use a secondary monitor for reading chats, etc.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;While using a single screen setup can improve focus, reduce distractions, and enhance ergonomic comfort, it’s not a one-size-fits-all solution. Different people may find that multiple screens work better for their workflow, especially if their tasks involve design, analysis, or other highly visual work. Productivity setups are highly personal, and optimizing them often requires a bit of experimentation.&lt;/p&gt;

&lt;p&gt;Ultimately, it’s about finding what works best for you and adjusting your workspace to support your needs and goals. If you have other tips or experiences with different setups, I’d love to hear your suggestions in the comments. Thank you!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsf6cgj1x9x10l3rudo81.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsf6cgj1x9x10l3rudo81.jpg" alt="Image description" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>linux</category>
      <category>minimalism</category>
      <category>programming</category>
    </item>
    <item>
      <title>API Routes in Next.js - Part 4</title>
      <dc:creator>Pratham Dupare</dc:creator>
      <pubDate>Tue, 02 Apr 2024 04:55:24 +0000</pubDate>
      <link>https://forem.com/prathamdupare/api-routes-in-nextjs-part-4-4e7g</link>
      <guid>https://forem.com/prathamdupare/api-routes-in-nextjs-part-4-4e7g</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Next.js is a full-stack framework that enables you to develop both the frontend and backend seamlessly. In contrast to using Express.js for building the backend, where you might need to run a separate server on a different port, Next.js eliminates this need.&lt;/p&gt;

&lt;p&gt;Next.js employs a file-based routing system, making it convenient and efficient.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello World!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Example app listening on port &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that in the traditional Express.js example, app.listen specifies the port to which it must listen, requiring it to be continuously running to handle requests.&lt;/p&gt;

&lt;p&gt;Next.js covers all traditional backend features, including middlewares, parsing, authentication, and even serverless functions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the API Route
&lt;/h2&gt;

&lt;p&gt;Route Handlers allow you to create custom request handlers for a given route using the Web Request&lt;br&gt;
and Response&lt;br&gt;
APIs.&lt;/p&gt;

&lt;p&gt;Route Handlers are defined in a &lt;code&gt;route.js|ts&lt;/code&gt; file inside the &lt;code&gt;app&lt;/code&gt; directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//app/api/route.js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dynamic&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;force-dynamic&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// defaults to auto&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;GET&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Route Handlers can be nested inside the &lt;code&gt;app&lt;/code&gt; directory, similar to &lt;code&gt;page.js&lt;/code&gt; and &lt;code&gt;layout.js&lt;/code&gt;. But there cannot be a &lt;code&gt;route.js&lt;/code&gt; file at the same route segment level as &lt;code&gt;page.js&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;While Route Handlers can be nested inside the &lt;code&gt;app&lt;/code&gt; directory, similar to &lt;code&gt;page.js&lt;/code&gt; and &lt;code&gt;layout.js&lt;/code&gt;, it's crucial to avoid having a &lt;code&gt;route.js&lt;/code&gt; file at the same route segment level as &lt;code&gt;page.js&lt;/code&gt;. A recommended practice is to keep routes separate in another folder, commonly in &lt;code&gt;/api/*&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For instance, if you need a route at &lt;code&gt;/api/users&lt;/code&gt;, create a &lt;code&gt;users&lt;/code&gt; folder inside the &lt;code&gt;api&lt;/code&gt; directory and then add a &lt;code&gt;route.js&lt;/code&gt; file inside it. This route will correspond to &lt;code&gt;/api/users&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This route will point to &lt;code&gt;/api/users&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Supported HTTP Methods
&lt;/h2&gt;

&lt;p&gt;The following HTTP methods&lt;br&gt;
are supported: &lt;code&gt;GET&lt;/code&gt;, &lt;code&gt;POST&lt;/code&gt;, &lt;code&gt;PUT&lt;/code&gt;, &lt;code&gt;PATCH&lt;/code&gt;, &lt;code&gt;DELETE&lt;/code&gt;, &lt;code&gt;HEAD&lt;/code&gt;, and &lt;code&gt;OPTIONS&lt;/code&gt;. If an unsupported method is called, Next.js will return a &lt;code&gt;405 Method Not Allowed&lt;/code&gt; response.&lt;/p&gt;

&lt;p&gt;This is esentially everything you need.&lt;/p&gt;

&lt;p&gt;To handle a &lt;code&gt;GET&lt;/code&gt; request, you simply write a &lt;code&gt;GET&lt;/code&gt; function inside the &lt;code&gt;route.js&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;GET&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, Next.js!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You return the response as you would return from any regular express server.&lt;/p&gt;

&lt;p&gt;For example ,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//app/api/items/route.js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;GET&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://data.mongodb-api.com/...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;API-Key&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DATA_API_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similarly, and within the same file, you can use all other &lt;code&gt;HTTP&lt;/code&gt; verbs.&lt;br&gt;
To witness this specific API in your browser, go to: &lt;code&gt;http://localhost:3000/app/api/items&lt;/code&gt;.&lt;br&gt;
That's it! It's simple and intuitive.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Components and Optimisations in Next.js - Part 3</title>
      <dc:creator>Pratham Dupare</dc:creator>
      <pubDate>Tue, 02 Apr 2024 04:50:36 +0000</pubDate>
      <link>https://forem.com/prathamdupare/components-and-optimisations-in-nextjs-part-3-n68</link>
      <guid>https://forem.com/prathamdupare/components-and-optimisations-in-nextjs-part-3-n68</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Next.js comes with a variety of built-in optimizations designed to improve your application's speed and Core Web Vitals&lt;br&gt;
.&lt;/p&gt;
&lt;h2&gt;
  
  
  Built-in Components
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. Images Component:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Utilizes the native &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; element.&lt;/li&gt;
&lt;li&gt;Optimizes image performance by implementing lazy loading.&lt;/li&gt;
&lt;li&gt;Automatically resizes images based on the device size for improved responsiveness.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;//app/page.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Image&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next/image&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Page&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Image&lt;/span&gt;
      &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/profile.png"&lt;/span&gt;
      &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Picture of the author"&lt;/span&gt;
    &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The Image Component requires the following properties: &lt;code&gt;src&lt;/code&gt;, &lt;code&gt;width&lt;/code&gt;, &lt;code&gt;height&lt;/code&gt;, and &lt;code&gt;alt&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Link Component:
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;Link&amp;gt;&lt;/code&gt; component in Next.js is a React component that extends the HTML &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; element. It plays a crucial role in providing prefetching and enabling client-side navigation between routes. This component serves as the primary means of navigating between routes in a Next.js application.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Built on the native &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; tags.&lt;/li&gt;
&lt;li&gt;Prefetches pages in the background, enhancing page transition speed.&lt;/li&gt;
&lt;li&gt;Facilitates faster and smoother navigation between pages.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next/link&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Page&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/dashboard"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Dashboard&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;code&gt;href&lt;/code&gt; (required)&lt;br&gt;&lt;br&gt;
The path or URL to navigate to.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/dashboard"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Dashboard&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Linking to Dynamic Routes&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;//app/blog/page.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next/link&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Page&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;ul&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`/blog/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;ul&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, you can generate a list of links to the dynamic route &lt;code&gt;app/blog/[slug]/page.js&lt;/code&gt;:&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Scripts Component:
&lt;/h3&gt;

&lt;p&gt;This is self-explanatory, this let's you run scripts for a specific components.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Implemented with the native &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags.&lt;/li&gt;
&lt;li&gt;Provides control over the loading and execution of third-party scripts.&lt;/li&gt;
&lt;li&gt;Enables efficient management of external scripts for better overall performance.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Script&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next/script&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Dashboard&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Script&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://example.com/script.js"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Required Props for Script Component in Next.js&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;Script&amp;gt;&lt;/code&gt; component in Next.js requires the following property:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;src:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Type: String&lt;/li&gt;
&lt;li&gt;Description: A path string specifying the URL of an external script. This can be either an absolute external URL or an internal path.&lt;/li&gt;
&lt;li&gt;Requirement: The &lt;code&gt;src&lt;/code&gt; property is required unless an inline script is used.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Optional Props&lt;/strong&gt; :&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Prop&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Required&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;src&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;src="http://example.com/script"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;String&lt;/td&gt;
&lt;td&gt;Required unless inline script is used&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;strategy&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;strategy="lazyOnload"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;String&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;onLoad&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;onLoad={onLoadFunc}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Function&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;onReady&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;onReady={onReadyFunc}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Function&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;onError&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;onError={onErrorFunc}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Function&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For a comprehensive guide on Next.js components, refer to the &lt;a href="https://nextjs.org/docs/app/api-reference/components" rel="noopener noreferrer"&gt;Api Reference/Components&lt;/a&gt; section of the official Next.js documentation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Static Assets
&lt;/h2&gt;

&lt;p&gt;The Next.js &lt;code&gt;/public&lt;/code&gt; folder serves as a convenient location for hosting static assets such as images, fonts, and other files.&lt;/p&gt;

&lt;p&gt;Files stored within the &lt;code&gt;/public&lt;/code&gt; directory can be efficiently cached by Content Delivery Network (CDN) providers. This caching mechanism enhances the delivery speed of assets to users, resulting in a smoother browsing experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Metadata
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Next.js Metadata API for Improved SEO and Shareability&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next.js provides a Metadata API that allows you to define your application's metadata, including meta and link tags inside the HTML head element. This is crucial for enhancing SEO and improving web shareability.&lt;/p&gt;

&lt;p&gt;There are two methods to add metadata to your application:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Config-based Metadata:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Export a static metadata object or a dynamic &lt;code&gt;generateMetadata&lt;/code&gt; function in a &lt;code&gt;layout.js&lt;/code&gt; or &lt;code&gt;page.js&lt;/code&gt; file.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;File-based Metadata:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Add static or dynamically generated special files to route segments.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Regardless of the method chosen, Next.js will automatically generate the relevant &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; elements for your pages. Additionally, you can create dynamic Open Graph (OG) images using the &lt;code&gt;ImageResponse&lt;/code&gt; constructor for a more customized and engaging web sharing experience.&lt;/p&gt;

&lt;p&gt;To define static metadata, export a Metadata object from a &lt;code&gt;layout.js&lt;/code&gt;(we have already seen in previous chapter) or static &lt;code&gt;page.js&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;metadata&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Page&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These components and elements cover the fundamental requirements for constructing a speedy and responsive Next.js application.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Server components and Client Components in Next.js - Part 2</title>
      <dc:creator>Pratham Dupare</dc:creator>
      <pubDate>Tue, 02 Apr 2024 04:49:10 +0000</pubDate>
      <link>https://forem.com/prathamdupare/server-components-and-client-components-in-nextjs-part-2-312a</link>
      <guid>https://forem.com/prathamdupare/server-components-and-client-components-in-nextjs-part-2-312a</guid>
      <description>&lt;h2&gt;
  
  
  Server components
&lt;/h2&gt;

&lt;p&gt;By default, Next.js uses Server Components. This makes server rendering possible without any configuration and you can opt into using Client Components when needed.&lt;/p&gt;

&lt;p&gt;Reacr Server Components allow you to write UI that can be rendered and optionally cached on the server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Server Rendering
&lt;/h2&gt;

&lt;p&gt;There are a lot of benefits of server side rendering such as :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Fetching&lt;/strong&gt;: Fetching data on the server improves performance by reducing client-side data retrieval time and the number of requests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security: Keeping&lt;/strong&gt; sensitive data and logic on the server, such as tokens and API keys, prevents exposure to the client, enhancing security.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Caching&lt;/strong&gt; : Server-side rendering allows for caching, improving performance and reducing costs by reusing results across requests and users.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Bundle Sizes&lt;/strong&gt;: Large dependencies impacting client bundles are moved to the server, benefiting users with slower internet or less powerful devices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Initial Page Load and FCP&lt;/strong&gt;: Server-generated HTML enables immediate page viewing without waiting for client-side JavaScript execution.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;SEO and Shareability&lt;/strong&gt;: Rendered HTML aids search engine indexing and social network previews for better SEO and shareability.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Streaming&lt;/strong&gt;: Server Components enable rendering in chunks, allowing users to see parts of the page earlier, enhancing the user experience.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Rendering
&lt;/h2&gt;

&lt;p&gt;So how are server components rendered?&lt;/p&gt;

&lt;p&gt;On the server, Next.js uses React's API to start rendering. When requested on client, the html is used to immidiately show a fast non-interactive preview on the route.&lt;/p&gt;

&lt;h3&gt;
  
  
  Static and dynamic rendering
&lt;/h3&gt;

&lt;p&gt;Static Rendering (Default):&lt;br&gt;
Routes are pre-rendered at build time or in the background, then cached and stored. This is great for content that doesn't change per user, like static blog posts or product pages.&lt;/p&gt;

&lt;p&gt;Dynamic Rendering:&lt;br&gt;
Routes are generated for each user when requested. This is useful for content that is personalized or relies on information like cookies or URL parameters, which can only be known at the time of the request.&lt;/p&gt;

&lt;p&gt;As a developer you don't have to choose static or dynamic rendering.&lt;/p&gt;
&lt;h2&gt;
  
  
  Client components
&lt;/h2&gt;

&lt;p&gt;Client Components allow you to write interactive UI that is prerenderd on the server and use client JavaScript to run in the browser.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Benefits&lt;/em&gt; of doing the rendering on the client are :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can use states, use state, effects and event listners on client components and they can provide immidiate feedback to the user and update the UI on client side.&lt;/li&gt;
&lt;li&gt;Browser APIs like geolocation and localStorage can be accesed.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Using Client Components in Next.js
&lt;/h2&gt;

&lt;p&gt;To use a Client Components, you can use the React &lt;code&gt;"use client"&lt;/code&gt; directive at the top of a file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use client'

import { useState } from 'react'

export default function Counter() {
  const [count, setCount] = useState(0)

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;You clicked {count} times&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setCount(count + 1)}&amp;gt;Click me&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is all you need to convert server components to client components.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; - If you use state, effects, browser APIs without specifying the client component by &lt;code&gt;"use client"&lt;/code&gt;, Next.js will thorow an error.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Full page load
&lt;/h2&gt;

&lt;p&gt;To optimize the initial page load, Next.js will use React's APIs to render a static HTML preview on the server for both Client and Server Components. This means, when the user first visits your application, they will see the content of the page immediately, without having to wait for the client to download, parse, and execute the Client Component JavaScript bundle.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Server and Client Components enhance website performance, conserve data, and are especially advantageous for low-powered devices. You have the flexibility to choose when to employ client components as needed!&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Introduction to Next.js - Part-1</title>
      <dc:creator>Pratham Dupare</dc:creator>
      <pubDate>Tue, 02 Apr 2024 04:45:28 +0000</pubDate>
      <link>https://forem.com/prathamdupare/introduction-to-nextjs-part-1-1olm</link>
      <guid>https://forem.com/prathamdupare/introduction-to-nextjs-part-1-1olm</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;h2&gt;
  
  
  What is Next.js?
&lt;/h2&gt;

&lt;p&gt;Used by some of the world's largest companies, Next.js enables you to create high-quality web applications with the power of React components.&lt;/p&gt;

&lt;p&gt;Next.js serves as a React framework designed for developing full-stack web applications. By leveraging React Components for creating user interfaces, Next.js extends functionality and streamlines optimizations.&lt;/p&gt;

&lt;p&gt;Beneath the surface, Next.js handles the abstraction and automatic configuration of essential React tooling, such as bundling and compiling. This empowers developers, whether working individually or within a team, to concentrate on application development rather than intricate configuration details.&lt;/p&gt;

&lt;p&gt;With Next.js, building interactive, dynamic, and high-performance React applications becomes a more efficient and focused process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites:
&lt;/h3&gt;

&lt;p&gt;This is meant to be easy for beginners, but I want to set a starting point. This helps keep the focus on Next.js features.&lt;br&gt;
It's recommended to know a bit about HTML, CSS, and React to make the most of this series.&lt;/p&gt;
&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;You can start a new Next.js app using &lt;code&gt;create-next-app&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Simply run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-next-app@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command initiates a setup process with prompts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;What is your project named? my-app
Would you like to use TypeScript? No / Yes
Would you like to use ESLint? No / Yes
Would you like to use Tailwind CSS? No / Yes
Would you like to use &lt;span class="sb"&gt;`&lt;/span&gt;src/&lt;span class="sb"&gt;`&lt;/span&gt; directory? No / Yes
Would you like to use App Router? &lt;span class="o"&gt;(&lt;/span&gt;recommended&lt;span class="o"&gt;)&lt;/span&gt; No / Yes
Would you like to customize the default import &lt;span class="nb"&gt;alias&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;@/&lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;? No / Yes
What import &lt;span class="nb"&gt;alias &lt;/span&gt;would you like configured? @/&lt;span class="k"&gt;*&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;You can optionally use a src directory in the root of your project to separate your application's code from configuration files.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: The latest versions of Next.js use the 'app' router, we will be using that in this series.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Running the Dev Server
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Run &lt;code&gt;npm run dev&lt;/code&gt; to start the development server.&lt;/li&gt;
&lt;li&gt;Visit &lt;code&gt;http://localhost:3000&lt;/code&gt; to view your application.&lt;/li&gt;
&lt;li&gt;Edit &lt;code&gt;app/page.jsx&lt;/code&gt; file and save it to see the updated result in your browser.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Open your project in your preffered text editor or IDE.&lt;br&gt;
I use Neovim.&lt;/p&gt;
&lt;h2&gt;
  
  
  Routes
&lt;/h2&gt;

&lt;p&gt;Next.js uses a file based routing, where each folder in app folder represents a route.&lt;br&gt;
A special &lt;code&gt;page.js&lt;/code&gt; file is used to make route segments publicly accessible.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
Open the file in &lt;code&gt;app/page.js&lt;/code&gt; and remove everything and return only a &lt;code&gt;&amp;lt;div&amp;gt;This is home route&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Your page.js should lool like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;This&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;home&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if you visit &lt;code&gt;https://localhost:3000/&lt;/code&gt;, You should be able to see the text 'This is home route'&lt;/p&gt;

&lt;p&gt;If you make any folders inside app directory, for example: add folders &lt;code&gt;app/about&lt;/code&gt; or &lt;code&gt;app/contact&lt;/code&gt; and add the respective &lt;code&gt;page.js&lt;/code&gt; files inside.&lt;/p&gt;

&lt;p&gt;Populate it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app/about/page.js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;About&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;This&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;about&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now visit &lt;code&gt;https://localhost:3000/about&lt;/code&gt; and you'll see text &lt;code&gt;This is about page.&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Layout page
&lt;/h2&gt;

&lt;p&gt;A layout is UI that is shared between multiple routes. On navigation, layouts preserve state, remain interactive, and do not re-render. Layouts can also be nested.&lt;/p&gt;

&lt;p&gt;You can define a layout by default exporting a React component from a layout.js file. The component should accept a children prop that will be populated with a child layout (if it exists) or a page during rendering.&lt;/p&gt;

&lt;p&gt;Let's understand this with and example.&lt;/p&gt;

&lt;h4&gt;
  
  
  Root Layout
&lt;/h4&gt;

&lt;p&gt;The root layout is defined at the top level of the &lt;code&gt;app&lt;/code&gt; directory and applies to all routes. This layout is required and must contain &lt;code&gt;html&lt;/code&gt; and &lt;code&gt;body&lt;/code&gt; tags, allowing you to modify the initial HTML returned from the server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//app/layout.js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;RootLayout&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;html&lt;/span&gt; &lt;span class="nx"&gt;lang&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;en&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* Layout UI */&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;main&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/main&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/body&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/html&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to display a Navbar on every page of your app, place it in the layout page.&lt;/p&gt;

&lt;p&gt;Create a simple Navbar component in &lt;code&gt;app/components/Navbar.jsx&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//app/components/Navbar.jsx&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Navbar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Navbar&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Navbar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Put Navbar component in &lt;code&gt;app/layout.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//app/layout.jsx&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Inter&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next/font/google&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./globals.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Navbar&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@/components/Navbar&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;inter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Inter&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;subsets&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;latin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;metadata&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Create Next App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Generated by create next app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;RootLayout&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;html&lt;/span&gt; &lt;span class="nx"&gt;lang&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;en&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;inter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Navbar&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/body&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/html&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Navbar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can see Navbar in every page you visit, for example on &lt;code&gt;https//localhost://3000/about&lt;/code&gt;, you'll see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Navbar
This is about page.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note: You can import anything with &lt;code&gt;@/name_of_component&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;app/layout.js&lt;/code&gt; also contains metadata for your site.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;metadata&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//This is title of your site.&lt;/span&gt;
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Create Next App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Generated by create next app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this blog, we learned about what Next.js is and how routes and layouts work in Next.js.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>Minimal notetaking with Neovim and Obsidian.</title>
      <dc:creator>Pratham Dupare</dc:creator>
      <pubDate>Mon, 01 Apr 2024 06:50:44 +0000</pubDate>
      <link>https://forem.com/prathamdupare/minimal-notetaking-with-neovim-and-obsidian-49mg</link>
      <guid>https://forem.com/prathamdupare/minimal-notetaking-with-neovim-and-obsidian-49mg</guid>
      <description>&lt;h2&gt;
  
  
  WHY?
&lt;/h2&gt;

&lt;p&gt;Several years ago, I experimented with Obsidian for a while, finding it useful initially. However, as an advocate for free and open-source software, I discovered that Obsidian wasn't open-source, prompting me to abandon it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Present Situation
&lt;/h3&gt;

&lt;p&gt;By 2024, I found Neovim to be immensely satisfying, although not for note-taking purposes. My needs were simple - I required a platform to jot down daily tasks, links, or to-dos, without any frills. While I attempted to use Neovim for this, the challenge arose when I wasn't always near my laptop. Hence, I sought a solution to synchronize my notes with my phone. My initial thought was to sync them using Syncthing (which I'll discuss further). However, I still needed to access the notes through a text editor on my phone, which wasn't ideal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;One day, I stumbled upon a YouTube video featuring TJ DeVries using Obsidian for note-taking. I was intrigued - how could a core Neovim maintainer use Obsidian? Upon researching, I discovered that Obsidian offered a Vim mode, which delighted me. However, this didn't fully address my issues:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Even with Obsidian's Vim mode, I often forgot to open the app.&lt;/li&gt;
&lt;li&gt;Despite the Vim mode, I still had to resort to using the mouse to navigate between notes. While Obsidian provided shortcuts, it felt cumbersome to learn them solely for note-taking purposes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Then it struck me - I could edit the notes directly within the folder where the Obsidian vault was located, simplifying the process significantly!&lt;/p&gt;

&lt;h2&gt;
  
  
  The Setup
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Laptop
&lt;/h3&gt;

&lt;p&gt;I installed Obsidian solely to create the vault/folder in my home directory. I would then use Vim to access it and make any necessary changes, while Syncthing handled the synchronization in the background.&lt;/p&gt;

&lt;h3&gt;
  
  
  Syncthing
&lt;/h3&gt;

&lt;h4&gt;
  
  
  What is Syncthing?
&lt;/h4&gt;

&lt;p&gt;Syncthing is a continuous file synchronization program that securely synchronizes files between two or more computers in real-time. Your data remains private, allowing you to choose where it's stored and whether it's shared with third parties.&lt;/p&gt;

&lt;p&gt;I installed Syncthing on both my laptop and Android device, linking it to my Obsidian folder. You can find tutorials on how to do this by watching videos from creators like &lt;a href="https://www.youtube.com/watch?v=Uag8PJaO0N4" rel="noopener noreferrer"&gt;Mental Outlaw&lt;/a&gt; or &lt;a href="https://www.youtube.com/watch?v=i6LuV7Pl2YU" rel="noopener noreferrer"&gt;DistroTube&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This setup ensured that my folder was synced in real-time whenever both devices were online!&lt;/p&gt;

&lt;h3&gt;
  
  
  Android
&lt;/h3&gt;

&lt;p&gt;On my Android device, I installed Obsidian and Syncthing, selecting the previously created/synced folder from Syncthing.&lt;/p&gt;

&lt;p&gt;Now, I could view and edit my notes wherever I wanted, with changes almost instantly reflected on my desktop too!&lt;/p&gt;

&lt;p&gt;Moreover, this setup essentially provided two backups of my notes on separate devices!&lt;/p&gt;

&lt;p&gt;I also considered creating a Git repository and writing a script to run a cron job for automatic backups on GitHub. After all, shouldn't Microsoft monopolize everything, right?!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;There's no conclusion - I'll continue using this setup indefinitely, or until I decide to explore something entirely different. Who knows what the future holds!&lt;/p&gt;

</description>
      <category>neovim</category>
      <category>notetaking</category>
      <category>obsidian</category>
      <category>developer</category>
    </item>
  </channel>
</rss>
