I am making two GET
requests to two different urls, which return different pieces of data. I am then trying to set the values returned to the value of an array, called artists
.
I am unsure as the best approach to take to combine the values returned from the API calls.
If any more information is required let me know.
One thing I am not 100% sure of is whether the following means that result is an array or not. And also, whether I should use promises in my componentShouldMount
method.
var result = data.result.posts;
this.setState({
artists: result
})
My code is below:
getInitialState: function() {
return {
artists: [],
isLoaded: true
}
},
componentDidMount: function() {
$.get(PostsOneURL, function(data) {
var result = data.result.posts;
this.setState({
artists: result
})
}.bind(this));
$.get(PostsTwoURL, function(data) {
var result = data.result.posts;
this.setState({
artists: result,
isLoaded: true
})
}.bind(this));
}