I am new to react and I am stuck on a specific project. The thing is, I have api_url in this.props received from the parent component. And in this child component I want to use api_url to get some data using JSON.
In the parent component, I have:
Repositories api_url={this.state.objs.repos_url}
and in the child component I want something like:
componentDidMount() { $.getJSON(this.props.api_url, function(json) { for (var i = 0; i < json.length; i++) { var each_repo = json[i] console.log(each_repo["name"]); } }); }
so I need the corresponding api_url in the URL section $.getJSON .
Is there a way to access this.props in componentDidMount or is there some other way to achieve the same results?
Another thing related to this is that I also use the $.getJSON call in the ComponentDidMount parent component.
Thanks in advance.
source share