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.
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?
– Marcos ACR
Yes, it is falling in the catch and returning "Error: Network Error", but as seen in the img the endpoint request returns normally.
– Rodrigo Cassimiro
have you tried this?: async componentDidMount() { Try{ const Response = await listAfps.get('). then( v => { this.setState({ afps: v.data }); } ) }catch(e){ } }
– Marcos ACR
I made that change, it’s still the same problem.
– Rodrigo Cassimiro