Last active
September 27, 2020 17:26
-
-
Save simicd/37306ff167f875b0227b57ba9c9fb911 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 DogImageWithButton: FC = () => { | |
/** Fetch image on button click */ | |
const { data, fetchApi } = useFetch<DogImageType>({ | |
url: "https://dog.ceo/api/breed/beagle/images/random", | |
}); | |
const getImage = () => { | |
fetchApi(); | |
}; | |
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