Skip to content

Instantly share code, notes, and snippets.

@3nvi
Created June 5, 2020 15:21
Show Gist options
  • Save 3nvi/c4e4f2d6d60140b207559e5741e51b34 to your computer and use it in GitHub Desktop.
Save 3nvi/c4e4f2d6d60140b207559e5741e51b34 to your computer and use it in GitHub Desktop.
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