<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Milka Mutinda</title>
    <description>The latest articles on DEV Community by Milka Mutinda (@milka_mutinda).</description>
    <link>https://dev.to/milka_mutinda</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%2F2080530%2F44eed9c4-8a2b-4144-8970-2ca555fcd1bd.png</url>
      <title>DEV Community: Milka Mutinda</title>
      <link>https://dev.to/milka_mutinda</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/milka_mutinda"/>
    <language>en</language>
    <item>
      <title>Technical Overview of Next.js.</title>
      <dc:creator>Milka Mutinda</dc:creator>
      <pubDate>Tue, 17 Sep 2024 15:44:33 +0000</pubDate>
      <link>https://dev.to/swahilipotdevs/technical-overview-of-lessons-learnt-12ol</link>
      <guid>https://dev.to/swahilipotdevs/technical-overview-of-lessons-learnt-12ol</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Lessons learned in nextjs:&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
**&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating the new project.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Key in the following command in the terminal .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g pnpm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then to create an app, enter the following command in the terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g pnpm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enter the following command still in the terminal to create the app in the desired folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-next-app@latest nextjs-dashboard 
      example "https://github.com/vercel/next- 
      learn/tree/main/dashboard/starter-example" - 
      -use-pnpm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Running development server.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To install the project packages, run the below command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pnpm i
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Followed by the following command to start the development server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pnpm dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Adding styles.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To add global styles in your application, navigate to layout.tsx file under app folder and key import the global.css file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import '@/app/ui/global.css';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Creating a Home Page.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To create an attractive home page, elements like fonts and images are crucial. We will start by adding fonts in the project. By the use of next/font module, Next.js automatically optimizes in the application and downloads the font files at build time to host them with the other static assets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; _import { Inter, Lusitana } from 'next/font/google';_

_export const inter = Inter({ subsets: ['latin'] });_

export const lusitana = Lusitana({
    weight: ['400', '700'],
    subsets: ['latin'],
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To add the desktop image, we use the  component. In the /app/page.tsx file, import the component from next/image and then add the image under the comment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import AcmeLogo from '@/app/ui/acme-logo';
import { ArrowRightIcon } from '@heroicons/react/24/outline';
import Link from 'next/link';
import { lusitana} from '@/app/ui/fonts';
_import Image from 'next/image';_
//..........    
        _&amp;lt;Image
        src="/hero-mobile.png"
        width={560}
        height={620}
        className="block md:hidden"
        alt="Screenshot of the dashboard project showing mobile version"
      /&amp;gt;_

        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/main&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Nesting Routes.&lt;/strong&gt;&lt;br&gt;
Create folders that are used to nest routes. For example, create folders under the app folder, like a dashboard and invoices that map to a URL to showcase your app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Navigating through Pages.&lt;/strong&gt;&lt;br&gt;
To navigate through a page, you need to use  component to link between pages in the application. To use this  component, go to /app/ui/dashboard/nav-links.tsx, and import the Link component from next/link. Replace &lt;a&gt; with .&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/...
import {
  UserGroupIcon,
  HomeIcon,
  DocumentDuplicateIcon,
} from '@heroicons/react/24/outline';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import clsx from 'clsx';
/...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Setting Up Database.&lt;/strong&gt;**&lt;/p&gt;

&lt;p&gt;Here, you will start by pushing your repository to Github for ease in setting up the database and deploying. Set up a vercel account and import your already created folder containing your app then deploy.&lt;/p&gt;

&lt;p&gt;Afterwards, connect store, create new, postgres then continue. Once you are done with that, go to .env.local tab, click show secret and copy snippet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;POSTGRES_URL="postgres://default:W95RsBPGcbeU@ep-cold-bar-a457mttq-pooler.us-east-1.aws.neon.tech:5432/verceldb?sslmode=require"
POSTGRES_PRISMA_URL="postgres://default:W95RsBPGcbeU@ep-cold-bar-a457mttq-pooler.us-east-1.aws.neon.tech:5432/verceldb?sslmode=require&amp;amp;pgbouncer=true&amp;amp;connect_timeout=15"
POSTGRES_URL_NO_SSL="postgres://default:W95RsBPGcbeU@ep-cold-bar-a457mttq-pooler.us-east-1.aws.neon.tech:5432/verceldb"
POSTGRES_URL_NON_POOLING="postgres://default:W95RsBPGcbeU@ep-cold-bar-a457mttq.us-east-1.aws.neon.tech:5432/verceldb?sslmode=require"
POSTGRES_USER="default"
POSTGRES_HOST="ep-cold-bar-a457mttq-pooler.us-east-1.aws.neon.tech"
POSTGRES_PASSWORD="W95RsBPGcbeU"
POSTGRES_DATABASE="verceldb"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Seeding The Database.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The database is seeded inside of /app, in a folder called seed. Make sure to uncomment the file. The folder contains a Next.js Route Handler, called route.ts, that will be used to seed your database.&lt;br&gt;
Ensure your local development server is running with pnpm run dev and navigate to your localhost. Afterwards, a confirmation message will appear to show a success.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fetching Data For The Dashboard Overview Page.&lt;/strong&gt;&lt;br&gt;
There are several ways of fetching data from the database, like using server components where in next.js we use react server components.&lt;br&gt;
There is also using SQL where you'll write dataabase queries using vercel postgres created previously and SQL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Card } from '@/app/ui/dashboard/cards';
import RevenueChart from '@/app/ui/dashboard/revenue-chart';
import LatestInvoices from '@/app/ui/dashboard/latest-invoices';
import { lusitana } from '@/app/ui/fonts';

export default async function Page() {
  return (
    &amp;lt;main&amp;gt;
      &amp;lt;h1 className={`${lusitana.className} mb-4 text-xl md:text-2xl`}&amp;gt;
        Dashboard
      &amp;lt;/h1&amp;gt;
      &amp;lt;div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-4"&amp;gt;
        {/* &amp;lt;Card title="Collected" value={totalPaidInvoices} type="collected" /&amp;gt; */}
        {/* &amp;lt;Card title="Pending" value={totalPendingInvoices} type="pending" /&amp;gt; */}
        {/* &amp;lt;Card title="Total Invoices" value={numberOfInvoices} type="invoices" /&amp;gt; */}
        {/* &amp;lt;Card
          title="Total Customers"
          value={numberOfCustomers}
          type="customers"
        /&amp;gt; */}
      &amp;lt;/div&amp;gt;
      &amp;lt;div className="mt-6 grid grid-cols-1 gap-6 md:grid-cols-4 lg:grid-cols-8"&amp;gt;
        {/* &amp;lt;RevenueChart revenue={revenue}  /&amp;gt; */}
        {/* &amp;lt;LatestInvoices latestInvoices={latestInvoices} /&amp;gt; */}
      &amp;lt;/div&amp;gt;
    &amp;lt;/main&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Handling Errors.&lt;/strong&gt;&lt;br&gt;
To handle errors in your code, you have to add JavaScript's try/catch statements inside your server actions /app/lib/actions.ts, to allow handling of errors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Accessibility.&lt;/strong&gt;&lt;br&gt;
Accessibility is crucial for making web applications usable for everyone. Next.js, being a React-based framework, offers a range of techniques and tools to ensure that your application is accessible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding Metadata.&lt;/strong&gt;&lt;br&gt;
Adding metadata to your Next.js application is essential for several reasons, primarily focused on improving SEO, accessibility, and sharing your web content on social media. &lt;/p&gt;

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