Fetching Data from an API with props
De enunpimpam
Revisión del 19:53 24 ago 2020 de Nacho (discusión | contribuciones) (Página creada con «Categoría:React constructor(props) { super(props); this.state = { href: "", items: [], total_hits: "", }; } componentDidMount() { fetch…»)
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,
});
};