I'm trying to get data from .json file. Nothing appears on the page. Maybe somebody have an idea why? Thanks! This is link on the file https://s3-us-west-2.amazonaws.com/digicode-interview/Q1.json
import React from 'react';
import createReactClass from 'create-react-class';
import ReactDOM from 'react-dom';
import axios from 'axios';
class Data extends React.Component {
constructor(props) {
super(props);
this.state = {
array: []
};
}
componentDidMount(){
axios
.get('https://crossorigin.me/https://s3-us-west-2.amazonaws.com/digicode-interview/Q1.json')
.then(({ data })=> {
this.setState({
array: data.recipes.Ingredients
});
})
.catch((err)=> {})
}
render() {
const child = this.state.array.map((element, index) => {
return <div key={index}>
<p>{ element.data.name }</p>
</div>
});
return <div><div>{ child }</div></div>;
}
}
export default Data;
dataproperty of theresponseallows you access to what you want. In your case, you've useddata, so it'll appear asdata.data.recipes.Ingredients. I'd suggest using({ response }), so it's more accurate of a representation of what you're getting back. Turning it intoresponse.data.recipes.Ingredientsrecipesis array, so you can't access Ingredients likedata.recipes.Ingredients. it should bedata.recipes[index].Ingredients