Short answer
Find what is undefined: the name after of in the message. For a function parameter the message names 'undefined' itself, so look at the call site. If it is a function parameter, the function was called without that argument: give it a default, function f({ a } = {}). If it is data from an API, a hook or a database, it has not loaded or the field is missing: check it first, or use const { a } = value ?? {}. Note that a default value does not apply when the value is null, only when it is undefined.
Why there is nothing to destructure, and the fix
01
A function called without its object argument
“Same as accessing properties, destructuring null or undefined throws a TypeError.” MDN, Destructuring
A function that destructures its parameter fails when someone calls it with no argument, or with undefined. Give the parameter an empty object as its default.
function createUser({ name, role = 'member' } = {}) { return { name, role }; } createUser(); // no error02
Data that has not loaded or is missing
The first render before a fetch finishes, an API response without the expected field, or a hook or context used outside its provider all give undefined. Handle the empty state before destructuring.
const json = await res.json(); const { user } = json; if (!user) throw new Error('Response has no user'); const { id, email } = user;03
null, where defaults do not help
“It is not used if the property has value null.” MDN, Destructuring: default value
Databases and APIs often return null for a missing record. A default in the pattern only covers undefined, so null still throws. Use ?? to swap null for an object.
const { name } = (await findUser(id)) ?? {};04
React props and hooks
A component destructuring a prop object that a parent did not pass, or useContext() returning undefined outside the provider (when createContext was given no default), fails the same way. Pass the prop, give it a default, or check that the provider wraps the tree.
function Profile({ user = {} }) { const { name = 'Guest' } = user; return <p>{name}</p>; }
Checked against the vendor’s docs on : MDN: Destructuring.
Rather hand it over?
Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
- from $450AI-Built App RescueA Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.See scope and start
Related: “Cannot read properties of undefined” · React “Invalid hook call” · JavaScript “Invalid Date”