<?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 Sajjad Hussain on Medium]]></title>
        <description><![CDATA[Stories by Sajjad Hussain on Medium]]></description>
        <link>https://medium.com/@sajjadast786?source=rss-980588a423fe------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*79ixX0sROpRJJlaT2GrsbQ.jpeg</url>
            <title>Stories by Sajjad Hussain on Medium</title>
            <link>https://medium.com/@sajjadast786?source=rss-980588a423fe------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 16:53:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sajjadast786/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[Next.js 16 + TailwindCSS]]></title>
            <link>https://medium.com/@sajjadast786/next-js-16-tailwindcss-9e1b5d59366a?source=rss-980588a423fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e1b5d59366a</guid>
            <dc:creator><![CDATA[Sajjad Hussain]]></dc:creator>
            <pubDate>Fri, 12 Dec 2025 13:32:24 GMT</pubDate>
            <atom:updated>2025-12-12T13:44:59.917Z</atom:updated>
            <content:encoded><![CDATA[<p>Must install extions on VsCode : ES7+ React/Redux/React-Native snippets by <a href="https://marketplace.visualstudio.com/publishers/dsznajder">dsznajder</a></p><h3>Step 1: Create Next.js Project</h3><p>npx create-next-app@latest</p><ul><li>Select project name: first-project</li><li>Choose options: App Router, JavaScript, TailwindCSS</li></ul><p>Navigate to your project:</p><p>cd first-project</p><p>npm run dev</p><p>Open in browser: <a href="http://localhost:3000/">http://localhost:3000</a></p><h3>Step 2: Create Home Page</h3><p>app/page.tsx:</p><pre>export default function Home() {<br>return (<br> &lt;div className=&quot;p-6&quot;&gt;<br> &lt;h1 className=&quot;text-2xl font-bold&quot;&gt;Home Page&lt;/h1&gt;<br> &lt;p&gt;This is the landing page.&lt;/p&gt;<br> &lt;/div&gt;<br> );<br>}</pre><h3>Step 3: Create WelcomeStore Component</h3><p>components/home/WelcomeStore.tsx:</p><pre>export default function WelcomeStore() {<br>return (<br> &lt;div className=&quot;p-6 border rounded-lg shadow-md&quot;&gt;<br> &lt;h2 className=&quot;text-xl font-semibold&quot;&gt;Welcome to Our Store&lt;/h2&gt;<br> &lt;p&gt;Explore products in Category 1 and Category 2 pages.&lt;/p&gt;<br> &lt;/div&gt;<br> );<br>}</pre><h3>Step 4: Update Home Page</h3><p>app/page.tsx:</p><pre>import WelcomeStore from &#39;./components/home/WelcomeStore&#39;;<br>export default function Home() {<br>return (<br> &lt;div className=&quot;p-6&quot;&gt;<br> &lt;WelcomeStore /&gt;<br> &lt;/div&gt;<br> );<br>}</pre><h3>Step 5: Category 1 — Server Action + Server Component</h3><h3>5.1 Create Generic Category1 Page</h3><p>app/category1/page.tsx:</p><pre>export default function Category1Page() {</pre><pre>return (</pre><pre> &lt;div className=&quot;p-6&quot;&gt;</pre><pre> &lt;h1 className=&quot;text-2xl font-bold&quot;&gt;Category 1 Products&lt;/h1&gt;</pre><pre> &lt;p&gt;Products will appear here after server action and component are created.&lt;/p&gt;</pre><pre> &lt;/div&gt;</pre><pre> );</pre><pre>}</pre><h3>5.2 Create Server Action</h3><p>lib/actions/category/fetchCategory1Products.ts:</p><pre>export async function fetchCategory1Products() {<br>try {<br>const res = await fetch(&#39;https://fakestoreapi.com/products&#39;, { cache: &#39;no-store&#39; });<br>if (!res.ok) throw new Error(&#39;Failed to fetch products&#39;);<br>return res.json();<br> } catch (error) {<br>console.error(&#39;Error fetching Category1 products:&#39;, error);<br>return [];<br> }<br>}</pre><h3>5.3 Create ProductCard1 Component (Server Component)</h3><p>components/category/ProductCard1.tsx:</p><pre>export type FakeProduct = {<br>id: number;<br>title: string;<br>price: number;<br>description: string;<br>category: string;<br>image: string;<br>rating: {<br>rate: number;<br>count: number;<br> };<br>};<br>export default function ProductCard1({ products }: { products: FakeProduct[] }) {<br>return (<br> &lt;div className=&quot;grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-6&quot;&gt;<br> {products.map((product) =&gt; (<br> &lt;div<br>key={product.id}<br>className=&quot;border rounded-lg p-4 shadow-sm hover:shadow-md transition mb-4&quot;<br> &gt;<br> &lt;img<br>src={product.image}<br>alt={product.title}<br>className=&quot;w-24 h-24 object-contain mx-auto mb-2&quot;<br> /&gt;<br> &lt;h4 className=&quot;text-lg font-semibold&quot;&gt;{product.title}&lt;/h4&gt;<br> &lt;p className=&quot;text-gray-700 font-medium&quot;&gt;${product.price}&lt;/p&gt;<br> &lt;p className=&quot;text-sm text-gray-500&quot;&gt;{product.category}&lt;/p&gt;<br> &lt;div className=&quot;text-yellow-500 text-sm mt-1&quot;&gt;<br> ⭐ {product.rating.rate} ({product.rating.count})<br> &lt;/div&gt;<br> &lt;/div&gt;<br> ))}<br> &lt;/div&gt;<br> );<br>}</pre><h3>5.4 Update Category1 Page to Fetch Products</h3><p>app/category1/page.tsx:</p><pre>import { fetchCategory1Products } from &#39;../../lib/actions/category/fetchCategory1Products&#39;;<br>import ProductCard1 from &#39;../../components/category/ProductCard1&#39;;<br>export default async function Category1Page() {<br>const products = await fetchCategory1Products();<br>return (<br> &lt;div className=&quot;p-6&quot;&gt;<br> &lt;h1 className=&quot;text-2xl font-bold&quot;&gt;Category 1 Products&lt;/h1&gt;<br> &lt;ProductCard1 products={products} /&gt;<br> &lt;/div&gt;<br> );<br>}</pre><h3>Step 6: Category 2 — API Route + Client Component</h3><h3>6.1 Create Generic Category2 Page</h3><p>app/category2/page.tsx:</p><pre>&quot;use client&quot;<br>export default function Category2Page() {<br>return (<br> &lt;div className=&quot;p-6&quot;&gt;<br> &lt;h1 className=&quot;text-2xl font-bold&quot;&gt;Category 2 Products&lt;/h1&gt;<br> &lt;p&gt;Products will appear here after API route and client component are created.&lt;/p&gt;<br> &lt;/div&gt;<br> );<br>}</pre><h3>6.2 Create API Route</h3><p>app/api/category/route.ts:</p><pre>export async function GET() {<br>try {<br>const res = await fetch(&#39;https://fakestoreapi.com/products&#39;);<br>const products = await res.json();<br>return new Response(JSON.stringify(products), { status: 200 });<br> } catch (error) {<br>return new Response(JSON.stringify({ error: &#39;Failed to fetch products&#39; }), { status: 500 });<br> }<br>}</pre><h3>6.3 Create ProductCard2 Component (Client Component)</h3><p>components/category/ProductCard2.tsx:</p><pre>&#39;use client&#39;;<br>export default function ProductCard2({ products }) {<br>return (<br> &lt;div className=&quot;grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-6&quot;&gt;<br> {products.map((product) =&gt; (<br> &lt;div<br>key={product.id}<br>className=&quot;border rounded-lg p-4 shadow-sm hover:shadow-md transition mb-4&quot;<br> &gt;<br> &lt;img<br>src={product.image}<br>alt={product.title}<br>className=&quot;w-24 h-24 object-contain mx-auto mb-2&quot;<br> /&gt;<br> &lt;h4 className=&quot;text-lg font-semibold&quot;&gt;{product.title}&lt;/h4&gt;<br> &lt;p className=&quot;text-gray-700 font-medium&quot;&gt;${product.price}&lt;/p&gt;<br> &lt;p className=&quot;text-sm text-gray-500&quot;&gt;{product.category}&lt;/p&gt;<br> &lt;div className=&quot;text-yellow-500 text-sm mt-1&quot;&gt;<br> ⭐ {product.rating.rate} ({product.rating.count})<br> &lt;/div&gt;<br> &lt;/div&gt;<br> ))}<br> &lt;/div&gt;<br> );<br>}</pre><h3>6.4 Update Category2 Page to Fetch from API</h3><p>app/category2/page.tsx:</p><pre>&#39;use client&#39;;<br>import { useState, useEffect } from &#39;react&#39;;<br>import ProductCard2 from &#39;../../components/category/ProductCard2&#39;;<br>export default function Category2Page() {<br>const [products, setProducts] = useState([]);<br>useEffect(() =&gt; {<br>async function fetchProducts() {<br>const res = await fetch(&#39;/api/category&#39;);<br>const data = await res.json();<br>setProducts(data);<br> }<br>fetchProducts();<br> }, []);<br>return (<br> &lt;div className=&quot;p-6&quot;&gt;<br> &lt;h1 className=&quot;text-2xl font-bold&quot;&gt;Category 2 Products&lt;/h1&gt;<br> &lt;ProductCard2 products={products} /&gt;<br> &lt;/div&gt;<br> );<br>}</pre><h3>Step 7: Run and Test</h3><p>npm run dev</p><ul><li>Home: <a href="http://localhost:3000/">http://localhost:3000</a> → Displays WelcomeStore component</li><li>Category1: <a href="http://localhost:3000/category1">http://localhost:3000/category1</a> → Server Action + ProductCard1</li><li>Category2: <a href="http://localhost:3000/category2">http://localhost:3000/category2</a> → API Route + ProductCard2</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e1b5d59366a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Next.js 15 + PostgreSQL (Neon) + Prisma + Zod + useActionState + useFormStatus — Fullstack App]]></title>
            <link>https://medium.com/@sajjadast786/next-js-15-postgresql-neon-prisma-zod-useactionstate-useformstatus-fullstack-app-a85ed7de9cea?source=rss-980588a423fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/a85ed7de9cea</guid>
            <category><![CDATA[useactionstate]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[zod]]></category>
            <category><![CDATA[prisma]]></category>
            <category><![CDATA[nextjs-15]]></category>
            <dc:creator><![CDATA[Sajjad Hussain]]></dc:creator>
            <pubDate>Sun, 09 Mar 2025 16:22:04 GMT</pubDate>
            <atom:updated>2025-03-09T16:22:04.314Z</atom:updated>
            <content:encoded><![CDATA[<h3>Next.js 15 + PostgreSQL (Neon) + Prisma + Zod + useActionState + useFormStatus — Fullstack App</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DpSgZogr1sUuxYKi4LJDaQ.jpeg" /><figcaption>Next.js 15 + PostgreSQL (Neon) + Prisma + Zod + useActionState + useFormStatus — Fullstack App</figcaption></figure><p>This is a well-structured, production-ready Next.js 15 app that includes:</p><ul><li>✅ Expenses &amp; Users (Create &amp; Display)</li><li>✅ PostgreSQL (Neon) with Prisma</li><li>✅ Form Validation using Zod</li><li>✅ React Server Actions (useActionState &amp; useFormStatus)</li></ul><h3>Step 1: Create a New Next.js 15 App with Tailwind and TypeScript</h3><pre>npm install next@latest</pre><p>Follow the installation steps.</p><h3>Step 2: Install All Necessary Dependencies</h3><pre>npm install -D prisma @prisma/client<br>npm install @prisma/adapter-neon @neondatabase/serverless ws bufferutil<br>npm install zod<br>npm install --save-dev @types/ws</pre><h3>Step 3: Initialize Prisma &amp; Set Up PostgreSQL (Neon)</h3><h3>Initialize Prisma</h3><pre>npx prisma init</pre><p>This creates:</p><ul><li>A prisma/ folder</li><li>A .env file</li></ul><h3>Get Neon PostgreSQL Connection String</h3><ol><li>Go to <a href="https://neon.tech/">Neon</a></li><li>Create a new PostgreSQL database</li><li>Copy your database connection string</li><li>Paste it into .env:</li></ol><p><strong>.env</strong></p><pre>DATABASE_URL=&quot;your-neon-connection-string-here&quot;</pre><h3>Step 4: Configure Prisma for Neon</h3><p><strong>prisma/schema.prisma</strong></p><pre>generator client {<br>  provider        = &quot;prisma-client-js&quot;<br>  previewFeatures = [&quot;driverAdapters&quot;]<br>}</pre><pre>datasource db {<br>  provider = &quot;postgresql&quot;<br>  url      = env(&quot;DATABASE_URL&quot;)<br>}</pre><h3>Step 5: Set Up Prisma Client with Neon Adapter</h3><p><strong>lib/prisma.ts</strong></p><pre>import { PrismaClient } from &#39;@prisma/client&#39;<br>import { PrismaNeon } from &#39;@prisma/adapter-neon&#39;<br>import { Pool, neonConfig } from &#39;@neondatabase/serverless&#39;<br>import ws from &#39;ws&#39;</pre><pre>const prismaClientSingleton = () =&gt; {<br>  neonConfig.webSocketConstructor = ws<br>  const connectionString = process.env.DATABASE_URL</pre><pre>  const pool = new Pool({ connectionString })<br>  const adapter = new PrismaNeon(pool)<br>  const prisma = new PrismaClient({ adapter })</pre><pre>  return prisma<br>}</pre><pre>declare const globalThis: {<br>  prismaGlobal: ReturnType&lt;typeof prismaClientSingleton&gt;<br>} &amp; typeof global</pre><pre>const prisma = globalThis.prismaGlobal ?? prismaClientSingleton()</pre><pre>export default prisma</pre><h3>Step 6: Define Database Models</h3><p><strong>prisma/schema.prisma</strong></p><pre>model Expense {<br>  id        String   @id @default(uuid())<br>  createdAt DateTime @default(now())<br>  updatedAt DateTime @updatedAt<br>  title     String   @db.VarChar(255)<br>  amount    Int<br>}</pre><pre> <br>}</pre><h3>Step 7: Run Prisma Migrations</h3><pre>npx prisma migrate dev --name init</pre><p>This will create the necessary migration files and apply them to your local database.</p><h3>Step 7b: Use Prisma Studio</h3><p>Prisma Studio is a visual tool to manage your database records.</p><h3>Start Prisma Studio</h3><pre>npx prisma studio</pre><p>This command opens Prisma Studio in your browser, allowing you to view and manage your database tables interactively.</p><h3>Features of Prisma Studio</h3><ul><li>✅ View and edit your database records</li><li>✅ Add new records easily</li><li>✅ Delete unwanted data</li><li>✅ Test database queries visually</li></ul><p>Once started, visit http://localhost:5555 in your browser to interact with your database.</p><h3>Step 8: Set Up Zod for Validation</h3><p><strong>lib/zodSchemas.js</strong></p><pre>import { z } from &#39;zod&#39;;</pre><pre>// Expense Validation Schema<br>export const expenseSchema = z.object({<br>  title: z.string().min(1, &#39;Title is required&#39;),<br>  amount: z.number().min(0, &#39;Amount must be greater than 0&#39;),<br> });</pre><h3>Step 12: Create Expense Utility Functions</h3><p><strong>lib/expenses/expense.ts</strong></p><pre>import prisma from &#39;@/lib/prisma&#39;</pre><pre>      export async function getExpenses() {<br>        return await prisma.expense.findMany()<br>      }<br>      <br>      export async function createExpense(data: { amount: number; title: string }) {<br>        return await prisma.expense.create({<br>          data,<br>        })<br>      }</pre><h3>Step 9: Create Server Actions</h3><p><strong>lib/expenses/actions.ts</strong></p><pre>&#39;use server&#39;</pre><pre>      import { revalidatePath } from &#39;next/cache&#39;<br>      import { expenseSchema } from &#39;@/lib/zodSchemas&#39;<br>      import { createExpense } from &#39;@/lib/expenses/expense&#39;<br>      interface State {<br>        success: boolean<br>        status: number<br>        message: string<br>      }<br>      <br>      export async function createExpenseAction(state: State, formData: FormData) {<br>        const result = expenseSchema.safeParse({<br>          title: formData.get(&#39;title&#39;),<br>          amount: parseFloat(formData.get(&#39;amount&#39;) as string),<br>        })<br>      <br>        if (!result.success) {<br>          return {<br>            success: false,<br>            status: 500,<br>            message: result.error.errors[0].message,<br>          }<br>        }<br>      <br>        await createExpense({<br>          title: result.data.title,<br>          amount: result.data.amount,<br>        })<br>      <br>        revalidatePath(&#39;/&#39;)<br>        return { success: true, status: 201, message: &#39;Expense created successfully&#39; }<br>      }</pre><h3>Step 17: Main Page</h3><p><strong>app/page.tsx</strong></p><pre>import { getExpenses } from &#39;@/lib/expenses/expense&#39;<br>      import CreateExpenseForm from &#39;@/components/CreateExpenseForm&#39;<br>      <br>      export default async function Home() {<br>        const expenses = await getExpenses()<br>      <br>        return (<br>          &lt;section className=&#39;py-16 bg-gradient-to-br from-gray-50 to-gray-100 min-h-screen flex items-center&#39;&gt;<br>            &lt;div className=&#39;container mx-auto max-w-4xl p-8 bg-white shadow-xl rounded-2xl border border-gray-200&#39;&gt;<br>              {/* Page Header */}<br>              &lt;div className=&#39;text-center&#39;&gt;<br>                &lt;h1 className=&#39;text-4xl font-extrabold text-gray-900&#39;&gt;<br>                  Expense Tracker<br>                &lt;/h1&gt;<br>                &lt;h2 className=&#39;text-gray-500 mt-2&#39;&gt;<br>                  Using Neon: Serverless Postgres<br>                &lt;/h2&gt;<br>              &lt;/div&gt;<br>      <br>              &lt;div className=&#39;mt-10 grid md:grid-cols-2 gap-8&#39;&gt;<br>                {/* Expense List with Table Layout */}<br>                &lt;div className=&#39;bg-white p-6 rounded-lg shadow-lg border border-gray-200&#39;&gt;<br>                  &lt;h3 className=&#39;text-xl font-semibold text-gray-800 border-b pb-3&#39;&gt;<br>                    Expense Items<br>                  &lt;/h3&gt;<br>                  &lt;div className=&#39;overflow-x-auto&#39;&gt;<br>                    &lt;table className=&#39;w-full mt-4 border-collapse&#39;&gt;<br>                      &lt;thead&gt;<br>                        &lt;tr className=&#39;bg-gray-700&#39;&gt;<br>                          &lt;th className=&#39;text-left p-3 text-white font-medium&#39;&gt;<br>                            Title<br>                          &lt;/th&gt;<br>                          &lt;th className=&#39;text-right p-3 text-white font-medium&#39;&gt;<br>                            Amount<br>                          &lt;/th&gt;<br>                        &lt;/tr&gt;<br>                      &lt;/thead&gt;<br>                      &lt;tbody&gt;<br>                        {expenses.length &gt; 0 ? (<br>                          expenses.map((expense, index) =&gt; (<br>                            &lt;tr<br>                              key={expense.id}<br>                              className={`border-b ${<br>                                index % 2 === 0 ? &#39;bg-gray-50&#39; : &#39;bg-white&#39;<br>                              } hover:bg-gray-100 transition`}<br>                            &gt;<br>                              &lt;td className=&#39;p-3 text-gray-800&#39;&gt;{expense.title}&lt;/td&gt;<br>                              &lt;td className=&#39;p-3 text-right font-semibold text-gray-600&#39;&gt;<br>                                ${expense.amount}<br>                              &lt;/td&gt;<br>                            &lt;/tr&gt;<br>                          ))<br>                        ) : (<br>                          &lt;tr&gt;<br>                            &lt;td colSpan={2} className=&#39;p-4 text-center text-gray-500&#39;&gt;<br>                              No expenses found.<br>                            &lt;/td&gt;<br>                          &lt;/tr&gt;<br>                        )}<br>                      &lt;/tbody&gt;<br>                    &lt;/table&gt;<br>                  &lt;/div&gt;<br>                &lt;/div&gt;<br>      <br>                {/* Expense Form */}<br>                &lt;CreateExpenseForm /&gt;<br>              &lt;/div&gt;<br>            &lt;/div&gt;<br>          &lt;/section&gt;<br>        )<br>      }</pre><h3>Step 18: CreateExpenseForm</h3><p><strong>components/CreateExpenseForm.tsx</strong></p><pre>&#39;use client&#39;<br>      <br>      import { useActionState } from &#39;react&#39;<br>      import { createExpenseAction } from &#39;@/lib/expenses/actions&#39;<br>      import { useEffect, useState } from &#39;react&#39;<br>      <br>      export default function CreateExpenseForm() {<br>        const [state, action, isPending] = useActionState(createExpenseAction, {<br>          success: false,<br>          status: 0,<br>          message: &#39;&#39;,<br>        })<br>        const [showMessage, setShowMessage] = useState(false)<br>      <br>        useEffect(() =&gt; {<br>          if (state?.message) {<br>            setShowMessage(true)<br>      <br>            const timer = setTimeout(() =&gt; {<br>              setShowMessage(false)<br>            }, 3000)<br>      <br>            return () =&gt; clearTimeout(timer)<br>          }<br>        }, [state])<br>      <br>        return (<br>          &lt;div className=&#39;bg-white p-6 rounded-lg shadow-md border border-gray-200&#39;&gt;<br>            &lt;h3 className=&#39;text-xl font-semibold text-gray-900&#39;&gt;Add New Expense&lt;/h3&gt;<br>            &lt;form className=&#39;mt-4 space-y-4&#39; action={action}&gt;<br>              {/* Grid Layout for Title &amp; Amount */}<br>              &lt;div className=&#39;grid grid-cols-2 gap-4 sm:grid-cols-1&#39;&gt;<br>                &lt;div&gt;<br>                  &lt;label className=&#39;block text-gray-700 font-medium mb-1&#39;&gt;<br>                    Title<br>                  &lt;/label&gt;<br>                  &lt;input<br>                    type=&#39;text&#39;<br>                    name=&#39;title&#39;<br>                    placeholder=&#39;Expense title&#39;<br>                    className=&#39;w-full border border-gray-300 p-3 rounded-lg shadow-sm focus:ring focus:ring-purple-200&#39;<br>                  /&gt;<br>                &lt;/div&gt;<br>                &lt;div&gt;<br>                  &lt;label className=&#39;block text-gray-700 font-medium mb-1&#39;&gt;<br>                    Amount<br>                  &lt;/label&gt;<br>                  &lt;input<br>                    type=&#39;number&#39;<br>                    name=&#39;amount&#39;<br>                    placeholder=&#39;Enter amount&#39;<br>                    className=&#39;w-full border border-gray-300 p-3 rounded-lg shadow-sm focus:ring focus:ring-purple-200&#39;<br>                  /&gt;<br>                &lt;/div&gt;<br>              &lt;/div&gt;<br>      <br>              {/* Display Message */}<br>              {showMessage &amp;&amp; (<br>                &lt;p<br>                  className={`text-sm font-medium p-2 rounded-md ${<br>                    state?.status === 201<br>                      ? &#39;text-green-600 bg-green-100&#39;<br>                      : &#39;text-red-600 bg-red-100&#39;<br>                  }`}&gt;<br>                  {state.message}<br>                &lt;/p&gt;<br>              )}<br>      <br>              {/* Submit Button */}<br>              &lt;button<br>                type=&#39;submit&#39;<br>                className=&#39;w-full bg-purple-600 text-white p-3 rounded-lg font-semibold transition hover:bg-purple-700 disabled:bg-purple-400&#39;<br>                disabled={isPending}<br>              &gt;<br>                {isPending ? &#39;Processing...&#39; : &#39;Submit&#39;}<br>              &lt;/button&gt;<br>            &lt;/form&gt;<br>          &lt;/div&gt;<br>        )<br>      }</pre><h3>Conclusion</h3><p>You now have a fully functional Next.js 15 app with PostgreSQL (Neon), Prisma, Zod, and React Server Actions. This setup is production-ready and can be extended further based on your requirements.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a85ed7de9cea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[test]]></title>
            <link>https://medium.com/@sajjadast786/test-63e9fa3673b7?source=rss-980588a423fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/63e9fa3673b7</guid>
            <dc:creator><![CDATA[Sajjad Hussain]]></dc:creator>
            <pubDate>Mon, 09 Sep 2024 19:34:38 GMT</pubDate>
            <atom:updated>2024-09-10T18:12:26.544Z</atom:updated>
            <content:encoded><![CDATA[<p>test</p><p><a href="https://www.celerant.com/contact/">https://www.celerant.com/contact/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63e9fa3673b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tips for Writing Clean Fast and Maintainable React Code | Sajjad Hussain]]></title>
            <link>https://medium.com/@sajjadast786/tips-for-writing-clean-fast-and-maintainable-react-code-sajjad-hussain-ad869adf10a3?source=rss-980588a423fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad869adf10a3</guid>
            <dc:creator><![CDATA[Sajjad Hussain]]></dc:creator>
            <pubDate>Mon, 06 Nov 2023 17:33:21 GMT</pubDate>
            <atom:updated>2023-11-06T17:34:00.397Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-8G_vKN4PhWn_u7Quc5FcQ.png" /></figure><p><a href="https://youtu.be/-pzH9J4hsaU">https://youtu.be/-pzH9J4hsaU</a></p><p>You’ll discover valuable tips for writing clean, efficient, and maintainable React code. Whether you’re a seasoned developer or just starting, these insights will elevate your React skills. Learn how to create an effective folder structure tailored to your project’s complexity, maintain an organized import order for improved code readability, explore higher-level component patterns to avoid prop-drilling, utilize a linter like ESLint and follow its guidelines for error-free code, embrace testing as a crucial part of development, consider using TypeScript or default props and prop types for error detection, implement lazy loading and code splitting for improved performance, organize reusable logic into custom hooks to reduce repetition, and handle errors effectively to ensure a mature and reliable application. Like, share, and subscribe to Dev Genius for more tech insights and apply these tips in your next React project for a smoother development experience. Happy coding! For Details watch below full Video<br><a href="https://youtu.be/-pzH9J4hsaU">https://youtu.be/-pzH9J4hsaU</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad869adf10a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Run ColdFusion Site with IIS | Sajjad Hussain]]></title>
            <link>https://medium.com/@sajjadast786/how-to-run-coldfusion-site-with-iis-sajjad-hussain-79eb5ccb2ffe?source=rss-980588a423fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/79eb5ccb2ffe</guid>
            <dc:creator><![CDATA[Sajjad Hussain]]></dc:creator>
            <pubDate>Thu, 04 May 2023 18:50:55 GMT</pubDate>
            <atom:updated>2023-05-04T18:53:07.695Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jB3ZqjbKF2qOc7Jrm14HIg.jpeg" /></figure><p>ColdFusion is a rapid application development platform that enables developers to create dynamic web pages and web applications. Integrating ColdFusion with IIS (Internet Information Services) allows users to deploy ColdFusion applications on the Microsoft Windows server. In this article, we will guide you through the steps to run a ColdFusion site with IIS.</p><p><strong>Step 1: Enable the required options in Windows Features</strong></p><p>The first step is to enable the required options in Windows Features. To do this, press the Windows key and search for “Turn Windows features on or off”. Click on it to open the dialog box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WdOIWbPxPP1AMNmW3TAdkA.jpeg" /></figure><p>In the Windows Features dialog box, expand the option for “Internet Information Services” and then expand “World Wide Web Services”. Now, enable the options for “Application Development Features”. Once you expand it, enable the following options: CGI, ISAPI Extensions, and ISAPI Filters. Click on “OK” to save the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*uLoEXxwld7iJW4e6DRTltw.jpeg" /></figure><p><strong>Step 2: Configure ColdFusion with IIS</strong></p><p>Next, you need to configure ColdFusion with IIS. To do this, go to the ColdFusion directory in your system. Typically, it would be located in the following path: C:\ColdFusion2021\cfusion\runtime\bin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*2XysoBfH0EPnHkBxTlurIQ.jpeg" /></figure><p>In this directory, you will find a file named “wsconfig.exe”. Run this file as an administrator. When the “Web Server Configuration Tool” opens up, click on the “Add” button to run the wizard for web server configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*_EPIAxr9PGG-UQgziiFqFg.jpeg" /></figure><p>In the wizard, select “App Server” as IIS and “IIS Websites” as “ALL”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*VNYeqeH9cGyb5i5kLDY94w.jpeg" /></figure><p>Once you have made these selections, click on the “Advanced” button. In the “Advanced” screen, enable the buffering option and click on “OK”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*tZ7Lu7CejTiYQ4fMxFLahg.jpeg" /></figure><p>Now, click on the “OK” button of the “Add Server Configuration” screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*Ed2-M169vl1ApK6Lm4i2-A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*FZwOS4Jwc048ZS3FyKi-sw.jpeg" /></figure><p>That’s it! Your ColdFusion project will now be working on IIS. You can now test your project by visiting the URL of your site in a web browser.</p><p><strong>Conclusion</strong></p><p>Integrating ColdFusion with IIS enables developers to deploy ColdFusion applications on a Windows server. By following the simple steps outlined in this article, you can easily run a ColdFusion site with IIS. By configuring your project with IIS, you can take advantage of the powerful features that IIS offers, such as load balancing and SSL encryption.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79eb5ccb2ffe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Signing AWS API Requests in ColdFusion: A Step-by-Step Guide | Sajjad Hussain]]></title>
            <link>https://medium.com/@sajjadast786/signing-aws-api-requests-in-coldfusion-a-step-by-step-guide-sajjad-hussain-6592f6d893cc?source=rss-980588a423fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/6592f6d893cc</guid>
            <dc:creator><![CDATA[Sajjad Hussain]]></dc:creator>
            <pubDate>Fri, 07 Apr 2023 17:11:58 GMT</pubDate>
            <atom:updated>2023-04-07T17:57:23.544Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Signing AWS API Requests in ColdFusion: A Step-by-Step Guide | Sajjad Hussain</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7yb39bzi-ioctUlOH_pTuw.jpeg" /></figure><p>AWS (Amazon Web Services) provides a powerful set of APIs for interacting with various AWS services, such as S3, EC2, and Lambda. To make authenticated API requests to AWS, you need to sign your requests using the AWS Signature Version 4 algorithm. In this tutorial, we will walk you through the process of signing AWS API requests in ColdFusion using the AWS Signature Version 4 algorithm.</p><p>AWS Signature Version 4 is a method for authenticating AWS API requests that provides a high level of security by ensuring that requests are not tampered with during transit and are only accepted by AWS if they are genuine. The process of signing requests involves several steps, including creating a canonical request, creating a string to sign, and generating a signature using a secret key.</p><p>Let’s dive into the step-by-step guide on how to sign AWS API requests in ColdFusion.</p><h3>Step 1: Set up AWS Access Key and Secret Key</h3><p>To sign AWS API requests, you need to have your AWS Access Key and Secret Key handy. These are the credentials that AWS uses to authenticate your requests. If you don’t have these credentials already, you can generate them in the AWS Management Console under the “IAM (Identity and Access Management)” service.</p><h3>Step 2: Set up Required Variables</h3><p>In your ColdFusion code, you need to set up the following variables:</p><pre>&lt;cfset accessKey = &quot;YOUR_ACCESS_KEY&quot;&gt;<br>&lt;cfset secretKey = &quot;YOUR_SECRET_KEY&quot;&gt;<br>&lt;cfset region = &quot;us-east-1&quot;&gt;<br>&lt;cfset service = &quot;s3&quot;&gt;<br>&lt;cfset httpMethod = &quot;GET&quot;&gt;<br>&lt;cfset canonicalUri = &quot;/example-bucket/example-object&quot;&gt;<br>&lt;cfset canonicalQueryString = &quot;&quot;&gt;</pre><p>Replace “YOUR_ACCESS_KEY” and “YOUR_SECRET_KEY” with your actual AWS Access Key and Secret Key, respectively. Also, set the appropriate AWS region, service, HTTP method, canonical URI, and canonical query string based on your API request.</p><h3>Step 3: Create a Timestamp in ISO 8601 Format</h3><p>AWS requires a timestamp in ISO 8601 format for signing API requests. You can create a timestamp in ColdFusion using the following code:</p><pre>&lt;cfset now = now()&gt;<br>&lt;cfset timestamp = dateConvert(&quot;utc2Local&quot;, now)&gt;<br>&lt;cfset timestamp = dateConvert(&quot;local2Utc&quot;, timestamp)&gt;<br>&lt;cfset timestamp = dateFormat(timestamp, &quot;yyyy-mm-dd&#39;T&#39;HH:mm:ss&#39;Z&#39;&quot;)&gt;</pre><p>The above code creates a timestamp in the local time zone, converts it to UTC, and formats it in ISO 8601 format.</p><h3>Step 4: Create a Date String in YYYYMMDD Format</h3><p>AWS requires a date string in the “YYYYMMDD” format for signing API requests. You can create a date string in ColdFusion using the following code:</p><pre>&lt;cfset dateStamp = dateFormat(timestamp, &quot;yyyymmdd&quot;)&gt;</pre><p>The above code formats the timestamp obtained in the previous step to a date string in “YYYYMMDD” format.</p><h3>Step 5: Create the Canonical Headers String</h3><p>AWS requires a canonical headers string for signing API requests. The canonical headers string consists of the “host” and “x-amz-date” headers in a specific format. You can create the canonical headers string in ColdFusion using the following code:</p><pre>&lt;cfset canonicalHeaders = &quot;host:#GetHttpRequestData().headers.host#x-amz-date:#timestamp#&quot;&gt;</pre><p>The above code uses the `GetHttpRequestData()` function to retrieve the “host” header from the API request headers and concatenates it with the “x-amz-date” header and its corresponding value obtained in the previous steps, separated by a line break (`&amp;#10;`).</p><h3>Step 6: Create the Canonical Request</h3><p>The canonical request is a string that represents the complete details of the API request in a specific format. You can create the canonical request in ColdFusion using the following code:</p><pre>&lt;cfset canonicalRequest = httpMethod &amp; chr(10) &amp; canonicalUri &amp; chr(10) &amp; canonicalQueryString &amp; chr(10) &amp; canonicalHeaders &amp; chr(10) &amp; &quot;UNSIGNED-PAYLOAD&quot;&gt;</pre><p>The above code concatenates the HTTP method, canonical URI, canonical query string, canonical headers, and “UNSIGNED-PAYLOAD” (since we are not including the request payload in this example) into a single string, separated by line breaks (chr(10)).</p><h3>Step 7: Create the String to Sign</h3><p>The string to sign is a string that represents the complete details of the API request that will be used to generate the signature. You can create the string to sign in ColdFusion using the following code:</p><pre>&lt;cfset stringToSign = &quot;AWS4-HMAC-SHA256&quot; &amp; chr(10) &amp; timestamp &amp; chr(10) &amp; dateStamp &amp; &quot;/&quot; &amp; region &amp; &quot;/&quot; &amp; service &amp; &quot;/aws4_request&quot; &amp; chr(10) &amp; hash(canonicalRequest, &quot;SHA-256&quot;)&gt;</pre><p>The above code concatenates the AWS Signature Version 4 algorithm, timestamp, date stamp, AWS region, AWS service, and the hash of the canonical request (using SHA-256) into a single string, separated by line breaks (chr(10)).</p><h3>Step 8: Generate the Signature</h3><p>The signature is a hexadecimal string that is generated by applying the AWS Signature Version 4 algorithm to the string to sign using the AWS Secret Key. You can generate the signature in ColdFusion using the following code:</p><pre>&lt;cfset kDate = hmac(&quot;AWS4&quot; &amp; secretKey, dateStamp, &quot;HmacSHA256&quot;)&gt;<br>&lt;cfset kRegion = hmac(kDate, region, &quot;HmacSHA256&quot;)&gt;<br>&lt;cfset kService = hmac(kRegion, service, &quot;HmacSHA256&quot;)&gt;<br>&lt;cfset kSigning = hmac(kService, &quot;aws4_request&quot;, &quot;HmacSHA256&quot;)&gt;<br>&lt;cfset signature = toBase64(hmac(kSigning, stringToSign, &quot;HmacSHA256&quot;))&gt;</pre><p>The above code uses the hmac function to generate intermediate keys (kDate, kRegion, kService, and kSigning) by applying the HMAC-SHA256 algorithm with the AWS Secret Key and the corresponding values (date stamp, region, service, and “aws4_request”) as inputs. Finally, the toBase64 function is used to convert the resulting signature from binary to base64-encoded format.</p><h3>Step 9: Include the Signature in the API Request Headers</h3><p>Finally, you need to include the generated signature in the “Authorization” header of the API request. You can add the “Authorization” header in ColdFusion using the following code:</p><pre>&lt;cfhttp url=&quot;https://example-bucket.s3.amazonaws.com/example-object&quot; method=&quot;GET&quot; result=&quot;response&quot;&gt;<br>&lt;cfhttpparam type=&quot;header&quot; name=&quot;host&quot; value=&quot;example-bucket.s3.amazonaws.com&quot;&gt;<br>&lt;cfhttpparam type=&quot;header&quot; name=&quot;x-amz-date&quot; value=&quot;#timestamp#&quot;&gt;<br>&lt;cfhttpparam type=&quot;header&quot; name=&quot;Authorization&quot; value=&quot;AWS4-HMAC-SHA256 Credential=#accessKeyId#/#dateStamp#/#region#/#service#/aws4_request, SignedHeaders=#signedHeaders#, Signature=#signature#&quot;&gt;<br>&lt;/cfhttp&gt;</pre><p>The above code uses the `&lt;cfhttpparam&gt;` tag to include the “host” and “x-amz-date” headers in the API request. It also includes the “Authorization” header with the generated signature in the format specified by AWS for signing API requests. The “Credential” field includes the AWS access key ID, date stamp, region, service, and “aws4_request”. The “SignedHeaders” field includes the list of headers that were included in the canonical request. Finally, the “Signature” field includes the generated signature.</p><p>And that’s it! With the above code, you have successfully implemented the AWS Signature Version 4 algorithm in ColdFusion to sign API requests for AWS services like Amazon S3. Remember to replace the placeholders with your actual AWS access key ID, secret key, region, service, and other relevant values for your specific use case.</p><p><strong><em>The author is a highly skilled Lead Full Stack Developer with expertise in React JS, Node JS, Next JS, and other cutting-edge technologies. He possess extensive experience ranging from being a programmer to a team lead, and have played a crucial role in the development of complex and large-scale projects. Profile: </em></strong><a href="https://www.linkedin.com/in/sajjadhussain12/">https://www.linkedin.com/in/sajjadhussain12</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6592f6d893cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React JS Tutorial | Building an E-commerce App with React JS | Sajjad Hussain]]></title>
            <link>https://medium.com/@sajjadast786/react-js-tutorial-building-an-e-commerce-app-with-react-js-sajjad-hussain-17d043f80e87?source=rss-980588a423fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/17d043f80e87</guid>
            <dc:creator><![CDATA[Sajjad Hussain]]></dc:creator>
            <pubDate>Thu, 06 Apr 2023 13:28:15 GMT</pubDate>
            <atom:updated>2023-04-07T17:59:43.392Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>React JS Tutorial | Building an E-commerce App with React JS | Sajjad Hussain</strong></p><figure><img alt="React JS Tutorial | Building an E-commerce App with React JS | Sajjad Hussain" src="https://cdn-images-1.medium.com/max/1023/1*wR_zkQd_lgkMIuDP7yHwdA.png" /></figure><p>In this tutorial, we will be building an e-commerce application using React JS. React JS is a popular JavaScript library for building user interfaces, particularly for web applications. It allows developers to create reusable UI components and efficiently manage the state of the application.</p><h3><strong>Prerequisites:</strong></h3><p>Before starting this tutorial, you should have basic knowledge of JavaScript, HTML, and CSS. Familiarity with React JS fundamentals such as components, state, and props will also be helpful.</p><h3><strong>Tools and Libraries:</strong></h3><p>To complete this tutorial, you will need the following tools and libraries:</p><p>Node.js and npm (Node Package Manager): Node.js is a JavaScript runtime that allows you to run JavaScript on the server-side, and npm is a package manager that allows you to install and manage third-party libraries in your project.</p><p>React JS: You will need to install React JS to create and manage the UI components in your application.</p><p>Redux: Redux is a state management library for JavaScript applications. It helps in managing the global state of the application, which is useful for building complex applications like e-commerce.</p><p>React Router: React Router is a library for handling routing in a React application. It allows you to create different routes for different pages in your application, such as a product page, cart page, and checkout page.</p><h3>Step 1: Set up the React JS project</h3><p>Open your terminal and navigate to the directory where you want to create your React JS project.</p><p>Run the following command to create a new React JS project using Create React App:</p><p><strong>npx create-react-app ecommerce-app</strong></p><p>Once the project is created, navigate to the project directory using the following command:</p><p><strong>cd ecommerce-app</strong></p><p>Now, you can open the project in your favorite code editor and start building your e-commerce application.</p><h3>Step 2: Create the UI Components</h3><p>In the “src” folder of your project, create a new folder called “components”.</p><p>Inside the “components” folder, create different folders for different UI components, such as “ProductList”, “ProductDetail”, “Cart”, and “Checkout”.</p><p>Inside each folder, create a corresponding React component file and implement the UI for that component using JSX and CSS. For example, in the “ProductList” component, you can create a list of products with their images, titles, and prices. In the “ProductDetail” component, you can display the details of a single product. In the “Cart” component, you can show the items added to the cart, and in the “Checkout” component, you can implement the checkout process.</p><h3>Step 3: Set up Redux for State Management</h3><p>Install Redux and React Redux in your project using the following command:</p><p><strong>npm install redux react-redux</strong></p><p>Create a “redux” folder in the “src” folder of your project.</p><p>Inside the “redux” folder, create a file called “store.js” to configure the Redux store for your application.</p><pre>import { createStore } from &#39;redux&#39;;<br>import rootReducer from &#39;./reducers&#39;;<br><br>const store = createStore(rootReducer);<br><br>export default store;</pre><p>Create a “reducers” folder inside the “redux” folder, and inside it, create a file called “index.js” to combine all the reducers.</p><pre>import { combineReducers } from &#39;redux&#39;;<br>import cartReducer from &#39;./cartReducer&#39;;<br><br>const rootReducer = combineReducers({<br>  cart: cartReducer<br>});<br><br>export default rootReducer;</pre><p>Create a “cartReducer.js” file inside the “reducers” folder to handle the state related to the cart in the Redux store.</p><pre>const initialState = {<br>  items: [], // array to store the items in the cart<br>  total: 0 // total price of items in the cart<br>};<br><br>const cartReducer = (state = initialState, action) =&gt; {<br>  switch (action.type) {<br>    case &#39;ADD_TO_CART&#39;:<br>      // check if item already exists in the cart<br>      const existingItem = state.items.find(item =&gt; item.id === action.payload.id);<br>      if (existingItem) {<br>        // if item already exists, update the quantity<br>        return {<br>          ...state,<br>          items: state.items.map(item =&gt;<br>            item.id === action.payload.id ? { ...item, quantity: item.quantity + 1 } : item<br>          ),<br>          total: state.total + action.payload.price // update the total price<br>        };<br>      } else {<br>        // if item does not exist, add it to the cart<br>        return {<br>          ...state,<br>          items: [...state.items, { ...action.payload, quantity: 1 }],<br>          total: state.total + action.payload.price // update the total price<br>        };<br>      }<br>    case &#39;REMOVE_FROM_CART&#39;:<br>      // find the index of the item to be removed<br>      const itemIndex = state.items.findIndex(item =&gt; item.id === action.payload.id);<br>      // get the quantity and price of the item to be removed<br>      const removedItem = state.items[itemIndex];<br>      return {<br>        ...state,<br>        items: state.items.filter(item =&gt; item.id !== action.payload.id), // remove the item from the cart<br>        total: state.total - removedItem.price * removedItem.quantity // update the total price<br>      };<br>    case &#39;CLEAR_CART&#39;:<br>      return {<br>        ...state,<br>        items: [], // empty the items array<br>        total: 0 // reset the total price<br>      };<br>    default:<br>      return state;<br>  }<br>};<br><br>export default cartReducer;</pre><p>Import and use the Redux store in your main application component, typically the “App.js” file.</p><pre>import React from &#39;react&#39;;<br>import { Provider } from &#39;react-redux&#39;;<br>import store from &#39;./redux/store&#39;;<br>import ProductList from &#39;./components/ProductList&#39;;<br>import Cart from &#39;./components/Cart&#39;;<br>import Checkout from &#39;./components/Checkout&#39;;<br><br>const App = () =&gt; {<br>  return (<br>    &lt;Provider store={store}&gt;<br>      &lt;div&gt;<br>        &lt;ProductList /&gt;<br>        &lt;Cart /&gt;<br>        &lt;Checkout /&gt;<br>      &lt;/div&gt;<br>    &lt;/Provider&gt;<br>  );<br>};<br><br>export default App;</pre><h3>Step 4: Implement Routing with React Router</h3><p>Install React Router in your project using the following command:</p><p><strong>npm install react-router-dom</strong></p><p>Create a “pages” folder in the “src” folder of your project.</p><p>Inside the “pages” folder, create different files for different pages of your e-commerce app, such as “ProductPage”, “CartPage”, and “CheckoutPage”.</p><p>Inside each page file, create a corresponding React component that will render the UI for that page.</p><p>In your main application component (typically “App.js”), import the necessary components from React Router and configure the routes for different pages.</p><pre>import React from &#39;react&#39;;<br>import { BrowserRouter as Router, Route, Switch } from &#39;react-router-dom&#39;;<br>import ProductPage from &#39;./pages/ProductPage&#39;;<br>import CartPage from &#39;./pages/CartPage&#39;;<br>import CheckoutPage from &#39;./pages/CheckoutPage&#39;;<br><br>const App = () =&gt; {<br>  return (<br>    &lt;Router&gt;<br>      &lt;div&gt;<br>        &lt;Switch&gt;<br>          &lt;Route exact path=&quot;/&quot; component={ProductPage} /&gt;<br>          &lt;Route path=&quot;/cart&quot; component={CartPage} /&gt;<br>          &lt;Route path=&quot;/checkout&quot; component={CheckoutPage<br><br><br><br><br>} /&gt;<br>&lt;/Switch&gt;<br>&lt;/div&gt;<br>&lt;/Router&gt;<br>);<br>};<br><br>export default App;</pre><p>6. In each page component, you can access the Redux store and dispatch actions to update the state based on user interactions or other events.</p><p>7. Update your navigation or links in your components to navigate between different pages using the “Link” component provided by React Router.</p><pre>import React from &#39;react&#39;;<br>import { Link } from &#39;react-router-dom&#39;;<br><br>const Navigation = () =&gt; {<br>  return (<br>    &lt;nav&gt;<br>      &lt;ul&gt;<br>        &lt;li&gt;<br>          &lt;Link to=&quot;/&quot;&gt;Home&lt;/Link&gt;<br>        &lt;/li&gt;<br>        &lt;li&gt;<br>          &lt;Link to=&quot;/cart&quot;&gt;Cart&lt;/Link&gt;<br>        &lt;/li&gt;<br>        &lt;li&gt;<br>          &lt;Link to=&quot;/checkout&quot;&gt;Checkout&lt;/Link&gt;<br>        &lt;/li&gt;<br>      &lt;/ul&gt;<br>    &lt;/nav&gt;<br>  );<br>};<br><br>export default Navigation;</pre><h3>Step 5: Implement UI Components</h3><p>Create UI components for different parts of your e-commerce app, such as product list, cart, checkout, and individual product item.</p><p>Use the Redux store to get the data and update the state in your UI components.</p><p>Utilize CSS or CSS-in-JS libraries like styled-components or emotion to style your components and create a visually appealing user interface.</p><p>Example of a ProductList component:</p><pre>import React from &#39;react&#39;;<br>import { connect } from &#39;react-redux&#39;;<br>import { addToCart } from &#39;../redux/actions/cartActions&#39;;<br><br>const ProductList = ({ products, addToCart }) =&gt; {<br>  return (<br>    &lt;div&gt;<br>      &lt;h2&gt;Product List&lt;/h2&gt;<br>      {products.map(product =&gt; (<br>        &lt;div key={product.id}&gt;<br>          &lt;h3&gt;{product.name}&lt;/h3&gt;<br>          &lt;p&gt;Price: ${product.price}&lt;/p&gt;<br>          &lt;button onClick={() =&gt; addToCart(product)}&gt;Add to Cart&lt;/button&gt;<br>        &lt;/div&gt;<br>      ))}<br>    &lt;/div&gt;<br>  );<br>};<br><br>const mapStateToProps = state =&gt; {<br>  return {<br>    products: state.products // access the products data from the Redux store<br>  };<br>};<br><br>const mapDispatchToProps = dispatch =&gt; {<br>  return {<br>    addToCart: product =&gt; dispatch(addToCart(product)) // dispatch the addToCart action to add item to cart<br>  };<br>};<br><br>export default connect(mapStateToProps, mapDispatchToProps)(ProductList);</pre><p>Example of a Cart component:</p><pre>import React from &#39;react&#39;;<br>import { connect } from &#39;react-redux&#39;;<br>import { removeFromCart, clearCart } from &#39;../redux/actions/cartActions&#39;;<br><br>const Cart = ({ cartItems, removeFromCart, clearCart }) =&gt; {<br>  return (<br>    &lt;div&gt;<br>      &lt;h2&gt;Cart&lt;/h2&gt;<br>      {cartItems.length === 0 ? (<br>        &lt;p&gt;Cart is empty&lt;/p&gt;<br>      ) : (<br>        &lt;div&gt;<br>          {cartItems.map(item =&gt; (<br>            &lt;div key={item.id}&gt;<br>              &lt;h3&gt;{item.name}&lt;/h3&gt;<br>              &lt;p&gt;Price: ${item.price}&lt;/p&gt;<br>              &lt;p&gt;Quantity: {item.quantity}&lt;/p&gt;<br>              &lt;button onClick={() =&gt; removeFromCart(item)}&gt;Remove&lt;/button&gt;<br>            &lt;/div&gt;<br>          ))}<br>          &lt;button onClick={() =&gt; clearCart()}&gt;Clear Cart&lt;/button&gt;<br>        &lt;/div&gt;<br>      )}<br>    &lt;/div&gt;<br>  );<br>};<br><br>const mapStateToProps = state =&gt; {<br>  return {<br>    cartItems: state.cart.items // access the cart items data from the Redux store<br>  };<br>};<br><br>const mapDispatchToProps = dispatch =&gt; {<br>  return {<br>    removeFromCart: item =&gt; dispatch(removeFromCart(item)), // dispatch the removeFromCart action to remove item from cart<br>    clearCart: () =&gt; dispatch(clearCart()) // dispatch the clearCart action to clear cart<br>  };<br>};<br><br>export default connect(mapStateToProps,mapDispatchToProps)(Cart);</pre><p>Example of a Checkout component:</p><pre>import React, { useState } from &#39;react&#39;;<br>import { connect } from &#39;react-redux&#39;;<br>import { clearCart } from &#39;../redux/actions/cartActions&#39;;<br><br>const Checkout = ({ cartItems, clearCart }) =&gt; {<br>  const [name, setName] = useState(&#39;&#39;);<br>  const [email, setEmail] = useState(&#39;&#39;);<br><br>  const handleCheckout = () =&gt; {<br>    // Implement your checkout logic here<br>    // You can use the data from the state (name, email) and cartItems from Redux store<br>    // to make API calls or perform any other necessary actions<br><br>    // Clear the cart after successful checkout<br>    clearCart();<br>  };<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h2&gt;Checkout&lt;/h2&gt;<br>      &lt;form&gt;<br>        &lt;label&gt;<br>          Name:<br>          &lt;input type=&quot;text&quot; value={name} onChange={e =&gt; setName(e.target.value)} /&gt;<br>        &lt;/label&gt;<br>        &lt;label&gt;<br>          Email:<br>          &lt;input type=&quot;email&quot; value={email} onChange={e =&gt; setEmail(e.target.value)} /&gt;<br>        &lt;/label&gt;<br>        &lt;button type=&quot;button&quot; onClick={handleCheckout}&gt;<br>          Checkout<br>        &lt;/button&gt;<br>      &lt;/form&gt;<br>    &lt;/div&gt;<br>  );<br>};<br><br>const mapStateToProps = state =&gt; {<br>  return {<br>    cartItems: state.cart.items // access the cart items data from the Redux store<br>  };<br>};<br><br>const mapDispatchToProps = dispatch =&gt; {<br>  return {<br>    clearCart: () =&gt; dispatch(clearCart()) // dispatch the clearCart action to clear cart<br>  };<br>};<br><br>export default connect(mapStateToProps, mapDispatchToProps)(Checkout);</pre><h3>Step 6: Implement Redux Actions and Reducers</h3><p>Define Redux actions to handle different interactions in your app, such as adding to cart, removing from cart, and clearing cart.</p><p>Create Redux reducers to handle the state updates based on the actions dispatched.</p><p>Use Redux middleware, such as thunk or saga, if needed, to handle asynchronous actions, such as fetching data from APIs.</p><p>Example of Redux actions:</p><pre>// src/redux/actions/cartActions.js<br><br>// Action types<br>export const ADD_TO_CART = &#39;ADD_TO_CART&#39;;<br>export const REMOVE_FROM_CART = &#39;REMOVE_FROM_CART&#39;;<br>export const CLEAR_CART = &#39;CLEAR_CART&#39;;<br><br>// Action creators<br>export const addToCart = item =&gt; {<br>  return {<br>    type: ADD_TO_CART,<br>    payload: item<br>  };<br>};<br><br>export const removeFromCart = item =&gt; {<br>  return {<br>    type: REMOVE_FROM_CART,<br>    payload: item<br>  };<br>};<br><br>export const clearCart = () =&gt; {<br>  return {<br>    type: CLEAR_CART<br>  };<br>};<br>Example of Redux reducers:<br><br>jsx<br><br>// src/redux/reducers/cartReducer.js<br><br>import { ADD_TO_CART, REMOVE_FROM_CART, CLEAR_CART } from &#39;../actions/cartActions&#39;;<br><br>const initialState = {<br>  items: []<br>};<br><br>const cartReducer = (state = initialState, action) =&gt; {<br>  switch (action.type) {<br>    case ADD_TO_CART:<br>      return {<br>        ...state,<br>        items: [...state.items, action.payload]<br>      };<br>    case REMOVE_FROM_CART:<br>      return {<br>        ...state,<br>        items: state.items.filter(item =&gt; item.id !== action.payload.id)<br>      };<br>    case CLEAR_CART:<br>      return {<br>        ...state,<br>        items: []<br>      };<br>    default:<br>      return state;<br>  }<br>};<br><br>export default cartReducer;</pre><h3>Step 7: Connect Redux Store to Your App</h3><p>Use the “Provider” component from react-redux library to wrap your root component and pass the Redux store as a prop.</p><p>In your root component (e.g., App.js), use the “connect” function from react-redux library to connect your app to</p><p>the Redux store and access the state and dispatch actions as needed.</p><p>Example of connecting Redux store to App.js:</p><pre>// src/App.js<br><br>import React from &#39;react&#39;;<br>import { Provider } from &#39;react-redux&#39;;<br>import store from &#39;./redux/store&#39;;<br>import Cart from &#39;./components/Cart&#39;;<br>import Checkout from &#39;./components/Checkout&#39;;<br><br>const App = () =&gt; {<br>  return (<br>    &lt;Provider store={store}&gt;<br>      &lt;div&gt;<br>        {/* Render components that need access to Redux store */}<br>        &lt;Cart /&gt;<br>        &lt;Checkout /&gt;<br>      &lt;/div&gt;<br>    &lt;/Provider&gt;<br>  );<br>};<br><br>export default App;</pre><p>And that’s it! You have now successfully implemented a simple eCommerce cart functionality using React and Redux.</p><p>React and Redux are powerful tools for building complex and scalable web applications. In this tutorial, you learned how to create a simple eCommerce cart feature using React components, Redux store, actions, and reducers. You also learned how to connect your components to the Redux store using the “connect” function from react-redux library.</p><p>Remember, this is just a basic example, and there are many other features you can implement in a real-world eCommerce application, such as handling API calls, managing user authentication, and integrating with a backend server. With the knowledge gained from this tutorial, you can continue to explore and build more sophisticated applications using React and Redux. Happy coding!</p><p><strong><em>The author is a highly skilled Lead Full Stack Developer with expertise in React JS, Node JS, Next JS, and other cutting-edge technologies. He possess extensive experience ranging from being a programmer to a team lead, and have played a crucial role in the development of complex and large-scale projects. Profile: </em></strong><a href="https://www.linkedin.com/in/sajjadhussain12/">https://www.linkedin.com/in/sajjadhussain12</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17d043f80e87" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 Advanced JavaScript Tricks for Experienced Developers | Sajjad Hussain]]></title>
            <link>https://medium.com/@sajjadast786/5-advanced-javascript-tricks-for-experienced-developers-f4d91e729aa?source=rss-980588a423fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4d91e729aa</guid>
            <dc:creator><![CDATA[Sajjad Hussain]]></dc:creator>
            <pubDate>Fri, 31 Mar 2023 11:32:21 GMT</pubDate>
            <atom:updated>2023-04-06T13:34:32.021Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>5 Advanced JavaScript Tricks for Experienced Developers | Sajjad Hussain</strong></p><figure><img alt="5 Advanced JavaScript Tricks for Experienced Developers" src="https://cdn-images-1.medium.com/max/1024/1*xiDj73t-bBDLZJ_GUlDnbw.jpeg" /></figure><p><strong>Closure:</strong></p><p>Closure is a powerful technique in JavaScript that allows developers to create private variables and functions. This means that variables and functions can be accessed only by the functions that were defined within the same scope. By using closure, you can create encapsulated code that is much more robust and secure. Here’s an example:</p><pre>function add(a) {<br>return function(b) {<br>return a + b;<br>}<br>}<br>const add5 = add(5);<br>console.log(add5(3)); // 8</pre><p>In this example, the add() function returns another function that adds its argument to the a parameter. The add5 variable is a closure that “remembers” the a parameter and can be called multiple times with different arguments.</p><h3>2. Currying:</h3><p>Currying is a technique in JavaScript that allows you to convert a function that takes multiple arguments into a series of functions that take a single argument. This can be useful for creating reusable functions that can be used in different contexts. Here’s an example:</p><pre>function multiply(a) {<br>return function(b) {<br>return a * b;<br>}<br>}<br>const double = multiply(2);<br>console.log(double(3)); // 6</pre><p>In this example, the multiply() function returns another function that multiplies its argument by the a parameter. The double variable is a curried function that multiplies its argument by 2.</p><h3>3. Memoization:</h3><p>Memoization is a technique in JavaScript that allows you to cache the results of expensive function calls. This can improve performance by reducing the number of times a function needs to be called with the same arguments. Here’s an example:</p><pre>function memoize(func) {<br>const cache = {};<br>return function(…args) {<br>const key = JSON.stringify(args);<br>if (cache[key]) {<br>return cache[key];<br>}<br>const result = func(…args);<br>cache[key] = result;<br>return result;<br>}<br>}<br>function fibonacci(n) {<br>if (n &lt; 2) {<br>return n;<br>}<br>return fibonacci(n - 1) + fibonacci(n - 2);<br>}<br>const memoizedFibonacci = memoize(fibonacci);<br>console.log(memoizedFibonacci(10)); // 55</pre><p>In this example, the memoize() function returns another function that caches the results of the func() function using a key generated from the arguments. If the result is already in the cache, it is returned without calling func(). Otherwise, func() is called and its result is cached before being returned.</p><h3>4. Generators:</h3><p>Generators are a powerful feature in JavaScript that allow you to create iterators with lazy evaluation. This means that the next value in the sequence is calculated only when it is requested. Generators are defined using the function* syntax and the yield keyword. Here’s an example:</p><pre>function* fibonacci() {<br>let a = 0, b = 1;<br>while (true) {<br>yield a;<br>[a, b] = [b, a + b];<br>}<br>}<br>const generator = fibonacci();<br>console.log(generator.next().value); // 0<br>console.log(generator.next().value); // 1<br>console.log(generator.next().value); // 1<br>console.log(generator.next().value); // 2</pre><p>In this example, the fibonacci() function is a generator that yields the next number in the Fibonacci sequence each time it is called. The generator variable is an iterator that can be used to iterate over the sequence.</p><h3>5. Promises:</h3><p>Promises are a built-in feature in JavaScript that provide a cleaner way to handle asynchronous code. Promises represent the eventual completion or failure of an asynchronous operation and allow you to chain multiple operations together. Here’s an example:</p><pre>function getData() {<br>return new Promise((resolve, reject) =&gt; {<br>fetch(&#39;https://example.com/data&#39;)<br>.then(response =&gt; response.json())<br>.then(data =&gt; resolve(data))<br>.catch(error =&gt; reject(error));<br>});<br>}<br>getData()<br>.then(data =&gt; console.log(data))<br>.catch(error =&gt; console.error(error));</pre><p>In this example, the getData() function returns a Promise that resolves with the data returned by a web API call. The then() method is used to handle the successful completion of the Promise, while the catch() method is used to handle any errors.</p><p>Overall, these advanced JavaScript techniques can be very powerful in the hands of experienced developers. By using them, you can write more efficient, reusable, and scalable code that is easier to maintain and debug.</p><p><strong><em>The author is a highly skilled Lead Full Stack Developer with expertise in React JS, Node JS, Next JS, and other cutting-edge technologies. He possess extensive experience ranging from being a programmer to a team lead, and have played a crucial role in the development of complex and large-scale projects. Profile: </em></strong><a href="https://www.linkedin.com/in/sajjadhussain12/">https://www.linkedin.com/in/sajjadhussain12</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4d91e729aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>