Diferencia entre revisiones de «Fetching Data from an API with props»
De enunpimpam
(Página creada con «Categoría:React constructor(props) { super(props); this.state = { href: "", items: [], total_hits: "", }; } componentDidMount() { fetch…») |
|||
| Línea 1: | Línea 1: | ||
[[Categoría:React]] | [[Categoría:React]] | ||
| + | <syntaxhighlight lang="js"> | ||
constructor(props) { | constructor(props) { | ||
super(props); | super(props); | ||
| Línea 21: | Línea 22: | ||
total_hits: responseData.collection.metadata.total_hits, | total_hits: responseData.collection.metadata.total_hits, | ||
}); | }); | ||
| − | }; | + | };</syntaxhighlight> |
Revisión actual del 19:54 24 ago 2020
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,
});
};