Arhum Butt’s Post

After building a personal journal app with React 18, Tailwind CSS, and a Node/Express backend, I ran it through a full code audit. The result was a masterclass in the gaps between "it works" and "it's production-ready." Here's what came up: BUG FIXES → apiFetch was crashing on non-JSON error responses (502/504 HTML pages). Added a try/catch around res.json() with a readable fallback message. → The date formatter was silently producing "Invalid Date" for null/undefined values. Now returns '—'. → Math.random() IDs were used throughout. Swapped to crypto.randomUUID() for collision-safe IDs. → A useEffect in Toast was missing onDone in its dependency array — a subtle stale closure bug. → API responses were trusted to always be arrays. They're not. Array.isArray() guards added everywhere. ERROR HANDLING → Every save/delete was fire-and-forget. Wrapped in try/catch with inline user-visible errors. → Deletes had no confirmation dialog. One misclick = permanent data loss. → If the initial data load failed, the app rendered silently empty. Now shows a proper error screen. → Added a cancelled flag in useEffect to prevent state updates on unmounted components. CODE QUALITY → Extracted a useJournalData() custom hook to keep App lean. → Created reusable <FormError /> and <SaveButton /> components — the same pattern was copy-pasted 4 times. → BLANK_ENTRY/POST/PLACE were constants sharing a reference. Made them factory functions so each form gets a fresh object. → Replaced repeated new Date().toISOString().slice(0,10) with a todayISO() helper. PERFORMANCE → Filtered and sorted lists were recalculated on every render. Wrapped in useMemo. → Event callbacks recreated on every render. Wrapped in useCallback. ACCESSIBILITY → Clickable cards had no keyboard support. Added role="button", tabIndex, and onKeyDown Enter handlers. → Inputs were missing htmlFor/id associations and autoComplete attributes. → Decorative emoji lacked aria-hidden="true". The app "worked" before. Now it's resilient. The gap between working code and production code isn't about features — it's about what happens when things go wrong. Github repo : https://lnkd.in/dPz6Wqp7 #React #WebDevelopment #CodeQuality #JavaScript #FrontendDevelopment

To view or add a comment, sign in

Explore content categories