-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp2.js
51 lines (47 loc) · 1.19 KB
/
App2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import './App.css'
import React from 'react'
export default class FetchDog extends React.Component {
state = {
loading: true,
doggies: [],
}
//link API and define content
async componentDidMount() {
const url = 'https://dog.ceo/api/breeds/list/all'
const response = await fetch(url)
const data = await response.json()
var result = Object.keys(data.message)
result.forEach((breed) => {
if (data.message[breed].length > 0) {
console.log('THE BREEDS')
const subBreeds = data.message[breed]
console.log(subBreeds)
}
})
this.setState({ doggies: result, loading: false, data: data })
}
//check to see if its loading
render() {
if (this.state.loading) {
return <div>loading...</div>
}
if (!this.state.doggies) {
return <div>didn't get a doggies</div>
}
//print out the stuff
return (
<div>
{this.state.doggies.map((breed) => (
<div>
<div>{breed}</div>
{this.state.data.message[breed].map((subBreed) => (
<div>
<div>{subBreed}</div>
</div>
))}
</div>
))}
</div>
)
}
}