API items do not appear on the screen, only on the console

Asked

Viewed 44 times

0

I need to fill out a table with my API data. I got a get to access the API and tried to put all the items inside an array within my state called "afps" and gave a setState to fill this array with the API values. Somehow in the console it brings me the request of the api, but when I do a console log with the result of the state does not bring me anything.
Imagem da requisição da api
imagem do console log do resultado da state

class ListaAfps extends React.Component {

  constructor() {
    super();
    this.state = {
      afps: []
    }
  }

  async componentDidMount() {
    try{

    const response = await listaAfps.get('');

    this.setState({ afps: response.data });

    }catch(e){

    }
  }
  render() {

    const { afps } = this.state;
    console.log({afps});  
  • You saw if he’s falling in the catch?

  • Yes, it is falling in the catch and returning "Error: Network Error", but as seen in the img the endpoint request returns normally.

  • have you tried this?: async componentDidMount() { Try{ const Response = await listAfps.get('). then( v => { this.setState({ afps: v.data }); } ) }catch(e){ } }

  • I made that change, it’s still the same problem.

No answers

Browser other questions tagged

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