React Diagnostic

How to Fix "TypeError: Cannot read properties of undefined (reading 'map')"

Triggered when calling .map() on a variable that is undefined or null (frequently an uninitialized async API response state in React components).

TypeError: Cannot read properties of undefined (reading 'map')

Quick Fix Checklist

  1. Initialize array state with empty array: useState<Item[]>([])
  2. Use optional chaining with fallback: items?.map(...) || null
  3. Add loading state guard: if (isLoading) return <Spinner />