axios react
$ npm install axiosimport 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>
)
}
}
import axios from "axios";// Send a POST request
axios({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
}
});$ npm install react-axios// GET request for remote image
axios({
method: 'get',
url: 'http://bit.ly/2mTM3nY',
responseType: 'stream'
})
.then(function(response) {
response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
});
Also in JavaScript:
- node js post multipart/form-data
- transfer data from one component to another angular
- how to find all permutations of an array with javascript
- variables in js
- js string to boolean
- length of list in javascript
- js array to object with keys
- react native gifted chat
- disable input jquery
- sort multidimensional array javascript
- Property 'find' does not exist on type NodeListOf
- submitting login and sign up forms using AJAX
- javascript add day to date
- destruction in javascript
- fullcalendar angular add events
- jquery bind function to multiple events
- render props
- vscode entenstion build
- node load file
- javascript conditional
- turn object to json javascript
- javascript tostring
- Amazon VPC supporting 5 different IP address ranges and i wanted to know how wide those rangers are
- anonymous function javascript