OrderMed.js
export default class OrderMed extends Component {
constructor(props){
super(props);
this.state = {
Meds: []
}
}
componentDidMount(){
axios.get("http://localhost:8081/api/v1/ivm/customer/inventory/medicines")
.then(response => {
console.log(response)
})
.then((data) =>{
this.setState({Meds: data});
})
console
{data: {…}, status: 200, statusText: '', headers: {…}, config: {…}, …}
config: {transitional: {…}, transformRequest: Array(1), transformResponse: Array(1), timeout: 0, adapter: ƒ, …}
data:
->medicineList: Array(1)
->0: {name: 'Dolo', type: 'fever', price: 50, sellers: {…}}
length: 1
[[Prototype]]: Array(0)
[[Prototype]]: Object
headers: {connection: 'keep-alive', content-type: 'application/json', date: 'Tue, 05 Jul 2022 18:46:55 GMT', keep-alive: 'timeout=60', transfer-encoding: 'chunked'}
request: XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}
status: 200
statusText: ""
I need to get that medicineList array in the data, .then((data)={this.setState({Meds: data});}) is not working for some reason
CodePudding user response:
You are not returning the value from the first then
:
componentDidMount(){
axios.get("http://localhost:8081/api/v1/ivm/customer/inventory/medicines")
.then(response => {
console.log(response)
return response
})
.then((data) =>{
this.setState({Meds: data});
})
CodePudding user response:
componentDidMount(){
axios.get("http://localhost:8081/api/v1/ivm/customer/inventory/medicines")
.then(response => {
console.log(response)
})
.then((data) =>{
this.setState({Meds: data.data.medicineList});
})
Does this make sense?