So, I started working in react and got stuck, when I was trying to render a component dynamically into the view, from a JSON file online. I am using axios.get to get information from JSON but is unable to render it properly.
any help is highly appreciated!!
Json : Json Link used in the project
import React, { Component } from "react";
import axios from "axios";
class Lessons extends Component {
state = {
Questions: []
};
async componentDidMount() {
const { data: Questions } = await axios.get(
"https://api.myjson.com/bins/1axyok"
);
this.setState({ Questions });
console.log(Questions);
console.log(this.state.Questions.QuestionID);
}
render() {
return (
<h4 style={{ padding: "20px" }}>{this.state.Questions.QuestionID}</h4>
);
}
}
The value for this.state.Questions.QuestionID (an example) is not getting rendered into the view
the part where it was supposed to render (below the question) QuestionID is blankcheck screenshot of the project here
So i tried to make two logs in the console (check code) and got the following output. The console.log for the object => console.log(Questions) gives result. another one, shows undefined check image of console.log here
Questionsis an array. Therefore it doesn't have a propertyQuestionID.