0

that's my API, i want to fetch it using axios

[
    {
        "groupType": "Interessegruppe",
        "groups": [
            {
                "id": "c42b0250-375e-4458-8f68-0df8179f889c",
                "name": "Teater",
                "assignmentStrategy": 1
            },
            {
                "id": "0fb94732-2bb1-483b-abbd-858327339ca0",
                "name": "Fotball",
                "assignmentStrategy": 1
            },
            {
                "id": "6b109ab1-5a3e-46b0-b0cc-e2b48d6e2dc6",
                "name": "Foto",
                "assignmentStrategy": 1
            }
        ]
    },

]

I wrote that code

      renderItem={({ item }) => <GroupCard title={item.groupType} subTitle={item.groups.name} />}
      />

and I fetched the groupType, but I can't fetch any of [ id or name]

1
  • 1
    item.groups is an array, so you need to use list rendering (there is no item.groups.name, but there is item.groups[0].name for instance) Commented Jan 20, 2021 at 11:33

1 Answer 1

2

async function loadData() {
    const data = await axios.get(url)
    return data[0].groups;
}

This function would return the groups array with id and name attributes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.