bug: React error #31 rendering project tags on item detail #33

Closed
opened 2026-02-08 21:09:15 +00:00 by forbes · 0 comments
Owner

Bug

Opening an item detail throws React error #31: "Objects are not valid as a React child (found: object with keys {id, code, name, created_at})."

Root Cause

MainTab.tsx line 30 fetches item projects typed as string[]:

get<string[]>(`/api/items/${encodeURIComponent(item.part_number)}/projects`)
  .then(setItemProjects)

But HandleGetItemProjects (handlers.go:1576) returns []ProjectResponse — an array of objects with keys {id, code, name, description, created_at}, not strings.

When line 95 renders {code} inside JSX, code is the full project object, not a string:

{itemProjects.map((code) => (
  <span key={code} style={...}>
    {code}   // ← object, not string → React error #31
  </span>
))}

Fix

Change the frontend to match the actual API response:

  1. Type the fetch as get<{id: string, code: string, name: string, created_at: string}[]>
  2. Render {project.code} instead of {code}
  3. Update the project-add filter (.filter((p) => !itemProjects.includes(p.code))) to compare correctly
## Bug Opening an item detail throws React error #31: "Objects are not valid as a React child (found: object with keys {id, code, name, created_at})." ## Root Cause `MainTab.tsx` line 30 fetches item projects typed as `string[]`: ```typescript get<string[]>(`/api/items/${encodeURIComponent(item.part_number)}/projects`) .then(setItemProjects) ``` But `HandleGetItemProjects` (handlers.go:1576) returns `[]ProjectResponse` — an array of objects with keys `{id, code, name, description, created_at}`, not strings. When line 95 renders `{code}` inside JSX, `code` is the full project object, not a string: ```tsx {itemProjects.map((code) => ( <span key={code} style={...}> {code} // ← object, not string → React error #31 </span> ))} ``` ## Fix Change the frontend to match the actual API response: 1. Type the fetch as `get<{id: string, code: string, name: string, created_at: string}[]>` 2. Render `{project.code}` instead of `{code}` 3. Update the project-add filter (`.filter((p) => !itemProjects.includes(p.code))`) to compare correctly
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kindred/silo#33