wispy-yellowW
Refine2y ago
12 replies
wispy-yellow

How to handle an API that returns data nested in objects?

For example, in the documentation the shape of the categories enddoint is an array of category objects. What if that array is nested inside an object in the response? For example:
{
  "categories": [
    {
    "id": 2,
    "title": "Smartphones & Tablets"
    },
    {
      "id": 3,
      "title": "Audio & Video"
    },
    {
      "id": 4,
      "title": "Gaming"
    },
  ]
}

For a hook such as useSelect how can I adjust the shape of the object so that the hook understands how to process it correctly?
Was this page helpful?