Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
Mapping through Contentful nested array is not working

I've successfully managed to bring the data back from Contentful but I can't seem to map further into the array. I'm not sure what I'm doing wrong as I'm getting the following error: field.fields.map is not a function

export default function Header({ links }) {
  console.log(links);
  return (
      <div className='header-links'>
        <ul className='flex text-white uppercase tracking-widest font-medium'>
          {links.map((link) => (
            <div key={link.title}>
              {link.links.map((field) => {
                <div>
                  {field.fields.map((singleLink) => (
                    <p>{singleLink.title}</p>
                  ))}
                </div>;
              })}
            </div>
          ))}
        </ul>
      </div>
  );
}

[
  {
    "title": "Header",
    "logo": {},
    "links": [
      {
        "fields": {
          "title": "Home",
          "slug": "/"
        }
      },
      {
        "fields": {
          "title": "Food",
          "slug": "/Food"
        }
      },
    ]
  }
]
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Change it in this way. When you are inside the field, they are already object so you can not map like array anymore

export default function Header({ links }) {
  console.log(links);
  return (
      <div className='header-links'>
        <ul className='flex text-white uppercase tracking-widest font-medium'>
          {links.map((link) => (
            <div key={link.title}>
              {link?.links?.map((field) => (
                <div>
                <p>{field?.fields?.title}</p>
                </div>
              )
            )}
            </div>
          ))}
        </ul>
      </div>
  );
}

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda