I am trying to make a front-end website using react, and I am using the APIs that NASA has. My main question pertains to the 4 Mars Rovers: Curiosity, Opportunity, Spirit, and Mission Manifest. Each of these Rovers have an API related to them that give out pictures that they have taken, and I handled the first Rover like this:
//App.js
onTermSubmit = async (term) =>{
const response = await MarsPics_Curiosity.get('',{
params:{
earth_date: term,
api_key: 'KEY'
})
this.setState({Marspictures_Curiosity: response.data.photos, MarsDate_Curiosity: term})
}
And I was thinking of make 3 more of these to call the rest of the rover APIs. But then, I kind of realized that it seems kind of redundant and repetitive. So, I was wondering if there is a better way to handle this without making 3 more separate functions?