The independent file on technology, travel & lifeFrom Pakistan, for everywhere
Huzi Blogs.
The ArchiveSectionsSearch

Planning a trip? HTG Travels — flights, visas, hotels & Umrah, handled properly.

WhatsApp +92 317 5054959
Huzi Blogs.

An independent file on technology, travel and life — long-form guides written plainly, from Pakistan, for everywhere.

ShopMeet the Creator

Sections

  • Travel
  • Technology
  • Lifestyle
  • Programming
  • Sports
  • Linux
  • All sections

The Desk

  • The Archive
  • Search the file
  • Disclaimer & Data Privacy Policy
  • A project of huzi.pk

© 2026 blogs.huzi.pk — All rights reserved.

Set in Playfair Display & Inter

    HomeProgrammingStory
    Programming

    A Beginner's Guide to React Hooks: Mastering Modern React (2026)

    H

    By Huzi

    File #10 · 4 min read

    Hooks turned React from a class-component puzzle into plain functions. They arrived with version 16.8 in 2019, and everything the React team has shipped since — Server Components, Actions, the use() reader — assumes you write functions, not classes. If you are learning React in 2026, this is the layer to get right.

    The quick answer: useState gives a function component memory, useEffect synchronizes it with the outside world, and the rules never change — top level only, from use-named code only. Master that pair first; reach for the rest only when a profiler shows a real problem.

    useState: a component's memory

    useState lets a function component remember between renders:

    import { useState } from "react";
    
    export function Counter() {
      const [count, setCount] = useState(0);
      return <button onClick={() => setCount((c) => c + 1)}>Clicked {count} times</button>;
    }
    

    Make the functional updater your default habit — setCount((c) => c + 1), not setCount(count + 1). Strict Mode double-invokes updaters in development on purpose, to surface stale-state bugs before your users find them for you.

    useEffect: synchronizing with the world

    Effects are for reaching outside React: fetching, subscriptions, timers. The dependency array is the contract — empty means run once on mount, [id] means re-run when id changes. Whatever you start, you must be able to cancel:

    useEffect(() => {
      const controller = new AbortController();
      fetch(`/api/user/${id}`, { signal: controller.signal })
        .then((r) => r.json())
        .then(setUser)
        .catch((e) => {
          if (e.name !== "AbortError") console.error(e);
        });
      return () => controller.abort();
    }, [id]);
    

    A dependency array is really a packing list: everything the outcome depends on, declared up front. HTG Travel builds itineraries the same way — every flight, transfer and visa dependency listed before departure, so nothing re-runs by surprise mid-trip.

    The supporting cast

    Every other built-in solves one narrow problem:

    Hook The job
    useMemo Caches an expensive computation until its dependencies change
    useCallback Keeps a function reference stable so memoized children skip needless re-renders
    useRef Holds a DOM node or a mutable value across renders without triggering one
    useContext Reads theme or auth state without prop drilling
    use() React 19's reader — even reads context inside a condition

    Reach for the memo hooks when a profiler shows a real problem — the React Compiler now auto-memoizes much of what we used to write by hand.

    New hooks, old rules

    React 19 added form-first hooks. useActionState tracks pending state for submissions without a state library:

    const [state, formAction, isPending] = useActionState(submitForm, null);
    

    Pair it with useOptimistic to show the result immediately and reconcile when the server answers.

    The release line keeps moving under these hooks — React 19.2 landed in October 2025 and 19.3 in September 2026 — but the hooks layer itself has not changed shape: what you learn here stays valid across the whole 19.x series.

    The rules underneath never changed: call hooks only at the top level of a component — never inside loops or conditions — and only from components or other hooks, the ones whose names start with use. React tracks call order; break it and everything unravels.

    Extract your own

    When logic repeats across components, pull it into a custom hook and name it:

    const { data, loading, error } = useFetch("/api/user/42");
    

    That one line is where maintainable React apps live.

    Pro tip: Most data fetching now belongs in Server Components or a framework like Next.js — the server-actions guide shows exactly where the form hooks pay off. Keep effects for genuine synchronization with external systems — sockets, browser APIs, third-party widgets.

    In Gaza, developers keep committing code through power cuts and connectivity blackouts — persistence that makes a double-render in Strict Mode feel very small. And in Sudan, engineers kept the country's networks alive through bombardment — the same stubbornness, a harder war.

    Most of this guide was written between bookings at our counter — HTG Travel, a Sialkot desk that files Umrah visas and northern tours all week and refactors paragraphs when the queue is short. Bring a stubborn bug or a travel plan; both get the same chai here. Trip questions go straight to +92 317 5054959.

    Presented by

    HTG Travels — Plan the Trip, Skip the Runaround

    Flights, visas, Umrah packages and Hunza–Skardu tours, handled end to end from our licensed Sialkot desk. Real fares, hotel names in writing, and a human who answers — before you pay a rupee.

    Flights & rebooking Visa files Umrah 2026–27 Northern tours
    Visit huzi.pkWhatsApp +92 317 5054959

    Sialkot, Pakistan · Licensed agency · Fast quotes on WhatsApp


    You Might Also Like

    Heavy Handwork Embroidered Chiffon Suit (Bottle Green) | Wedding Wear

    Heavy Handwork Embroidered Chiffon Suit (Bottle Green) | Wedding Wear

    PKR 5750

    Elegant Embroidered Lawn 2-Piece Suit | Unstitched Shirt & Plain Trouser for Pakistani Ladies

    Elegant Embroidered Lawn 2-Piece Suit | Unstitched Shirt & Plain Trouser for Pakistani Ladies

    PKR 2900

    Trendy All-Over Digital Print Lawn 3-Pc Suit with Matching Lawn Dupatta (Casual)

    Trendy All-Over Digital Print Lawn 3-Pc Suit with Matching Lawn Dupatta (Casual)

    PKR 4250

    Heavy Embroidered Formal Chiffon Suit | Silk Gharara Trouser

    Heavy Embroidered Formal Chiffon Suit | Silk Gharara Trouser

    PKR 7550

    Luxury Heavy Schiffli Embroidered Lawn Suit 3-Pc | Digital Print Silk Dupatta

    Luxury Heavy Schiffli Embroidered Lawn Suit 3-Pc | Digital Print Silk Dupatta

    PKR 6550

    Keep reading

    Related files

    Programming
    English

    The Beginner's Guide to React: Building the Modern Web (2026)

    The component mental model, one-way props, the server/client split that defines modern React, and the scaffolding commands to start a real project today.

    By HuziFile #52

    Read
    Programming
    English

    Demystifying REST APIs: A Beginner's Guide (2026)

    Resources with URLs, HTTP verbs as actions, status codes as the contract, and where REST sits next to GraphQL and gRPC in a 2026 backend.

    By HuziFile #121

    Read
    Programming
    English

    Mastering Modern Layouts: A Deep Dive into CSS Flexbox and Grid (2026)

    Flexbox distributes along one axis, Grid draws two dimensions, Subgrid aligns card contents, and one auto-fit line builds responsive grids with no media queries at all.

    By HuziFile #111

    Read
    Programming
    English

    The Ultimate Beginner's Guide to Building a Website with Cloudflare Pages (2026)

    From an empty folder to a live site: git push, connect the repo in the dashboard, Pages Functions with D1 bindings, and the two fixes every beginner eventually needs.

    By HuziFile #99

    Read
    Programming
    English

    The Modern Craftsman: Essential Guide to C++ (2026)

    What modern actually means now: std::print and structured bindings, smart pointers for ownership, ranges pipelines, concepts, and std::expected error handling in C++23.

    By HuziFile #89

    Read
    Programming
    English

    Web Development: Essential Strategies for Modern Websites (2026)

    Frontend and backend split, a tool-by-tool delivery lifecycle, Core Web Vitals budgets, security non-negotiables, and the AI-assisted stack that defines 2026 web work.

    By HuziFile #459

    Read
    Back to the archive