Hi!
I have an api in this format:
I’m using strapi in a Nextjs project.
I’m having trouble reading the information contained in “especialidade> nome_especialidade”.
My API:
{
“data”: [
{
“id”: 2,
“attributes”: {
“nome”: “Zeca”,
“createdAt”: “2022-06-01T02:15:59.058Z”,
“updatedAt”: “2022-06-01T02:16:07.769Z”,
“publishedAt”: “2022-06-01T02:16:07.767Z”,
“especialidade”: [
{
“id”: 5,
“nome_especialidade”: “Otorrino”
},
{
“id”: 6,
“nome_especialidade”: “Cirurgião”
}
]
}
}
],
“meta”: {
“pagination”: {
“page”: 1,
“pageSize”: 25,
“pageCount”: 1,
“total”: 1
}
}
}
In my project I have the reading as follows:
const [Alldata, setAlldata] = useState({});
const [nome, setNome] = useState("");
const [especialidade, setEspecialidade] = useState([]);
const [ID, setID] = useState(null);
const getData = async () => {
await fetch("http://localhost:1337/api/............?populate=%2A")
.then((response) => response.json())
.then((json) => setAlldata(json));
};
{ Alldata.data?.map((data) => (
{data.attributes.nome_especialidade}
))
but I don’t configure to list the result of this field “nome_especialidade”
where am i wrong?
Thanks!