<?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 QA-init on Medium]]></title>
        <description><![CDATA[Stories by QA-init on Medium]]></description>
        <link>https://medium.com/@QA-initi?source=rss-d968c631bf1f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*KVQNXcJQqcZMm61JSS_qow.png</url>
            <title>Stories by QA-init on Medium</title>
            <link>https://medium.com/@QA-initi?source=rss-d968c631bf1f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 05:10:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@QA-initi/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[Build Tools in React Ecosystems Webpack, Babel, Turbopack, tsc, SWC]]></title>
            <link>https://medium.com/@QA-initi/build-tools-in-react-ecosystems-webpack-babel-turbopack-tsc-swc-be21636a78ac?source=rss-d968c631bf1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/be21636a78ac</guid>
            <category><![CDATA[babeljs]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[swc]]></category>
            <category><![CDATA[webpack]]></category>
            <dc:creator><![CDATA[QA-init]]></dc:creator>
            <pubDate>Wed, 22 Apr 2026 19:26:29 GMT</pubDate>
            <atom:updated>2026-04-22T19:32:49.350Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Have you heard about these terms but find it difficult to co-relate, then this post is for you.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9aBNC-obDSFJf3y5" /><figcaption>Photo by <a href="https://unsplash.com/@graphis_photos?utm_source=medium&amp;utm_medium=referral">sıtkı aksoy</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Whenever we create a new react project or nexjs project, there are different files and bundles which automatically gets added to the project to enhance the developer experience and make the application development faster. This post aims to discuss those concepts which are part of the application compilation and building process.</p><h3>Webpack (Bundler)</h3><p><strong>What it is</strong>: <em>A module bundler for web apps</em>. It starts from entry file(s) and produces optimized output bundles. It can also process CSS, images, and other assets via loaders and plugins.<br><strong>When to use it</strong>: Traditional React/Vue/TypeScript apps, or when you need highly customizable build pipelines.</p><p>Example: webpack.config.js(basic)</p><pre>const path = require(&quot;path&quot;);<br><br>module.exports = {<br>  mode: &quot;production&quot;,<br>  entry: &quot;./src/index.ts&quot;,<br>  output: {<br>    filename: &quot;bundle.js&quot;,<br>    path: path.resolve(__dirname, &quot;dist&quot;),<br>    clean: true,<br>  },<br>  module: {<br>    rules: [<br>      {<br>        test: /\.[tj]sx?$/,<br>        exclude: /node_modules/,<br>        use: &quot;babel-loader&quot;,<br>      },<br>    ],<br>  },<br>  resolve: { extensions: [&quot;.ts&quot;, &quot;.tsx&quot;, &quot;.js&quot;] },<br>};</pre><p>Build command:</p><pre>npx webpack</pre><h3>Babel (Transpiler)</h3><p><strong>What it is</strong>: <em>A JavaScript/TypeScript transpiler</em>. Babel converts modern JavaScript syntax (and optionally JSX/TS syntax) into JavaScript that older browsers or Node versions can run.<br>Important: Babel does not do type-checking for TypeScript.</p><p><strong>When to use it</strong>: To support older browsers, to transform JSX, to apply plugins(macros, code transforms)</p><p>Example: transpile modern JS + JSX</p><pre>.babelrc<br>{<br>  &quot;presets&quot;: [<br>    [&quot;@babel/preset-env&quot;, { &quot;targets&quot;: &quot;&gt;0.25%, not dead&quot; }],<br>    [&quot;@babel/preset-react&quot;, { &quot;runtime&quot;: &quot;automatic&quot; }],<br>    [&quot;@babel/preset-typescript&quot;]<br>  ]<br>}</pre><p>Input:</p><pre>&lt;&gt; src/App.tsx<br>export const App = () =&gt; &lt;h1&gt;Hello&lt;/h1&gt;</pre><p>Command</p><pre>npx babel src --extensions &quot;.ts, .tsx&quot; --out-dir dist</pre><p>Output: browser-compatible JS with JSX transformed.</p><h3>Turbopack (Bundler / Dev Server)</h3><p><strong>What it is</strong>: A Rust-based bundler/dev server by Vercel(used with NextJs) focused on very fast incremental builds in development.</p><p><strong>When to use it</strong>: Mostly in Next.js projects (especially dev mode). It’s a replacement path for webpack in the Next.js ecosystem.</p><p>Example: run Next.js dev with Turbopack</p><pre>npx next dev --turbo</pre><p>Advantage: Faster startup and faster “edit → refresh” cycle especially as the application gets large.</p><h3>tsc (TypeScript Compiler + Type Checker)</h3><p>What it is: The official TypeScript compiler. It can:</p><p>1. Type-check TS code.</p><p>2. Edit JavaScript optionally</p><p>3. Generate <strong><em>.d.ts</em></strong><em> </em>type declaration files.</p><p>Key point: tsc is the type-checking authority for TS.</p><p>Example: type-check only(no JS output)</p><pre>{<br>  &quot;compilerOptions&quot;: {<br>    &quot;target&quot;: &quot;ES2020&quot;,<br>    &quot;strict&quot;: true,<br>    &quot;noEmit&quot;: true<br>  },<br>  &quot;include&quot;: [&quot;src&quot;]<br>}</pre><p>Run:</p><pre>npx tsc</pre><p>Type check with emitting:</p><pre>{<br>  &quot;compilerOptions&quot;: {<br>    &quot;outDir&quot;: &quot;dist&quot;,<br>    &quot;module&quot;: &quot;ESNext&quot;,<br>    &quot;target&quot;: &quot;ES2020&quot;,<br>    &quot;declaration&quot;: true<br>  },<br>}</pre><h3>SWC (Transpiler / Minifier)</h3><p>What it is: A fast Rust-based compiler that can transform JS/TS/JSX/TSX and minify output. Commonly used by Next.js and can replace Babel in many toolchains.<br>Important: Like Babel, SWC transpiles TypeScript syntax but does not replace TypeScript type-checking unless you run type checks separately.</p><p>Example: .swcrc</p><pre>{<br>  &quot;jsc&quot;: {<br>    &quot;parser&quot;: { &quot;syntax&quot;: &quot;typescript&quot;, &quot;tsx&quot;: true },<br>    &quot;target&quot;: &quot;es2019&quot;<br>  },<br>  &quot;module&quot;: { &quot;type&quot;: &quot;es6&quot; }<br>}</pre><p>Command:</p><pre>npx swc src -d dist</pre><h3>How they typically fit together (common setups)</h3><h4>1) Webpack + Babel</h4><ul><li>Webpack bundles</li><li>Babel transforms JS/TS/JSX</li><li>Optionally run tsc — noEmit in CI for type checking</li></ul><h4>2) Webpack + ts-loader (or Babel) + tsc</h4><ul><li>Webpack bundles</li><li>Loader compiles/transforms</li><li>tsc may still be used for type-checking and declarations</li></ul><h4>3) Next.js + SWC (default) / Turbopack (dev)</h4><ul><li>Next.js uses SWC for transforms/minify</li><li>Turbopack can be used for dev bundling</li><li>Type-checking still exists (often via tsc or Next’s type checking pipeline)</li></ul><h3>Quick Differences (One-liners):</h3><ul><li><strong>Webpack</strong>: “Combine all my modules/assets into deployable bundles.”</li><li><strong>Babel</strong>: “Rewrite my JS/TS/JSX syntax into compatible JS.”</li><li><strong>Turbopack</strong>: “Super fast incremental dev bundling (primarily Next.js).”</li><li><strong>tsc</strong>: “Type-check TypeScript (and optionally emit JS/.d.ts).”</li><li><strong>SWC</strong>: “Babel-like transforms + minify, but faster (Rust).”</li></ul><h3><strong>Defaults by Project Type:</strong></h3><p>Understanding which of the defaults bundlers and compilers, come out of box when used with different options while creating the react app using “create-react-app” or while using the react + vite option.. Similary exploring the defaults while creating the Nextjs project.</p><h3>A) “Normal React” (CRA / Webpack-based)</h3><p>This typically means Create React App (CRA) or a custom webpack React setup.</p><p>Create React App defaults:</p><ul><li>Bundler: webpack</li><li>Transpiler: Babel</li><li>Webpack loaders (typical):</li><li>babel-loader (JS/TS/JSX/TSX)</li><li>css-loader and style-loader (CSS)</li><li>Asset handling via webpack’s built-in asset modules (modern) or historical file/url loaders</li><li>TypeScript: Babel strips TS types; type-checking is handled separately (internally via a type-checking step/plugin).</li></ul><p>Available flavors without manual compiler wiring:</p><ul><li>JavaScript template or TypeScript template</li><li>Limited Babel customization unless you eject or use additional tooling.</li></ul><h3>B) React + Vite</h3><p>Vite is a dev server + build tool.</p><p>Vite defaults:</p><ul><li>Dev-time: native ESM served to the browser</li><li>Dev-time transpilation: esbuild (fast)</li><li>Production bundler: Rollup</li></ul><p>React JSX handling options:</p><ul><li>@vitejs/plugin-react (uses Babel for transforms and Fast Refresh)</li><li>@vitejs/plugin-react-swc (uses SWC instead of Babel)</li></ul><p>TypeScript in Vite:</p><ul><li>Vite transpiles TS syntax for running/building.</li><li>Type-checking is commonly done separately using tsc — noEmit or a checker plugin.</li></ul><p>Available flavors without manual compiler wiring:</p><ul><li>Templates: react (JS) and react-ts (TS)</li><li>Choose Babel-based or SWC-based React plugin.</li></ul><h3>C) Next.js</h3><p>Next.js includes its own build pipeline.</p><p>Next.js defaults (modern):</p><ul><li>Transpiler/Compiler: SWC</li><li>Bundler: webpack (common default for production builds)</li><li>Dev bundler option: Turbopack (next dev — turbo)</li><li>Minifier: SWC minifier</li></ul><p>TypeScript in Next.js:</p><ul><li>Supported out-of-the-box.</li><li>Type-checking is typically performed during next build.</li></ul><p>Available flavors without manual compiler wiring:</p><ul><li>JavaScript or TypeScript</li><li>webpack or Turbopack (dev mode)</li><li>Babel generally not needed unless you require specific Babel plugins.</li></ul><h3>Quick Comparison Table</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ioah_dJvJ94ZEIbG6mLeGQ.png" /></figure><h3>Why it is important to know these terms?</h3><p>It’s important to know webpack/Babel/Vite/SWC/tsc/Turbopack because they determine how the React/Next app is built, runs in dev, ships to production, and fails when something breaks. Concretely:</p><ol><li>Debug build and runtime errors faster</li></ol><ul><li>Errors like “Unexpected token”, “Cannot use import statement outside a module”, JSX not compiling, or “Top-level await not supported” are usually toolchain mismatches (bundler/transpiler/target).</li><li>Knowing which tool is responsible tells you where to fix it (Babel/SWC config vs bundler config vs TS config).</li></ul><p>2. Make correct compatibility decisions (browsers + Node)</p><ul><li>The output JavaScript depends on targets (e.g., ES2017 vs ES5).</li><li>Babel/SWC + bundlers decide whether features get transformed/polyfilled, which affects:</li><li>older browser support</li><li>bundle size</li><li>whether you need polyfills (core-js, regenerator, etc.)</li></ul><p>3. Control performance: dev speed and production bundle size</p><ul><li>Tooling choices affect:</li><li>dev startup time and hot reload speed (Vite/Turbopack vs webpack)</li><li>production output (tree-shaking, code splitting, minification)</li><li>Example: SWC often speeds up transforms; Vite improves dev feedback loops; webpack is powerful but can get slower in large projects.</li></ul><p>4. Understand TypeScript “transpile vs type-check” (a common pitfall)</p><ul><li>Many setups transpile TypeScript without type-checking during dev/build.</li><li>If you don’t know this, you can mistakenly assume “it compiled so it’s type-safe.”</li><li>Typical best practice: run tsc — noEmit (or framework-integrated checks) in CI.</li></ul><p>5. Avoid fighting your framework (use defaults wisely)</p><ul><li>Next.js and Vite intentionally provide a mostly pre-wired pipeline.</li><li>If you know what they already include (SWC, Rollup, esbuild, etc.), you’ll avoid unnecessary custom configs that:</li><li>break upgrades</li><li>cause subtle bugs</li><li>slow builds</li></ul><p>6. Integrate libraries correctly</p><ul><li>Some packages ship different builds (CJS vs ESM, modern vs legacy).</li><li>Understanding bundlers/transpilers helps you resolve issues like:</li><li>ESM-only packages in older tooling</li><li>needing to transpile a dependency in node_modules</li><li>SSR incompatibilities in Next.js (using window, document)</li></ul><p>7. Make better architectural and deployment choices</p><ul><li>SSR/SSG/CSR behavior (especially in Next.js) is tied to the build pipeline.</li><li>Output affects hosting: static hosting vs Node server vs edge runtimes.</li></ul><p>8. Security and supply-chain awareness</p><ul><li>Build tooling runs a lot of third-party code (plugins/loaders).</li><li>Knowing the pipeline helps you minimize and audit what executes during builds.</li></ul><p><strong>In short: these concepts let’s:</strong></p><p>a. ship compatible code,</p><p>b. keep builds fast,</p><p>c. maintain type safety, and</p><p>d. troubleshoot confidently — without over-customizing what React/Vite/Next already do for you.</p><p>That’s all for today, Happy Reading!!!</p><p><strong>References:</strong></p><p><a href="https://webpack.js.org/concepts/">https://webpack.js.org/concepts/</a></p><p><a href="https://babeljs.io/docs/">https://babeljs.io/docs/</a></p><p><a href="https://nextjs.org/docs/app/api-reference/turbopack">https://nextjs.org/docs/app/api-reference/turbopack</a></p><p><a href="https://www.typescriptlang.org/docs/handbook/babel-with-typescript.html">https://www.typescriptlang.org/docs/handbook/babel-with-typescript.html</a></p><p><a href="https://betterstack.com/community/guides/scaling-nodejs/cli-tsc-compiler/">https://betterstack.com/community/guides/scaling-nodejs/cli-tsc-compiler/</a></p><p><a href="https://daily.dev/blog/compile-ts-to-js-a-beginners-guide">https://daily.dev/blog/compile-ts-to-js-a-beginners-guide</a></p><p><a href="https://www.typescriptlang.org/docs/handbook/modules/guides/choosing-compiler-options.html">Documentation - Modules - Choosing Compiler Options</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be21636a78ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Next.js App Router: The Mental Model That Makes It Click]]></title>
            <link>https://medium.com/@QA-initi/understanding-next-js-app-router-the-mental-model-that-makes-it-click-47c183e6ca6f?source=rss-d968c631bf1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/47c183e6ca6f</guid>
            <category><![CDATA[useful-tips]]></category>
            <category><![CDATA[nextjs-tutorial]]></category>
            <category><![CDATA[nextjs14]]></category>
            <category><![CDATA[concept]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[QA-init]]></dc:creator>
            <pubDate>Tue, 21 Apr 2026 18:47:09 GMT</pubDate>
            <atom:updated>2026-04-21T18:47:09.675Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A practical guide to server components, routing conventions, and the special files that power modern Next.js apps v14.2.15</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*kG3xS1o8SPEkNW5xQ2jhwg.png" /><figcaption>Example layout.tsx</figcaption></figure><h3>In this article:</h3><p><em>1.Server components<br>2. Client components<br>3. File-system routing<br>4. Server actions<br>5. Route handlers<br>6. page.tsx<br>7. layout.tsx<br>8. loading.tsx<br>9. error.tsx<br>10. not-found.tsx</em></p><p>If you’ve ever stared at a Next.js project and wondered why your component is fetching data on the server in one file but throwing a hydration error in another, you’re not alone. The App Router isn’t complicated — it just requires a different mental model than the Pages Router that most of us learned first.</p><p>Think of your app as a request pipeline, not a collection of pages.</p><p><strong><em>Request → Route match → Layout(s) → Page → Optional loading/error/not-found UI → Response</em></strong></p><p>The mental model</p><p><strong>The App Router as a pipeline:</strong></p><p>Before diving into individual concepts, here’s the single diagram that contextualizes everything that follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N81vpy9Hqf2bLfSXfBh0mA.png" /><figcaption>App Router Flow (Nextjs version: 14.2.15)</figcaption></figure><h4>1. Server Components</h4><p>In the App Router, <strong>every component is a Server Component by default.</strong> That single sentence is responsible for most of the confusion (and most of the power) one will encounter in a Next.js project.</p><p>Server components render entirely on the server. They never ship to the browser. This means application can talk directly to the database, read environment secrets, and do expensive data fetching — none of which leaks to the client, and none of it bloats the JavaScript bundle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RKNqxa0O5d6-9YL13pUZWA.png" /></figure><pre>Example:<br>// app/profile/[username]/page.tsx<br>// No &quot;use client&quot; = Server Component by default<br><br>import { db } from &quot;@/lib/db&quot;;<br>import { notFound } from &quot;next/navigation&quot;;<br><br>export default async function ProfilePage({<br>  params,<br>}: {<br>  params: { username: string };<br>}) {<br>  // Direct DB call — never exposed to the browser<br>  const user = await db.user.findUnique({<br>    where: { username: params.username },<br>  });<br><br>  if (!user) notFound();<br><br>  return (<br>    &lt;main&gt;<br>      &lt;h1&gt;{user.name}&lt;/h1&gt;<br>      &lt;p&gt;@{user.username}&lt;/p&gt;<br>    &lt;/main&gt;<br>  );<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F50z_1aPPYg1t7uIasvM2Q.png" /></figure><h4>2. Client Components</h4><p>The moment a user need to do something — click, toggle, type, drag — we need a Client Component. These run in the browser and are required for interactivity.</p><p><strong><em>When needed:</em></strong></p><p>useState, useEffect, event handlers, browser APIs Real-time UI interactions (click, toggle, form local state).</p><p><strong>Example:</strong></p><pre>&quot;use client&quot;;<br><br>import { useState } from &quot;react&quot;;<br><br>export default function LikeButton({ postId }: { postId: string }) {<br>  const [liked, setLiked] = useState(false);<br>  const [count, setCount] = useState(0);<br><br>  const handleLike = () =&gt; {<br>    setLiked((prev) =&gt; !prev);<br>    setCount((prev) =&gt; prev + (liked ? -1 : 1));<br>  };<br><br>  return (<br>    &lt;button onClick={handleLike} aria-pressed={liked}&gt;<br>      {liked ? &quot;♥ Liked&quot; : &quot;♡ Like&quot;} · {count}<br>    &lt;/button&gt;<br>  );<br>}</pre><p><strong>Pattern:</strong></p><ul><li>Keep page as server component</li><li>Pass minimal props to small client components for interaction</li></ul><h4>3. File System Routing</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZrDv3oh5fArUgoOHjnGXyA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IafrUdYKz3rq_pPGB_xPOA.png" /></figure><h4>4. Server Actions</h4><p>Server Actions are async functions that run on the server, callable from forms or client components. They’re the App Router’s answer to the question: “How do I submit a form without writing a REST endpoint?”</p><p>Mark a function with “<em>use server”</em> and pass it directly to a form’s action prop. Next.js handles the network boundary — no fetch calls, no API routes, no CORS headers.</p><p><strong>Example:</strong></p><pre>// actions/post.action.ts<br>&quot;use server&quot;;<br><br>import { db } from &quot;@/lib/db&quot;;<br>import { revalidatePath } from &quot;next/cache&quot;;<br>import { getServerSession } from &quot;next-auth&quot;;<br><br>export async function createPost(formData: FormData) {<br>  // 1. Always validate input<br>  const content = String(formData.get(&quot;content&quot;) || &quot;&quot;).trim();<br>  if (!content) throw new Error(&quot;Content is required&quot;);<br><br>  // 2. Always check auth<br>  const session = await getServerSession();<br>  if (!session) throw new Error(&quot;Unauthorized&quot;);<br><br>  // 3. Mutate<br>  await db.post.create({<br>    data: { content, authorId: session.user.id },<br>  });<br><br>  // 4. Revalidate the cache<br>  revalidatePath(&quot;/&quot;);<br>}</pre><pre>// Using the action in a form component<br>import { createPost } from &quot;@/actions/post.action&quot;;<br><br>export default function CreatePostForm() {<br>  return (<br>    &lt;form action={createPost}&gt;<br>      &lt;textarea name=&quot;content&quot; placeholder=&quot;What&#39;s on your mind?&quot; /&gt;<br>      &lt;button type=&quot;submit&quot;&gt;Post&lt;/button&gt;<br>    &lt;/form&gt;<br>  );<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NvxI8xaM8svmM9kUTvbMQA.png" /></figure><h4>5. Route Handlers: explicit HTTP endpoints</h4><p>Sometimes we need a proper <em>HTTP </em>API — not a form mutation, but an endpoint that external services, mobile apps, or webhooks can call. That’s what <em>route.ts</em> is for.</p><p>Route handlers live in <em>route.ts</em> files and export named functions corresponding to <em>HTTP </em>methods:<em> GET, POST, PUT, DELETE</em>, etc. We get full control over request parsing and response shaping.</p><p>Example:</p><pre>// app/api/posts/route.ts<br>import { NextRequest, NextResponse } from &quot;next/server&quot;;<br>import { db } from &quot;@/lib/db&quot;;<br><br>export async function GET(req: NextRequest) {<br>  const posts = await db.post.findMany({<br>    orderBy: { createdAt: &quot;desc&quot; },<br>    take: 20,<br>  });<br>  return NextResponse.json(posts);<br>}<br><br>export async function POST(req: NextRequest) {<br>  const body = await req.json();<br><br>  if (!body.content) {<br>    return NextResponse.json(<br>      { error: &quot;Content is required&quot; },<br>      { status: 400 }<br>    );<br>  }<br><br>  const post = await db.post.create({<br>    data: { content: body.content },<br>  });<br>  return NextResponse.json(post, { status: 201 });<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UUuMC5zLC_IqBl4432pRRQ.png" /></figure><h4>6. Page.tsx</h4><p>page.tsx is what makes a folder into a visitable route. Without it, the folder is just an organizational container — no page renders, no URL is accessible.</p><p>Think of it simply: page.tsx is what the user sees at this URL. It’s a server component by default, which means we can fetch exactly the data we need right inside it — no separate loader function, no useEffect on mount.</p><p><strong>Example:</strong></p><pre>app/dashboard/page.tsx<br><br>import { Suspense } from &quot;react&quot;;<br>import { getMetrics } from &quot;@/lib/metrics&quot;;<br>import FeedWidget from &quot;./FeedWidget&quot;;<br><br>// Metadata export — for SEO<br>export const metadata = {<br>  title: &quot;Dashboard&quot;,<br>  description: &quot;Your activity at a glance&quot;,<br>};<br><br>export default async function DashboardPage() {<br>  const metrics = await getMetrics();<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Dashboard&lt;/h1&gt;<br>      &lt;MetricsGrid data={metrics} /&gt;<br>      &lt;Suspense fallback={&lt;Spinner /&gt;}&gt;<br>        &lt;FeedWidget /&gt;<br>      &lt;/Suspense&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p><strong>7.Layout.tsx</strong></p><p>While page.tsx re-renders on every visit, layout.tsx persists. It wraps all pages within its segment and survives client-side navigation — the navbar and sidebar don’t flash or remount as users move between routes.</p><p>Every app needs a root layout at app/layout.tsx that provides the end tags. Beyond that, we can add nested layouts for specific sections — an authenticated layout, an admin layout, a settings layout. Ideal for navbar, sidebar, theme providers, shell structure</p><pre>// app/layout.tsx — root layout (required)<br>import Navbar from &quot;@/components/Navbar&quot;;<br>import &quot;./globals.css&quot;;<br><br>export default function RootLayout({<br>  children,<br>}: {<br>  children: React.ReactNode;<br>}) {<br>  return (<br>    &lt;html lang=&quot;en&quot;&gt;<br>      &lt;body&gt;<br>        &lt;Navbar /&gt;<br>        &lt;main&gt;{children}&lt;/main&gt;<br>      &lt;/body&gt;<br>    &lt;/html&gt;<br>  );<br>}<br><br>// app/(dashboard)/layout.tsx — nested layout for dashboard routes<br>export default function DashboardLayout({<br>  children,<br>}: {<br>  children: React.ReactNode;<br>}) {<br>  return (<br>    &lt;div className=&quot;dashboard-shell&quot;&gt;<br>      &lt;Sidebar /&gt;<br>      &lt;section&gt;{children}&lt;/section&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p><strong>8.Loading.tsx</strong></p><p>When a server component is doing async work — fetching data, querying a database — Next.js can show a loading UI while it waits. No isLoading state, no manual Suspense setup. Just add a loading.tsx file.</p><p>Internally, Next.js wraps the page.tsx in a Suspense boundary with loading.tsx as the fallback. The loading UI streams to the browser immediately while the actual page content resolves on the server. This is what makes Next.js feel instant even on slow data fetches.</p><pre>// app/notifications/loading.tsx<br>export default function LoadingNotifications() {<br>  return (<br>    &lt;div className=&quot;space-y-4&quot;&gt;<br>      {Array.from({ length: 5 }).map((_, i) =&gt; (<br>        &lt;div<br>          key={i}<br>          className=&quot;skeleton-row animate-pulse&quot;<br>        /&gt;<br>      ))}<br>    &lt;/div&gt;<br>  );<br>}</pre><p><strong>9.Error.tsx</strong></p><p>What happens when a server component throws? Without an error boundary, the entire page crashes. With error.tsx, we get segment-level error recovery — the error is contained, and the user gets a helpful UI with a way to recover.</p><p>Important: error.tsx must be a client component (add “use client”) because error boundaries in React are a client-side concept. It receives the error object and a reset function we can call to retry the failed segment.</p><pre>&quot;use client&quot;;<br><br>// app/notifications/error.tsx<br>export default function NotificationsError({<br>  error,<br>  reset,<br>}: {<br>  error: Error &amp; { digest?: string };<br>  reset: () =&gt; void;<br>}) {<br>  return (<br>    &lt;div role=&quot;alert&quot;&gt;<br>      &lt;h2&gt;Couldn&#39;t load notifications&lt;/h2&gt;<br>      &lt;p&gt;{error.message}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; reset()}&gt;<br>        Try again<br>      &lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p><strong>10.Not-found.tsx</strong></p><p>There’s a meaningful difference between something broke (error boundary) and this resource doesn’t exist (not-found). Next.js provides a separate file for the latter, triggered explicitly with notFound() from next/navigation.</p><p>Call notFound() when a database lookup returns null. This interrupts rendering and displays the not-found.tsx UI — with the correct 404 status code, no tricks required.</p><pre>// app/profile/[username]/page.tsx<br>import { notFound } from &quot;next/navigation&quot;;<br><br>export default async function ProfilePage({<br>  params,<br>}: {<br>  params: { username: string };<br>}) {<br>  const user = await getUser(params.username);<br><br>  // Triggers not-found.tsx automatically<br>  if (!user) notFound();<br><br>  return &lt;div&gt;{user.name}&lt;/div&gt;;<br>}<br><br>// app/not-found.tsx<br>import Link from &quot;next/link&quot;;<br><br>export default function NotFoundPage() {<br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;404 — Page not found&lt;/h1&gt;<br>      &lt;p&gt;The page you&#39;re looking for doesn&#39;t exist.&lt;/p&gt;<br>      &lt;Link href=&quot;/&quot;&gt;Go home&lt;/Link&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p><strong>Recap: Quick Practical Mental Model:</strong></p><ul><li>Read data in server components.</li><li>Keep client components small and interaction-focused.</li><li>Use server actions for internal mutations(Read/Write/Update/Delete)</li><li>Use route handlers for external/public HTTP use cases.</li><li>Add loading.tsx, error.tsx, and not-found.tsx per critical route segment for production-grade UX.</li></ul><p>These are few of the important concepts in Nextjs, please feel free to add in comments, if you would like to include any other concepts.</p><p>Happy Reading!!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47c183e6ca6f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spotify Search API]]></title>
            <link>https://medium.com/@QA-initi/spotify-search-api-50e966e43bd7?source=rss-d968c631bf1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/50e966e43bd7</guid>
            <category><![CDATA[spotify-api]]></category>
            <category><![CDATA[postman]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[spotify]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[QA-init]]></dc:creator>
            <pubDate>Wed, 29 Oct 2025 19:24:00 GMT</pubDate>
            <atom:updated>2025-10-29T19:24:00.987Z</atom:updated>
            <content:encoded><![CDATA[<p><em>In this article we will discuss about accessing the Spotify api using the Postman with “Client Credentials”.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tLRKlG3hLystmhem" /><figcaption>Photo by <a href="https://unsplash.com/@sgcreative?utm_source=medium&amp;utm_medium=referral">sgcdesignco</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Background:</h3><p>Whenever we are working on any frontend application which consumes data from the backend API’s or any external API’s. Having knowledge on accessing these api’s becomes crucial due to different Authorization workflow.</p><p>Most of the applications now-a-days are highly secure and have strong authorization and authentication workflow.</p><p>Spotify uses OAuth2.0 as its Authorization workflow along with OIDC as the Authentication protocol.</p><h3>What is OAuth2.0?</h3><p>OAuth 2.0 is an <strong>authorization</strong> framework (not an authentication protocol). It is designed to grant a third-party application limited access to a user’s protected resources on another service, without the user having to share their credentials. It uses access tokens to authorize access on behalf of the user, but it does not provide a mechanism for the application to verify who the user is. Authentication is handled separately, often in conjunction with OAuth 2.0, such as through <a href="https://www.google.com/search?q=OpenID+Connect+%28OIDC%29&amp;oq=OAuth2.0+is+a+authentication+mechanism+or+a+author&amp;gs_lcrp=EgZjaHJvbWUqCQgBECEYChigATIGCAAQRRg5MgkIARAhGAoYoAEyCQgCECEYChigATIJCAMQIRgKGKABMgkIBBAhGAoYoAEyCQgFECEYChigATIHCAYQIRiPAtIBCjE4NDUzajBqMTWoAgiwAgHxBRkxEsXVJKjE&amp;sourceid=chrome&amp;ie=UTF-8&amp;mstk=AUtExfCUNaIobhlO6lEY-yzbkgg8opDcbl9NYXv0FNRUFPRhjfm0FwIi4NtnBEttTOvCcXNRYU_6XXX7lLwdcIIys2vTnt76LL4Y_jy5GmryEXeft7W75Mzxqo6kIiw6O2b8V-8&amp;csui=3&amp;ved=2ahUKEwibtr6H18mQAxVNLkQIHfd2JpEQgK4QegQIARAC">OpenID Connect (OIDC)</a>, which is built on top of OAuth 2.0 to add an identity layer.</p><ul><li><strong>Authorization:</strong> OAuth 2.0 focuses on delegation and consent. A user can grant an application permission (via an access token) to perform specific actions on their behalf, such as “access your photos” or “read your email”.</li><li><strong>Authentication:</strong> OAuth 2.0 itself does not authenticate the user. The process of verifying the user’s identity is a separate concern, though it is often part of the same overall flow, particularly when using OIDC.</li><li><strong>How it works:</strong></li></ul><ol><li>A client application requests access to a user’s resources.</li><li>The user is directed to an authorization server to log in and grant consent.</li><li>The authorization server issues an access token to the client application.</li><li>The client uses this access token to access the user’s resources on the server/application.</li></ol><h3>Spotify API using Postman:</h3><p>While researching on this topic, I found that there is already an excellent collection on the Spotify API in the postman. Link is <a href="https://www.postman.com/postman/postman-team-collections/collection/k4a3k87/spotify">here.</a></p><p>However I created my own postman collection flow for my custom needs.</p><p>Here are the steps I followed:</p><p><strong>Pre-requisites:</strong></p><ul><li>You already have a app created in Spotify app. <a href="https://developer.spotify.com/documentation/web-api/tutorials/getting-started#create-an-app">[Docs]</a></li><li>ClientId and Client Secret is generated as part of the app creation process.</li></ul><p><strong>Postman Flow:</strong></p><ol><li>Get the token from the spotify api. (https://accounts.spotify.com/api/token)</li></ol><ul><li>Under “username” — -&gt; provide “Client Id”</li><li>Under “password” — → provide “Client Secret”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*029lNoJXY-v-Gr1Yb30_5g.png" /></figure><p><strong>Outcome</strong>: This will generate the “access_token”</p><p>2. Next, access the <a href="https://developer.spotify.com/documentation/web-api/reference/search">Spotify Search API</a> using the access_token in the request header as the Authorization process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cDAp8pW1aCzuzpJr0vRLBw.png" /></figure><p>This will authorize the search API request and will generate the API response with success.</p><p><strong>Conclusion:</strong></p><p>This is the quickest way to access any api in Spotify using your own client Id and client secret. Very helpful if we need to research on the API’s response structure and its field.</p><p>References:</p><p><a href="https://developer.spotify.com/documentation/web-api/reference/search">https://developer.spotify.com/documentation/web-api/reference/search</a></p><p><a href="https://www.freecodecamp.org/news/api-testing-with-postman-a-step-by-step-guide-using-the-spotify-api/">https://www.freecodecamp.org/news/api-testing-with-postman-a-step-by-step-guide-using-the-spotify-api/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50e966e43bd7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with Spring AI: A Beginner’s Guide to Chat Model, Prompts, and Responses]]></title>
            <link>https://medium.com/@QA-initi/getting-started-with-spring-ai-a-beginners-guide-to-chat-model-prompts-and-responses-3fe19c1b3437?source=rss-d968c631bf1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fe19c1b3437</guid>
            <category><![CDATA[openai-api]]></category>
            <category><![CDATA[chat-model]]></category>
            <category><![CDATA[chat-api]]></category>
            <category><![CDATA[spring-ai]]></category>
            <dc:creator><![CDATA[QA-init]]></dc:creator>
            <pubDate>Fri, 29 Aug 2025 00:41:23 GMT</pubDate>
            <atom:updated>2025-08-29T00:49:56.145Z</atom:updated>
            <content:encoded><![CDATA[<p><em>In this article, we’ll explore the Chat Model</em><strong><em> interface</em></strong><em> in Spring AI and break down its key components — such as messages, prompts, and responses. We’ll also talk about how we should approach the official Spring AI documentation to build a solid understanding of this model.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1zniyqQ0PkHY8qaw6F_GfQ.png" /><figcaption><a href="https://docs.spring.io/spring-ai/reference/api/chatmodel.html">https://docs.spring.io/spring-ai/reference/api/chatmodel.html</a></figcaption></figure><h3>What is Spring AI?</h3><p>Spring AI is an extension of the Spring ecosystem that allows us to easily connect with AI models (like OpenAI, Azure OpenAI, etc.). It provides:</p><ul><li><strong>Abstraction:</strong> Instead of calling APIs directly, we are using Spring’s familiar interfaces.</li><li><strong>Flexibility:</strong> Supports multiple AI providers.</li><li><strong>Integration:</strong> Plays nicely with existing Spring Boot projects.</li></ul><p>For developers new to AI, Spring AI feels natural because it uses concepts we already know — interfaces, beans, and configuration properties.</p><p><strong>Official Documentation:</strong></p><p>Below link is the reference to the chat model API under SpringAI project.</p><p><a href="https://docs.spring.io/spring-ai/reference/api/chatmodel.html">Chat Model API</a></p><h3>The ChatModel API</h3><p>At the core of Spring AI’s conversational capabilities is the <strong>ChatModel interface</strong>. Think of it as the contract for how a user can send a request to an AI model and receive a response.</p><p>A typical flow looks like this:</p><ol><li><strong>Create a message or prompt</strong></li><li><strong>Send it to the ChatModel</strong></li><li><strong>Receive a response</strong></li></ol><p>This makes working with AI conversational models as simple as working with a REST client in Spring.</p><p>The Chat Model API lets developers add AI chat features to their apps. It uses smart language models like GPT to create responses that sound like a person is talking. When someone types a message, the API sends it to the model. The model then uses what it has learned to come up with a reply that fits naturally. Once the reply is ready, the app gets it and can show it to the user or use it for more tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*sklT762_-EMgMLvm2UcNMQ.png" /><figcaption>Big picture of the chat model api</figcaption></figure><h3>Key Components</h3><h3>1. ChatModel</h3><p>A core interface for interacting with AI-powered chat models.</p><p>👉 Example:</p><pre>public interface ChatModel extends Model&lt;Prompt, ChatResponse&gt;, StreamingChatModel {<br>    default String call(String message) { ... }<br>    ChatResponse call(Prompt prompt);<br>}</pre><p><strong>What it does</strong>:</p><ul><li>The call(String message) method offers a quick, plain-text API for simple use.</li><li>The call(Prompt prompt) method provides deeper control and customization via structured prompts.</li><li>If streaming responses are needed (completing a response in parts), use methods inherited from StreamingChatModel like stream(Prompt)</li></ul><h3>2. Messages</h3><p>Messages are the building blocks of conversations. In a chat system, a message might come from either the <strong>user</strong> or the <strong>assistant</strong> (the AI).</p><p>Spring AI models this through classes like:</p><ul><li>UserMessage – Represents a user’s input.</li><li>AssistantMessage – Represents the model’s output.</li><li>SystemMessage – Provides instructions to guide the model’s behavior.</li></ul><p>They inform the model who is speaking and what role each message plays in the conversation</p><h3>3. Prompts</h3><p>A <strong>prompt</strong> represents the input a user sends to the AI model.</p><p>Can contain:</p><ul><li>Multiple <strong>messages</strong>, categorized by role (system, user, tool, etc.).</li><li>Optional <strong>ChatOptions</strong> to control behavior like model selection, response format, temperature, and more <a href="https://docs.spring.io/spring-ai/reference/api/prompt.html?utm_source=chatgpt.com">reference</a> here.</li><li>Think of Prompt as the full context: conversation setup, instruction tone, and any configuration tweaks all bundled together.</li></ul><p>👉 Example:</p><pre>Prompt prompt = new Prompt(<br>    new SystemMessage(&quot;You are a helpful Java assistant.&quot;),<br>    new UserMessage(&quot;What is Spring AI?&quot;)<br>);</pre><p>Prompts are powerful because they let control how the AI responds by including <strong>system instructions</strong> along with user input.</p><h3>4. Chart Options</h3><p>Optional settings attached to a Prompt.</p><p>Examples include:</p><ul><li>Selecting a specific model (e.g., GPT-4 or Anthropic Claude).</li><li>Adjusting <strong>temperature</strong> for creativity or determinism.</li><li>Limiting response length with <strong>max tokens</strong>.</li><li>Specifying <strong>response formats</strong>, like JSON schema compliance</li><li>Options can be configured programmatically via a builder (e.g., OpenAiChatOptions.builder()…) or through application.properties. <a href="https://docs.spring.io/spring-ai/reference/api/chat/openai-chat.html?utm_source=chatgpt.com">More reference</a></li><li>Example of openAI chat options is provided below</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*krcf1enEv44K7yVVvEr4DA.png" /><figcaption><a href="https://docs.spring.io/spring-ai/reference/api/chat/openai-chat.html">https://docs.spring.io/spring-ai/reference/api/chat/openai-chat.html</a></figcaption></figure><h3>5. Responses</h3><p>Once a prompt is sent to the ChatModel, we will get back a <strong>ChatResponse</strong>. This response contains:</p><ul><li>The <strong>Assistant’s reply</strong> (text, structured data, etc.)</li><li>Metadata (like token usage, finish reason, etc.)</li></ul><p>👉 Example:</p><pre>ChatResponse response = chatModel.call(prompt);<br>String reply = response.getResult().getOutput().getText();<br>System.out.println(reply);</pre><p>In summary:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q5LjoRKbLat2oSPJiwFzHA.png" /></figure><p>#openapi, #chatmodelapi, #springai</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fe19c1b3437" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React onClick Explained: Function calls vs Function Reference]]></title>
            <link>https://medium.com/@QA-initi/react-onclick-explained-function-calls-vs-function-reference-3591462a8636?source=rss-d968c631bf1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3591462a8636</guid>
            <category><![CDATA[onclick]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[QA-init]]></dc:creator>
            <pubDate>Thu, 28 Aug 2025 03:56:47 GMT</pubDate>
            <atom:updated>2025-08-28T03:59:28.210Z</atom:updated>
            <content:encoded><![CDATA[<p><em>When I first started working with React, one of the things that confused me was handling the </em><em>onClick event. I often found myself mixing up </em><em>onClick={() =&gt; myFunction()} and </em><em>onClick={myFunction()}, not realizing why one worked and the other caused unexpected behavior.</em></p><p><em>After making this mistake several times, I decided to dig deeper into how React interprets function calls vs. function references in event handlers. In this article I will share some of the practical examples where each approach works (or doesn’t work).</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8V8oKpvO1igiYVPnLVFL-g.png" /><figcaption>Unspalsh image by <a href="https://unsplash.com/@filisantillan">Fili Santillán</a></figcaption></figure><p>This article is an improvised version of my previous article written around the similar topic. Thanks for the precious feedback from @Sena.brauch, @kristofajosh and @patricknelson to extent this topic further</p><p>Link to the previous article:<a href="https://medium.com/@QA-initi/react-the-different-between-these-two-codes-syntax-onclick-removeitem-id-and-aa9ee07a56c8"><em>https://medium.com/@QA-initi/react-the-different-between-these-two-codes-syntax-onclick-removeitem-id-and-aa9ee07a56c8</em></a></p><h3>Understanding the Difference Between onClick={() =&gt; removeItem(id)} and onClick={removeItem(id)} in React</h3><p>When working with event handlers in React, a common source of confusion is the difference between writing:</p><pre>onClick={() =&gt; removeItem(id)}</pre><p>and</p><pre>onClick={removeItem(id)}</pre><p>At first glance, both look similar — but they behave very differently. Let’s break it down with examples.</p><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><h4>1. Using onClick={() =&gt; removeItem(id)} (✅Correct Approach)</h4><p>Here, an <strong>arrow function</strong> is created for the onClick handler. This means:</p><ul><li>The function removeItem(id) is <strong>not called immediately</strong>.</li><li>Instead, React stores the arrow function and executes it <strong>only when the button is clicked</strong>.</li><li>This is the recommended approach when we need to <strong>pass arguments</strong> to the function.</li></ul><p>Example:</p><pre>&lt;button onClick={() =&gt; removeItem(id)}&gt;Remove Item&lt;/button&gt;</pre><p>➡️The removeItem function will only run <strong>after the user clicks the button</strong></p><h3>2. Using onClick={removeItem(id)} (❌ Usually Incorrect)</h3><p>Here, we are <strong>directly invoking</strong> the function removeItem(id) while React is rendering the component. This means:</p><ul><li>removeItem(id) runs immediately during render.</li><li>Whatever the function returns gets assigned to onClick.</li><li>If it doesn’t return a function, React won’t have a valid event handler — causing errors or unexpected behavior.</li></ul><p>Example:</p><pre>&lt;button onClick={removeItem(id)}&gt;Remove Item&lt;/button&gt;</pre><p>➡️ This will call removeItem(id) immediately, not when the button is clicked.</p><h3>3. When Can You Use a Direct Method Call Without Errors?</h3><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p>There are some valid scenarios where we can safely write onClick={someFunction} without using an arrow function.</p><h4>➡️ Scenario A: Function with No Arguments</h4><p>If the function doesn’t need parameters, we can pass it directly as a reference.</p><pre>function handleClick() {<br>  alert(&quot;Button clicked!&quot;);<br>}<br><br>&lt;button onClick={handleClick}&gt;Click Me&lt;/button&gt;</pre><ul><li>Works perfectly because React stores the reference to handleClick and only calls it when the button is clicked.</li><li>If we write onClick={handleClick()}, it would execute immediately during render. Notice the brackets immediately following the handleClick which is not correct.❌</li></ul><h4>➡️Scenario B: Function That Returns Another Function</h4><p>If the function returns a new function (a “curried function”), calling it directly is fine.</p><pre>function createHandler(id) {<br>  return () =&gt; {<br>    alert(&quot;Item ID: &quot; + id);<br>  };<br>}<br><br>&lt;button onClick={createHandler(5)}&gt;Show ID&lt;/button&gt;</pre><ul><li>Here, createHandler(5) runs during render but <strong>returns a function</strong>.</li><li>That returned function is then assigned to onClick, so React has a valid event handler.</li></ul><h4>️ ️➡️Scenario C: Direct Function Reference (No Extra Wrapping)</h4><p>If no arguments are needed, we don’t need the arrow function wrapper at all.</p><pre>function sayHello() {<br>  console.log(&quot;Hello!&quot;);<br>}<br><br>&lt;button onClick={sayHello}&gt;Say Hello&lt;/button&gt;</pre><ul><li>React only calls sayHello when the button is clicked.</li><li>This is the simplest and most efficient way when no parameters are required.</li></ul><h4>➡️Scenario C: Built-in JavaScript function</h4><p>We can also directly use built-in functions, though React will pass the event object as an argument.</p><pre>&lt;button onClick={console.log}&gt;Log Event&lt;/button&gt;</pre><ul><li>Clicking the button will log the click event object.</li><li>This works because console.log is a valid function reference.</li></ul><p>🟩<strong>In Summary:</strong></p><ul><li><strong>Use </strong><strong>onClick={functionName}</strong> → when the function takes <strong>no arguments</strong>.</li><li><strong>Use </strong><strong>onClick={() =&gt; functionName(arg)}</strong> → when we need to <strong>pass arguments</strong>.</li><li><strong>Avoid </strong><strong>onClick={functionName(arg)}</strong> unless the function <strong>returns another function</strong>.</li></ul><p>🟩<strong>Example</strong>:</p><ul><li>onClick={() =&gt; removeItem(id)} → safe, common, and correct way when passing arguments.</li><li>onClick={removeItem(id)} → runs immediately and usually causes issues, unless the function returns another function.</li><li>Passing a function reference directly (onClick={sayHello}) is fine when no arguments are needed.</li></ul><p>That’s all for today. Happy reading!!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3591462a8636" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java — NullPointerException for ExentTest when trying to log inside a test]]></title>
            <link>https://medium.com/@QA-initi/java-nullpointerexception-for-exenttest-when-trying-to-log-inside-a-test-2ad940078cb6?source=rss-d968c631bf1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ad940078cb6</guid>
            <dc:creator><![CDATA[QA-init]]></dc:creator>
            <pubDate>Thu, 22 Aug 2024 18:30:38 GMT</pubDate>
            <atom:updated>2024-08-22T18:30:38.670Z</atom:updated>
            <content:encoded><![CDATA[<h3>Java — NullPointerException for ExentTest when trying to log inside a test</h3><p><em>java.lang.NullPointerException: Cannot invoke “com.aventstack.extentreports.ExtentTest.log(com.aventstack.extentreports.Status, String)” because “this.test” is null</em></p><p><strong>Description:</strong></p><p>I was trying to configure my Test Script to log the message so that the message is visible in the Extent Report. The configuration involves below 3 classes:</p><pre>package reports;<br><br>import com.aventstack.extentreports.ExtentReports;<br>import com.aventstack.extentreports.reporter.ExtentSparkReporter;<br><br>public class ExtentManager {<br>    static public ExtentReports extent;<br>    public static ExtentReports getReportObject() {<br>        String path = System.getProperty(&quot;user.dir&quot;)+&quot;/reports/extent-report.html&quot;;<br>        ExtentSparkReporter reporter = new ExtentSparkReporter(path);<br>        reporter.config().setReportName(&quot;Automation Tests&quot;);<br>        extent = new ExtentReports();<br>        extent.attachReporter(reporter);<br>        return extent;<br>    }<br>}</pre><pre>package reports;<br><br>import com.aventstack.extentreports.Status;<br>import org.testng.ITestContext;<br>import org.testng.ITestListener;<br>import org.testng.ITestResult;<br><br>public class Listeners extends BaseTests implements ITestListener {<br><br>    @Override<br>    public void onTestStart(ITestResult result) {<br>        test = extent.createTest(result.getMethod().getMethodName());<br>    }<br><br>    @Override<br>    public void onTestSuccess(ITestResult result) {<br>        test.log(Status.PASS, &quot;Test Passed&quot;);<br>    }<br><br>    @Override<br>    public void onTestFailure(ITestResult result) {<br>        test.fail(result.getThrowable());<br>    }<br><br>    @Override<br>    public void onFinish(ITestContext context) {<br>        extent.flush();<br>    }<br><br>}</pre><pre>package tests;<br><br>import com.aventstack.extentreports.ExtentReports;<br>import com.aventstack.extentreports.ExtentTest;<br>import org.openqa.selenium.WebDriver;<br>import org.testng.annotations.BeforeMethod;<br><br>public class BaseTests  {<br>    public ExtentReports extent = ExtentReporterNG.getReportObject();<br>    private static ExtentTest test;<br><br>    @BeforeMethod<br>    public void setUp() throws IOException {<br>        // Test set-up code<br>    }<br>}</pre><pre>package tests;<br><br>import tests.BaseTests;<br>import com.aventstack.extentreports.ExtentTest;<br>import com.aventstack.extentreports.Status;<br>import org.testng.Assert;<br>import org.testng.annotations.Test;<br>import pages.*;<br><br>public class validateTest extends BaseTests {<br><br><br>    @Test<br>    public void test1(){<br>        // code for test functionality<br>        // Assert the condition<br>  test.info(&quot;Test was validated with success&quot;);//this get printed in report<br>    }<br><br>@Test<br>    public void test2(){<br>        // code for test functionality<br>        // Assert the condition<br>  test.info(&quot;Test was validated with success&quot;);//this get printed in report<br>    }</pre><p>On running test following error message received:</p><p>j<em>ava.lang.NullPointerException: Cannot invoke “com.aventstack.extentreports.ExtentTest.info(String)” because “this.test” is null</em></p><p><strong>Explaination:</strong></p><p>The java.lang.NullPointerException indicates that the ExtentTest object (test) is not initialized when we try to log a message using test.info() in the test methods. This usually happens if the ExtentTest instance isn’t properly created or assigned before you try to use it.</p><p>Common Causes:<br>1.ExtentTest Not Initialized in BaseTests: The test object should be initialized, else test will return null.<br>2.Incorrect Reference: The test object being used in your test method may not be referencing the correct ExtentTest instance.</p><p>Solution:</p><p>In the scenario listed above, inside the BaseTests, code:private static ExtentTest test is marked as private, hence when we call the “test.info(“”)” inside the “validateTest”, it is unable to access the “extent” due to its access method which is ‘private’.</p><p><strong>Changing the access method to ‘public’, resolved this issue.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ad940078cb6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Installing React-native in Mac os]]></title>
            <link>https://medium.com/@QA-initi/installing-react-native-in-macos-3ce0faecc8f3?source=rss-d968c631bf1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ce0faecc8f3</guid>
            <dc:creator><![CDATA[QA-init]]></dc:creator>
            <pubDate>Sat, 16 Dec 2023 01:38:31 GMT</pubDate>
            <atom:updated>2023-12-18T03:56:08.299Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Today I tried installing react-native CLI and also tried the step by step instructions, however it was not a easy step as mentioned in the docs. I finally have it installed and i believe this will serve as a good guide for macos users.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-8SvMhSFz9FNNoJ3" /><figcaption>Photo by <a href="https://unsplash.com/@austindistel?utm_source=medium&amp;utm_medium=referral">Austin Distel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Ensure following is done before trying to initialize a new project:</strong></p><p><strong>Must have:</strong></p><ol><li>Xcode: This should be already available in macos system. If not then do install.</li></ol><p>2. Vs Code</p><p>3. Node version &gt;=18</p><p>4. Java</p><p>5. Env variable set to JAVA_HOME in the bash profile or .zshrc</p><p>6. Latest version of Ruby:</p><blockquote>My macos already had system default ruby version (2.6) which might be old version and it was preventing the automated installation of Cocopods since ruby version is not latest. To avoid this, i installed latest version of ruby using homebrew.</blockquote><blockquote>``brew install ruby``</blockquote><blockquote>Then set a script inside .zshrc to prevent the system available Ruby overriding the new version.</blockquote><pre>if [ -d &quot;/opt/homebrew/opt/ruby/bin&quot; ]; then<br>export PATH=/opt/homebrew/opt/ruby/bin:$PATH<br>export PATH=`gem environment gemdir`/bin:$PATH<br>fi</pre><p>Then Navigate to folder where you want to create project:</p><p><strong>Important : Open the IOS emulator first</strong> → Ensure its preference have the location of Xcode(I had only the latest version)</p><p>Then run the following command:</p><pre>npx react-native@latest init AwesomeProject</pre><p>This command will create the project and also do installation of <strong>Cocopods</strong></p><p>I did not install <strong>cocopods</strong> separately.</p><p>Open the folder in Vs Code and then ‘cd’ to the project folder.</p><p>Open the terminal and then type ‘<strong>npm start</strong>’ then press ‘<strong>i</strong>’ for ios</p><p>This will start the metro server and then will launch the IOS emulator with updated content.</p><p>Congratulations you are all set!!!</p><p>All the pain was worth knowing the installation steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SboGcz7MrGRE-FUgJ5JUwQ.png" /><figcaption>Awesome Project loaded in iOS emulator</figcaption></figure><p>Please note: I did not install Android SDK and its platform tool as i was just trying to work with ios emulator only.</p><p>References:</p><p><a href="https://reactnative.dev/docs/environment-setup?guide=native">https://reactnative.dev/docs/environment-setup?guide=native</a></p><p><a href="https://mac.install.guide/ruby/13.html">https://mac.install.guide/ruby/13.html</a></p><p><strong>Happy Reading!!!</strong></p><p>#react-native, #ios, #reactnative, #install-guide</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ce0faecc8f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reducers with useReducer Hook]]></title>
            <link>https://medium.com/@QA-initi/reducers-with-usereducer-hook-b924f9ee15a4?source=rss-d968c631bf1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b924f9ee15a4</guid>
            <dc:creator><![CDATA[QA-init]]></dc:creator>
            <pubDate>Tue, 28 Nov 2023 01:51:57 GMT</pubDate>
            <atom:updated>2023-11-28T01:51:57.956Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post we will look into example of using reducers with useReducer Hook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xKRTwu2lB_f_kuvL" /><figcaption>Photo by <a href="https://unsplash.com/@christinhumephoto?utm_source=medium&amp;utm_medium=referral">Christin Hume</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In React, reducers are functions that specify how the application’s state changes in response to dispatched actions. Typically use <strong>reducers </strong>can be used in combination with <strong>Redux </strong>or the <strong>useReducer </strong>hook in functional components to manage the state changes.</p><p>Here’s an example of how you can create a reducer in React using the useReducer hook:</p><pre>import React, { useReducer } from &#39;react&#39;;<br><br>// Reducer function<br>const reducer = (state, action) =&gt; {<br>  switch (action.type) {<br>    case &#39;INCREMENT&#39;:<br>      return { ...state, count: state.count + 1 };<br>    case &#39;DECREMENT&#39;:<br>      return { ...state, count: state.count - 1 };<br>    default:<br>      return state;<br>  }<br>};<br><br>const Counter = () =&gt; {<br>  // Initial state<br>  const initialState = { count: 0 };<br><br>  // useReducer hook to manage state with the reducer function<br>  const [state, dispatch] = useReducer(reducer, initialState);<br><br>  // Action creators<br>  const increment = () =&gt; {<br>    dispatch({ type: &#39;INCREMENT&#39; });<br>  };<br><br>  const decrement = () =&gt; {<br>    dispatch({ type: &#39;DECREMENT&#39; });<br>  };<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Counter: {state.count}&lt;/h1&gt;<br>      &lt;button onClick={increment}&gt;Increment&lt;/button&gt;<br>      &lt;button onClick={decrement}&gt;Decrement&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>};<br><br>export default Counter;</pre><p>In this example:</p><ul><li><strong>reducer </strong>is a function that takes the <strong>current state</strong> and an <strong>action </strong>as arguments and returns the new state based on the <strong>action type</strong>.</li><li><strong>useReducer </strong>hook initializes the state and returns the current state along with a <strong>dispatch </strong>function that allows you to dispatch actions to the reducer.</li><li><strong>dispatch </strong>is used to trigger state changes by passing an action object with a type property that matches a case in the <strong>reducer’s switch </strong>statement.</li><li>The Counter component renders a counter that displays the current count from the state. Clicking the buttons triggers the increment and decrement actions, updating the state based on the reducer logic.</li></ul><p>This is a basic example of how to create a reducer using the useReducer hook in React. Reducers help manage complex state changes in a predictable way by handling different actions and updating the state accordingly.</p><p>Happy Reading!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b924f9ee15a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create Global Context in React]]></title>
            <link>https://medium.com/@QA-initi/how-to-create-global-context-in-react-f02c9d91270b?source=rss-d968c631bf1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f02c9d91270b</guid>
            <dc:creator><![CDATA[QA-init]]></dc:creator>
            <pubDate>Tue, 28 Nov 2023 01:40:56 GMT</pubDate>
            <atom:updated>2025-08-28T22:54:12.027Z</atom:updated>
            <content:encoded><![CDATA[<p>This post outlines the steps and approach which can be used to create a global context in Reactjs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8XTg9btOV9ebDjZx" /><figcaption>Photo by <a href="https://unsplash.com/@nublson?utm_source=medium&amp;utm_medium=referral">Nubelson Fernandes</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In React, we can create a global context using the <strong>createContext </strong>function from the React package. Context provides a way to pass data through the component tree without having to pass props manually at every level.</p><p>Here’s a step-by-step guide to define a global context in React:<br><strong>Step 1: Create a Context</strong><br>Use the <strong>createContext </strong>function to create a new context. This function returns a Context object.</p><pre>import React from &#39;react&#39;;<br><br>const GlobalContext = React.createContext();<br>export default GlobalContext;</pre><p><strong>Step 2: Provide Data with a Provider</strong><br>Wrap your top-level component or a specific part of your component tree with the <strong>Provider </strong>component provided by the context.</p><pre>import React from &#39;react&#39;;<br>import GlobalContext from &#39;./GlobalContext&#39;;<br><br>const App = () =&gt; {<br>  // Define the data you want to share globally<br>  const globalData = {<br>    user: {<br>      name: &#39;John Doe&#39;,<br>      email: &#39;john@example.com&#39;,<br>    },<br>    settings: {<br>      theme: &#39;dark&#39;,<br>      language: &#39;en&#39;,<br>    },<br>    // ...other global data<br>  };<br><br>  return (<br>    &lt;GlobalContext.Provider value={globalData}&gt;<br>      {/* Your app components */}<br>    &lt;/GlobalContext.Provider&gt;<br>  );<br>};<br><br>export default App;</pre><p><strong>Step 3: Consume the Context</strong><br>Any component that wants to access the global data can consume the context using the <strong>useContext </strong>hook or by wrapping the component with Consumer.</p><p>Using useContext hook:<br>*********************</p><pre>import React, { useContext } from &#39;react&#39;;<br>import GlobalContext from &#39;./GlobalContext&#39;;<br><br>const SomeComponent = () =&gt; {<br>  const globalData = useContext(GlobalContext);<br><br>  // Access global data<br>  console.log(globalData.user.name);<br><br>  return (<br>    // Component JSX<br>  );<br>};<br><br>export default SomeComponent;</pre><p>Using Consumer: (Used for class components)<br>***************</p><pre>import React from &#39;react&#39;;<br>import GlobalContext from &#39;./GlobalContext&#39;;<br><br>const AnotherComponent = () =&gt; {<br>  return (<br>    &lt;GlobalContext.Consumer&gt;<br>      {(globalData) =&gt; (<br>        // Access global data<br>        &lt;div&gt;{globalData.user.name}&lt;/div&gt;<br>      )}<br>    &lt;/GlobalContext.Consumer&gt;<br>  );<br>};<br><br>export default AnotherComponent;</pre><p>Above syntax is used for class components and is alternate way to use the context in the target component.</p><p>By following these steps, we can define a global context in React to share data across components without the need for <strong>prop drilling</strong>, making it easier to manage and access shared state or data in the application.</p><p>Thanks for reading!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f02c9d91270b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React useEffect Example]]></title>
            <link>https://medium.com/@QA-initi/react-useeffect-example-5a0f014c1985?source=rss-d968c631bf1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a0f014c1985</guid>
            <dc:creator><![CDATA[QA-init]]></dc:creator>
            <pubDate>Thu, 16 Nov 2023 05:26:05 GMT</pubDate>
            <atom:updated>2023-11-16T05:26:05.197Z</atom:updated>
            <content:encoded><![CDATA[<p><em>In this post we will understand the role of useEffect in the provided code and comprehend its role in fetching and rendering the data</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*isEVX9Jp20S_x_Wo" /><figcaption>Photo by <a href="https://unsplash.com/@blakeconnally?utm_source=medium&amp;utm_medium=referral">Blake Connally</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>We will look into the following example code:</p><pre>import { useState, useEffect } from &#39;react&#39;;<br><br>const url = &#39;https://api.github.com/users&#39;;<br><br>const FetchData = () =&gt; {<br>  const [users, setUsers] = useState([]);<br><br>  useEffect(()=&gt;{<br>    const fetchData =async()=&gt;{<br>      try{<br>      const response = await fetch(url)<br>      const data = await response.json();<br>      setUsers(data)<br>    }catch(error){<br>      console.log(error)<br>    }<br>  }<br>  fetchData();<br>}<br>  ,[])<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h3&gt;Github users&lt;/h3&gt;<br>      {users.map((user)=&gt;{<br>        const {id, login,avatar_url,url} = user;<br>        return (<br>          &lt;div key={id}&gt;<br>            &lt;img src={avatar_url} alt={login} /&gt;<br>            &lt;h4&gt;{login}&lt;/h4&gt;<br>            &lt;a href={url}&gt;profile&lt;/a&gt;<br>          &lt;/div&gt;<br>        )<br>      })}<br>    &lt;/div&gt;<br>  )<br>};<br>export default FetchData;</pre><p>In React, useEffect is a hook that allows us to perform <strong>side-effects</strong> in functional components. <strong>Side-effects</strong> can include data fetching, subscriptions, or manually changing the DOM.</p><p>In this code, the useEffect hook is used to fetch data from the GitHub API when the component mounts. Let&#39;s break down the code:</p><ol><li>useEffect is called with a callback function and a dependency array ([]). In this case the dependency array is empty, indicating that the effect will only run once, when the component mounts and not re-run on subsequent updates.</li><li>Inside the useEffect callback, an async function fetchData is defined. This function performs an asynchronous operation using fetch to make a GET request to the GitHub API (&#39;https://api.github.com/users&#39;).</li><li>Upon receiving the response from the API, it is parsed as JSON using response.json(), and the resulting data is stored in the data variable.</li><li>The setUsers(data) function is called to update the users state with the fetched data.</li><li>The users state is then mapped in the JSX to render a list of GitHub users. For each user, their avatar image, username (login), and a link to their GitHub profile (url) are displayed.</li></ol><p>Regarding the useEffect hook:</p><ul><li>When you provide an empty dependency array ([]) as the second argument to useEffect, it signifies that the effect should only run once after the initial render, mimicking the behavior of componentDidMount in class-based components.</li><li>By fetching data inside useEffect, you ensure that data fetching happens after the component is mounted, preventing any potential issues with fetching during the initial render, which might cause unnecessary re-renders.</li></ul><p>This pattern helps in managing side effects and performing actions related to component lifecycle events in functional components.</p><p>That’s all in this post. Happy reading!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a0f014c1985" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>