best way to use axios in react code example

Example 1: import axios react

import axios from 'axios';

Example 2: axios js and react

import React from 'react';

import axios from 'axios';

export default class PersonList extends React.Component {
  state = {
    persons: []
  }

  componentDidMount() {
    axios.get(`https://jsonplaceholder.typicode.com/users`)
      .then(res => {
        const persons = res.data;
        this.setState({ persons });
      })
  }

  render() {
    return (
      
    { this.state.persons.map(person =>
  • {person.name}
  • )}
) } }

Example 3: axios react

$ npm install react-axios

Tags:

Misc Example