How to catch a child object using Axios?

Asked

Viewed 107 times

-1

I’m making a website using React. When I run the GET method, I get the following result banco de dados:

On the front, the code is like this:

import React from 'react'
import axios from 'axios'

export default class ListaTarefas extends React.Component {
  state = {
    tarefas: []
  }

  componentDidMount() {
    axios.get('http://localhost:3004/api/listaTarefas/')
      .then(res => {
        const tarefas = res.data
        console.log(res.data)
        this.setState({ tarefas })
      })
  }

  render() {
    return (
      <ul>
        { this.state.tarefas.map(tarefa => 
        <li key={tarefa._id}> {tarefa.nomeTarefa} </li>)}
      </ul>
    )
  }
}

I can normally take the Filename, complete, etc, but I would like to know how to get the attribute Filename, which has other attributes.

  • did wrong on the line const tarefas = res.data actually is const { tarefas } = res.data; It already solves, it has the name right, but, I can’t remember now are so many names

  • Dude, I tried that and no more results, started giving error in tasks.map also.

1 answer

1


task.subTarefa.nameSub or task.subTarefa[0]. nameSub

  • 1

    thanks, solved!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.