What I am trying to do grab json data to render it as an element. Here is what I have, but this.images continues to come up empty(and undefined/null if I don't set it at the top.
import React, { Component } from 'react';
import axios from 'axios';
export default class Grid extends Component {
constructor(props) {
super(props);
this.images = [];
}
componentWillMount() {
axios.get('grid-config.json')
.then((res) => {
this.setImageArray(res.data);
});
}
setImageArray(imageArray) {
let newArray = [];
for(let i = 0; i < imageArray.length; i++) {
newArray.push(imageArray[i]);
}
this.images = newArray;
}
render() {
const postData = this.props.images;
console.log(this.images);
return (
<div>
hello
</div>
);
}
}