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

225
Visualizações
Object showing empty but has values? Undefined when mapping

I have an object that I'm filling with some information, when logging the object it shows empty but when opening the object up in chrome, it shows that correct details are filled.

This is what the logs look like

closed: closed obj

open: opened obj

When mapping the object I get the following error Cannot read properties of undefined (reading 'map')

Am I doing something wrong?

here is my code:

function Admin() {
  const [loading, setLoading] = useState<boolean>(false);
  const [webAppTypes, setWebAppTypes] = useState<IWebAppType[]>([]);

  var nm: { [key: number]: Array<IWebApp> } = {};

  useEffect(() => {
    setLoading(true);
    fetch(`${process.env.REACT_APP_API_URL}/webapptype/read_all`, {
      headers: headers,
    })
      .then((data) => {
        setLoading(false);
        return data.json();
      })
      .then((res) => {
        setWebAppTypes(res);
      });
  }, []);

  useEffect(() => {
    webAppTypes.map((a) => {
      fetch(`${process.env.REACT_APP_API_URL}/webapp/read_all/${a.id}`, {
        headers: headers,
      })
        .then((data) => {
          return data.json();
        })
        .then((data) => {
          let arr: Array<IWebApp> = [];
          data.map((a: any) => {
            const model: IWebApp = {
              id: a.id,
              name: a.name,
              description: a.description,
              link: a.link,
              image: a.image,
            };
            arr.push(model);
          });
          nm[a.id] = arr;
        });
    });
    console.log(nm);
  }, [webAppTypes]);

  if (loading) return <h6>Loading...</h6>;

  return (
    <div style={{ padding: 100, paddingLeft: 200, width: 500 }}>
      {webAppTypes.map((a) => {
        return (
          <Accordion key={a.id}>
            <AccordionSummary
              expandIcon={<ExpandMoreIcon />}
              aria-controls="panel1a-content"
              id="panel1a-header"
            >
              <Typography>{a.name}</Typography>
            </AccordionSummary>
            <AccordionDetails>
              <>
                {nm[a.id].map((t) => {
                  return <Typography>{t.id}</Typography>;
                })}
              </>
            </AccordionDetails>
          </Accordion>
        );
      })}
    </div>
  );
}

Any help would be appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

@new_ting it appears you are returning the data as json and trying to map from there. You need to parse the json before mapping it, mapping it as json won't work.

  return data.json(); //this is the json I was talking about
    })
    .then((data) => {
      let arr: Array<IWebApp> = [];
      data.map((a: any) => {//here is the mapping being done to the json string
about 4 years ago · Juan Pablo Isaza 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