Created
June 5, 2020 15:21
-
-
Save 3nvi/c4e4f2d6d60140b207559e5741e51b34 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
import React from "react"; | |
import { get } from 'lodash'; | |
import { useParams, Link } from "react-router-dom"; | |
import useQuery from './useQuery'; | |
import Page404 from "./Page404"; | |
const DogPage = () => { | |
const { breed } = useParams(); | |
const { data, statusCode } = useQuery({ | |
url: `https://dog.ceo/api/breed/${breed}/images/random` | |
}); | |
if (statusCode === 404) { | |
return <Page404 /> | |
} | |
const imageSrc = get(data, "message"); | |
return ( | |
<div> | |
<div> | |
<Link to="/">back</Link> | |
</div> | |
{!imageSrc && <p>Loading...</p>} | |
{imageSrc && <img alt={`A nice ${breed}`} src={imageSrc} height={200} />} | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment