Skip to content

Instantly share code, notes, and snippets.

@simicd
Created September 27, 2020 17:22
Show Gist options
  • Save simicd/865daf136674887b868470e74b93e5e2 to your computer and use it in GitHub Desktop.
Save simicd/865daf136674887b868470e74b93e5e2 to your computer and use it in GitHub Desktop.
// 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