install axios react code example
Example 1: import axios
import axios from "axios";
Example 2: import axios react
import axios from 'axios';
Example 3: how to install axios in react
$ npm install axios
Example 4: 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 (
<ul>
{ this.state.persons.map(person => <li>{person.name}</li>)}
</ul>
)
}
}
Example 5: install axios
npm install axios
Example 6: axios library
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>