loading...

Trying to consume an API using axios

rudsonramon profile image Rudson Ramon Rodrigues ・1 min read

I am trying to use axios in my react page, but I could not get the result of my API on the screen. There is something wrong?

import React from "react";
import axios from "axios";

export default class QuestionList extends React.Component {

state = {

persons: []

};

componentDidMount() {

axios.get(http://localhost:8070/api/v1/surveys).then(res => {

console.log(res);

this.setState({ person: res.data });

});

}

render() {

return (

    {this.state.persons.map(person => (
  • {person.question}
  • ))}


);

}

}

Discussion

markdown guide