Skip to content
This repository has been archived by the owner on Aug 17, 2024. It is now read-only.

Question 4& 7 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions src/components/Breeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,49 @@ import React from "react";
import "./Breeds.css";

class Breeds extends React.Component {
constructor(props) {
super(props);
this.state = {
listOfBreeds: [],
imgSrc: [],
isChanged: false
};
}
componentDidMount() {
fetch("https://dog.ceo/api/breeds/list/all")
.then((res) => res.json())
.then((data) => {
this.setState({
listOfBreeds: Object.keys(data.message)
});
});
}

changeHandler = (event) => {
fetch("https://dog.ceo/api/breed/" + event.target.value + "/images/random")
.then((res) => res.json())
.then((data) => {
this.setState({
imgSrc: data.message
});
});
};
render() {
return (
<div className="Breeds">
<h2 className="Breeds-title">Select a Breed</h2>
<p>
<select className="Breeds-select">
<option>beagle</option>
<option>bluetick</option>
<option>bullterrier-staffordshire</option>
<option>malinois</option>
<option>wolfhound-irish</option>
</select>
<div>
<select className="Breeds-select" onChange={this.changeHandler}>
{this.state.listOfBreeds.map((dog) => (
<option>{dog}</option>
))}
</select>
</div>
</p>
<img className="Breeds-image" src="http://via.placeholder.com/300x300" />

<img className="Breeds-image" onChange={this.changeHandler} src={this.state.imgSrc} />

<p>
<button className="Breeds-button">Show me more!</button>
</p>
Expand Down