DEV Community

Rudson Ramon Rodrigues
Rudson Ramon Rodrigues

Posted on

2

Trying to consume an API using axios

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}
  • ))}


);

}

}

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay