Fetching Data from an API with props

De enunpimpam
Saltar a: navegación, buscar
constructor(props) {
    super(props);
    this.state = {
      href: "",
      items: [],
      total_hits: "",
  };
}

componentDidMount() {

  fetchFoto = async () => {
    const respuesta = await fetch(
      'https://images-api.nasa.gov/search?q=curiosity&page=5'
    );
    const responseData = await respuesta.json();
    this.setState({
      href: responseData.collection.href,
      items: responseData.collection.items,
      total_hits: responseData.collection.metadata.total_hits,
    });
  };