DevIdiot!
Switching classes on button press is just state
The first dark mode toggle I built in React, I built the way I had built them in plain JavaScript for years. I grabbed the document body and called classList.toggle('dark') on it, and it worked. Click, dark. Click again, light. It shipped, and then a user reported the toggle losing its setting. They would switch to dark, click anything that re-rendered the page, and the page snapped back to light while the button still said dark. The class and the state had disagreed, and the class lost, because
State lives in the parent, the child just asks
The SeatFinder check-in button lives in the guest row. It is a small thing, one button per guest, and the checked-in state looks like it belongs right there next to it, inside the row component. Put it there and the button works, it flips to Checked in on tap, while the header count says 0 of 80 where it should say 3 of 80. The row knew. The parent had no idea. (The row knew, the parent had no idea, and that gap was the bug.)The tempting next move is worse: change the prop directly from the chil
Building a reusable read more toggle button
A bio on a wedding site, a long review on a poster page, a description on a dashboard card. Three places, one pattern: a boolean, a button, a slice of text. Each copy had drifted a little, different truncation lengths, different labels, one missing the collapse state entirely. That is the shape of a component that should exist once. When the same behavior shows up in three places, the question is not how to write it a fourth time, it is where it lives.The fix is one component with a clear contra
What is useCallback?
useCallback is a React Hook that lets you cache (memoize) a function definition between re-renders. Instead of creating a brand-new function on every render, React returns the exact same function instance from memory unless one of its dependencies changes.import { useCallback } from 'react';const cachedFn = useCallback(() => { // Your function logic here}, [dependencies]);• fn (First Argument): The function you want to cache.• dependencies (Second Argument): An array of reactive values (prop
Which component rendered this div? A build plugin that answers in one click
Add data-source="path:line" to every JSX element in development, for Vite, Next.js and Babel. Zero runtime, works in any DevTools, and great with AI coding agents.It's your first day on a new project. You don't know the codebase at all, and your first task is to fix a button on the checkout page. You open DevTools, click the button and see this:<button class="MuiButtonBase-root MuiButton-root css-1x2y3z4">Now find it in the code. You search for the class name: it's generated. You sea
TypeScript Email Adapters Need a Failure Contract
Email verification code often starts with one promise: sendVerificationEmail(email). That shape is convenient, but it hides the decisions an application actually needs to make.Did the provider accept the request? Was the message delayed? Did a retry create a second token? Is the address invalid, or is the inbox simply not ready yet? When every outcome becomes either true or an exception, a React form has to guess. Those guesses turn into confusing spinners, duplicate requests, and tests that pas
React Hooks: useEffect vs useCallback vs useMemo
When learning React, I came across three important hooks: useEffect, useCallback, and useMemo.At first, I found them confusing because they all use dependency arrays.But after understanding their purpose, I realized that each hook solves a different problem.Let's understand them with simple examples. 1. What is useEffect?useEffect is used to perform an action after a component renders.For example, when we want to update the browser tab title whenever a counter changes.import { useState, use
What Runs First in a Next.js Page: Server Components, Render, Effects
A child component's useEffect reads something its parent's effect was supposed to set up. It's undefined. You add a console.log to both and find the child's effect ran first, even though the parent rendered first.Nothing is broken. That's the order React promises. The mental model: down, then back upThe server goes first, the browser second. Inside the browser, render walks down the tree, parent before child. Effects walk back up, child before parent. The screen updates in between.Picture n
You Don't Need That useEffect: Derived State in React
A search box over a list. It works, and it shows up in code review every week:function Results({ items, query }) { const [filtered, setFiltered] = useState(items); useEffect(() => { setFiltered(items.filter((item) => item.name.includes(query))); }, [items, query]); return <List items={filtered} />;}Type a letter and the list updates. Nothing looks broken. But every keystroke renders Results twice, and the first render shows the old list. The mental model: a copy that runs
Reading Shopify's pricing page in DevTools: the trial length is a template variable
By Alexandr M., Ecom Store ProEvery few weeks someone in a Shopify forum asks whether the "$1 a month for 6 months" deal is still running. The answers usually quote a banner or a screenshot. This post goes another way: it opens Shopify's public pricing page in DevTools and reads what the page itself ships.The short version is that the number of promotional months is a slot in a message template, and it sits next to the vocabulary of a bandit test. That matters if you write about SaaS pricing, bu
Build a Crypto Price Tracker App with JavaScript
Crypto prices move fast, and checking them means opening an exchange app every time. A small price tracker that pulls live prices from a free public API and shows them in a clean list is a perfect weekend project — and it teaches you fetching, rendering, and auto-refresh in one go.We use the free CoinGecko API, which needs no API key for basic price data:const coins = ['bitcoin', 'ethereum', 'solana', 'dogecoin'];async function loadPrices() { const ids = coins.join(','); const url = `https://a
Build a Countdown Timer App with JavaScript
A countdown timer is one of those small tools you end up using constantly: counting down to a product launch, an exam, a birthday, or a sale ending. In this post, we build one with plain JavaScript that takes a target date and shows days, hours, minutes, and seconds, updating every second.The HTML is a date input and four boxes for the numbers:<input type="datetime-local" id="target-date" /><button id="start-btn">Start countdown</button><div id="countdown"> <div>&l
Build a Savings Goal Tracker App with JavaScript
Saving money is easier when you can see the goal. A savings goal tracker lets you set a target — a new phone, a trip, an emergency fund — and watch a progress bar fill up as you add money. In this post, we build one with plain JavaScript and localStorage, so your goals survive a page refresh.The HTML is simple: a form to add a goal, and a list that shows each goal with a progress bar.<form id="goal-form"> <input id="goal-name" placeholder="Goal name (e.g. New laptop)" required /> &
React or Next.js Site Not Indexed by Google? Here's the Fix
Your React app looks perfect in the browser. Google sees an empty page.No rankings, no traffic, and Search Console just says "Crawled, currently not indexed" without telling you why.Here's how to see exactly what Google sees in 2 minutes, find the real cause and fix it with code tested on Next.js 16.4. Why is Google not indexing my React or Next.js site?Almost always, it's one of three problems:Rendering: your content only appears after JavaScript runs.Discovery: Google can't find your URLs
Stripe for Beginners: Accept Payments in Your Web App
Taking payments sounds intimidating — cards, security, compliance, refunds — but Stripe handles the hard parts. You never touch the card number: Stripe's checkout or card form collects it securely, and you work only with tokens and payment IDs.The simplest integration is Stripe Checkout. Your server creates a checkout session, and Stripe hosts the whole payment page:import Stripe from 'stripe';const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);const session = await stripe.checkout.sessions
Nodemailer for Beginners: Send Emails from Node.js
Almost every web app needs to send email: password resets, welcome messages, order confirmations, OTPs. Nodemailer is the standard Node.js library for sending mail, and it works with almost any email service — Gmail, SendGrid, Amazon SES, or your own SMTP server.Here is a complete example with Gmail:import nodemailer from 'nodemailer';const transporter = nodemailer.createTransport({ service: 'gmail', auth: { user: '[email protected]', pass: 'your-app-password', },});const info = await tra
Day.js for Beginners: Tiny Dates Without Moment.js
JavaScript's built-in Date is awkward, and Moment.js — the old answer — is now too large for modern apps at nearly 300 KB. Day.js is a 2 KB alternative with the same friendly API, and for most apps it does everything you need.Installation is one package, and the API will feel familiar if you have used Moment:import dayjs from 'dayjs';const now = dayjs();console.log(now.format('DD MMM YYYY, hh:mm A')); // 21 Nov 2026, 07:59 PMconst nextWeek = dayjs().add(7, 'day');console.log(nextWeek.format('ddd
styled-components for Beginners: CSS in JavaScript That Scales
In a big React app, CSS files grow messy. Class names collide, dead styles pile up, and changing one component's style breaks another. styled-components solves this by letting you write CSS inside your JavaScript, scoped to a single component.You define a styled element with a template literal:import styled from 'styled-components';const Card = styled.div` background: white; border: 1px solid #e5e7eb; border-radius: 12px; padding: 24px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);`;const Titl
MUI for Beginners: Material Design Components in React
Starting a React app from scratch means building every button, input, dialog, and table yourself — and making them all look consistent. MUI (formerly Material-UI) is a component library that gives you all of those pieces, styled with Google's Material Design, ready to drop into your app.Getting started is quick. Install the packages, wrap your app in a theme provider, and use the components:import { Button, TextField, Card, CardContent, Typography } from '@mui/material';function LoginCard() { r
Headless UI for Beginners: Accessible Components Without the Styling
Building a dropdown or a modal sounds simple until you try to do it properly. Keyboard navigation, focus trapping, screen reader announcements, closing on Escape — accessibility is a long checklist. Headless UI, from the Tailwind CSS team, gives you fully accessible components with zero styling, so you can make them look however you want.Here is a dropdown menu:import { Menu } from '@headlessui/react';function UserMenu() { return ( <Menu> <Menu.Button className="px-4 py-2 bg-bl