Explain this error: TypeError: Cannot read properties of undefined (reading "map")

That error means you're calling .map() on something that is undefined, usually because the data hasn't loaded yet.

The usual fix is to give the value a safe default:

tsx
const { data } = useQuery(['orders'], fetchOrders)

// data is undefined on the first render
const rows = (data ?? []).map((order) => (
  <Row key={order.id} order={order} />
))

If the array lives deeper in an object, use optional chaining: data?.items?.map(...).

Worth checking too:

  • Does the API return { items: [] } rather than a bare array?
  • Is the state initialised as useState([]) and not useState()?

Parley can make mistakes. Check important information.