React HooksMedium
What is useReducer and when should you use it over useState?
useReducer is an alternative to useState that is deeply inspired by Redux. It is designed for managing complex state objects or state logic that involves multiple sub-values or interconnected…
import React, { useReducer } from 'react'; // 1. Define initial stateconst initialState = { data: [], loading: false, error: null};
Next.jsEasy
What is Next.js and how does it differ from React?
React is a UI library for building components; Next.js is a full-stack React framework that adds routing, server rendering, data fetching, caching, bundling and deployment conventions on top of…
// app/page.tsx - a Server Component by default (no "use client")import { db } from "@/lib/db";import LikeButton from "./like-button"; export default async function Home() { // Runs only on the server: safe to query the database directly const posts = await db.post.findMany({ take: 5 });
JavaScriptEasy
What is a callback function?
A callback is a function you pass to another function so it can be called later, either right away (synchronous callbacks like map) or when something finishes (asynchronous callbacks like timers and…
// Synchronous callback: called immediately by mapconst prices = [10, 20, 30];const withTax = prices.map((p) => p * 1.2);console.log(withTax); // [12, 24, 36] // Asynchronous, error-first callback (Node style)function loadUser(id, callback) { setTimeout(() => {
ReactEasy
What is JSX?
JSX is a syntax extension for JavaScript that lets you write HTML-like markup inside JavaScript. A compiler (Babel, SWC, Oxc or esbuild) turns it into function calls that create React elements, so…
// JSX with expressions, conditionals, lists and attributestype Product = { id: string; name: string; price: number; inStock: boolean }; export function ProductList({ products, currency = "USD" }: { products: Product[]; currency?: string }) { const fmt = new Intl.NumberFormat("en-US", { style: "currency", currency }); return ( <>