Skip to main content

🧱 Part 1 — Kickoff & Project Setup (Beginner Friendly 🚀)

Welcome to the very first step of our React + TypeScript journey! 🎉 By the end of this part, you’ll have a working React app, understand what each tool does, and even create your first typed component and custom hook. Let’s make sure we understand every little detail together.


✨ Why React + TypeScript?

  • React → lets you build UI with reusable components.
  • TypeScript → makes your code safe and predictable by adding types.
  • Together → you get the best of both worlds: fast development + fewer bugs.

Think of React as the engine of your car and TypeScript as the safety system (seatbelts, airbags, sensors). You can drive without them, but why take the risk? 😉


⚡ Step 1: Create a New Project with Vite

Vite is a modern, super-fast build tool that sets up your React app in seconds.

Run these commands:

# Create a new app using Vite’s React + TS template
pnpm create vite@latest tasktimer --template react-ts

# Move into the folder
cd tasktimer

# Install dependencies
pnpm install

# Start the app
pnpm dev

👉 Open http://localhost:5173 — you should see a starter page. That’s your first React + TS app running!


🔍 Step 2: Understanding TypeScript in One Minute

TypeScript = JavaScript + Types.

let count: number = 5;  // ✅ count must be a number
count = "hello";        // ❌ Error: Type 'string' is not assignable to type 'number'

Types prevent silly mistakes before your code even runs. This means fewer bugs and more confidence.


🗂 Step 3: Organize Your Project

Here’s a clean folder structure we’ll use:

src/
  app/         # app-level setup (providers, store, router)
  components/  # reusable UI components (Button, Header, Modal)
  features/    # feature-specific code (tasks, timer)
  hooks/       # custom hooks
  lib/         # utilities (api, storage)
  styles/      # global CSS or Tailwind
  types/       # shared TypeScript types

👉 Why this matters: As apps grow, this prevents “spaghetti code.”


🛡 Step 4: Make TypeScript Strict

Open tsconfig.json and ensure strict checks:

{
  "compilerOptions": {
    "strict": true,
    "noImplicitReturns": true,
    "exactOptionalPropertyTypes": true,
    "noUncheckedIndexedAccess": true
  }
}
  • strict → strongest safety net.
  • noImplicitReturns → all functions must return something.
  • exactOptionalPropertyTypes → optional fields are handled carefully.
  • noUncheckedIndexedAccess → safer array access.

🎨 Step 5: Add ESLint + Prettier

  • ESLint → finds bugs and enforces coding rules.
  • Prettier → formats code consistently.

Install:

pnpm add -D eslint prettier @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-react eslint-plugin-react-hooks eslint-config-prettier

👉 Together, they keep your code clean and consistent.


🧩 Step 6: Build Your First Component

// src/components/Header.tsx
import type { ReactNode } from 'react';

export type HeaderProps = {
  title: string;
  rightSlot?: ReactNode; // optional extra content
};

export function Header({ title, rightSlot }: HeaderProps) {
  return (
    <header style={{ padding: 16, borderBottom: '1px solid #ddd' }}>
      <h1>{title}</h1>
      {rightSlot}
    </header>
  );
}

👉 You just wrote your first typed React component!

Usage:

// src/app/App.tsx
import { Header } from '@/components/Header';

export default function App() {
  return <Header title="TaskTimer" rightSlot={<button>Login</button>} />;
}

🌀 Step 7: Your First Custom Hook

Hooks let us reuse logic easily.

// src/hooks/useToggle.ts
import { useState } from 'react';

export function useToggle(initial = false) {
  const [value, setValue] = useState(initial);
  const toggle = () => setValue((v) => !v);
  return { value, toggle };
}

Usage:

import { useToggle } from '@/hooks/useToggle';

export function Demo() {
  const { value, toggle } = useToggle();
  return <button onClick={toggle}>{value ? 'ON' : 'OFF'}</button>;
}

👉 Congrats, you built your first custom hook! 🎉


📦 Step 8: Install Useful Libraries (Upfront)

Let’s install libraries we’ll need throughout the series:

pnpm add axios @reduxjs/toolkit react-redux @tanstack/react-query react-hook-form zod clsx dayjs react-icons
pnpm add -D @types/react-redux
  • axios → API requests
  • redux-toolkit + react-redux → global state
  • react-query → server state
  • react-hook-form + zod → forms + validation
  • clsx → conditional class names
  • dayjs → date/time utilities
  • react-icons → ready-to-use icons

✅ Wrap-Up

In this first part, we:

  • Learned what React, TypeScript, and Vite are.
  • Created a fresh project.
  • Organized folders for scalability.
  • Set TypeScript to strict mode.
  • Added ESLint + Prettier.
  • Built our first typed component and first custom hook.
  • Installed essential libraries upfront.

👉 Next: We’ll dive into TypeScript fundamentals for React (props, events, refs, unions, and more) and apply them to our TaskTimer app.

Comments

Popular posts from this blog

🌟 Dot net Microservices interview questions

Here is a comprehensive list of 200 .NET microservices coding questions covering all core microservices concepts and cross-cutting concerns relevant for designing, building, deploying, and maintaining .NET-based distributed systems. 🧩 A. Microservices Fundamentals (20) Build a microservice in .NET 8 that exposes a simple CRUD API. Implement communication between two microservices using REST. How would you design microservices for an e-commerce application? Create a microservice that handles user registration and login. How do you isolate domain logic in a microservice? How to apply the "Single Responsibility Principle" in microservices? Design a service registry/discovery mechanism using custom middleware. Implement a service that handles file uploads and metadata separately. Build a stateless microservice and explain its benefits. Implement health check endpoints in .NET 8. Demonstrate versioning in a microservice API. Add Swagger/OpenAPI support to your m...

⚡ Part 1: Introduction to Generics in C#

🌍 Why Do We Need Generics? Imagine you want to create a stack (like a pile of books 📚): You can push items on top You can pop items off the top If we write a stack for integers : public class IntStack { private int[] items = new int[10]; private int index = 0; public void Push(int item) => items[index++] = item; public int Pop() => items[--index]; } 👉 Problem: This only works for int . What if we want a string stack ? Or a Customer stack ? We’d have to duplicate code for every type. 😢 ✅ Solution: Generics Generics let us create type-safe reusable code without duplication. We can say: “I don’t care what type it is yet — I’ll decide later.” 1) Generic Classes Here’s a generic stack : // Generic class "Stack<T>" // The <T> is a placeholder for any type public class Stack<T> { private T[] items = new T[10]; // Array of type T private int index = 0; // Push adds an item of type T public void P...

🚪 Part 9: API Gateway for .NET 8 Microservices (Ocelot & YARP)

Once you have multiple microservices (Products, Orders, Payments…), exposing each one directly to clients gets messy: Different base URLs Duplicated auth logic No unified rate limiting / caching Hard to evolve routes or aggregate data 👉 Enter the API Gateway — your single front door for all microservices. An API Gateway handles: ✅ Routing & path rewriting ✅ Load balancing, retries, circuit breakers ✅ Authentication & Authorization (JWT, OAuth2) ✅ Rate limiting & caching ✅ Aggregation (compose results from multiple services) In this post we’ll implement two strong options: Ocelot → config-driven, mature, DevOps-friendly YARP (Yet Another Reverse Proxy) → Microsoft’s code-first, extensible gateway ⚖️ Ocelot vs YARP — When to Choose Ocelot → JSON config, minimal C#, built-in QoS (rate limit, circuit breaker). Perfect for teams that like DevOps config-as-code. YARP → full C# control, middleware-friendly, can embed into broader apps (e.g. add dashb...