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

140
Visualizações
Display individual elements from array in React

Been trying all morning and for the life of me I can't get individual array data to be displayed from my API. I am trying to display one body of text from an array at a time, and can only get it to output all at once. Had it working when the data was in JSON format but now its in an array I'm struggling to make it work.

My code:

 componentDidMount() {
    axios
      .get(
        "API_DATA"
      )
      .then((res) => {
        let data = res.data
        this.setState({ data, loading: false });
        console.log(data)
      });
  }

  render() {
    if (this.state.loading) {
      return <Loader />
    }
    // return table if loading is false
    // handling error goes with the same logic
    // table will only render if loading is false
    else 
    return (
       this.state.data.data).map((item) => (
          <>
            <p key={item.id}>{item.title}</p>
          </>
        ))
     
    
  }
}

I previously used added [0] or [1] etc to determine which element I wanted to display and this worked very nicely however if I try this.state.data.data[0]).map((item) => ( It states it is not a function.

Expected output of API:

{
    "data": [
        {
            "id": 9,
            "status": "published",
            "body": "TEST1",
            "availability": "internal",
            "title": "Test1",
            "posted_by": "Tester"
        },
        {
            "id": 10,
            "status": "published",
            "body": "TEST",
            "availability": "internal",
            "title": "TEST2",
            "posted_by": "Tester"
        },
about 4 years ago · Juan Pablo Isaza
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