Created
April 27, 2020 21:01
-
-
Save morsh/e420f1e9bf513574413ea127a7af9d34 to your computer and use it in GitHub Desktop.
don't mock around
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface State { | |
dogImageUrl: string; | |
} | |
export class DogPicture extends React.PureComponent<{}, State> { | |
componentDidMount() { | |
const dogService = new DogService(); | |
dogService.getRandomImageUrl() | |
.then(dogImageUrl => this.setState({ dogImageUrl })) | |
} | |
render() { | |
if (!this.state?.dogImageUrl) { | |
return null; | |
} | |
return ( | |
<img src={this.state.dogImageUrl} alt='Dog' data-testid="dog-image" /> | |
) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
export interface IDogService { | |
getRandomImageUrl(): Promise<string>; | |
} | |
export class DogService implements IDogService { | |
async getRandomImageUrl() { | |
const response = await axios.get('https://dog.ceo/api/breeds/image/random'); | |
return response.data.message as string; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment