Created
September 27, 2020 17:22
-
-
Save simicd/865daf136674887b868470e74b93e5e2 to your computer and use it in GitHub Desktop.
This file contains 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
// DogImageWithButton.tsx | |
import React, { FC } from "react"; | |
import { useFetch } from "./useFetch"; | |
type DogImageType = { message: string; status: string }; | |
export const DogImage: FC = () => { | |
/** Fetch image on button click */ | |
const getImage = () => { | |
const data = useFetch<DogImageType>({ | |
url: "https://dog.ceo/api/breed/beagle/images/random", | |
}); | |
}; | |
return ( | |
<> | |
{data ? <img src={data.message} alt="dog"></img> : <div>Loading</div>} | |
<button onClick={() => getImage()}>New Image</button> | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment