Open History to see the last commit
1import React from "react";
2import { Typography, Link } from "@material-ui/core";
3import { Link as RouterLink } from "react-router-dom";
4import { useQuery } from "react-query";
5import fetch from "./fetch";
6β
7export default function Characters() {
8 const { status, data } = useQuery("characters", () =>
9 fetch("https://rickandmortyapi.com/api/character/")
10 );
11β
12 if (status === "loading") return <p>Loading...</p>;
13 if (status === "error") return <p>Error :(</p>;
14β
15 console.info(data);
16β
17 return (
18 <div>
19 <Typography variant="h2">Characters</Typography>
20 {data.results.map(person => {
21 return (
22 <article key={person.id} style={{ margin: "16px 0 0" }}>
23 <Link component={RouterLink} to={`/characters/${person.id}`}>
24 <Typography variant="h6">
25 {person.name} - {person.gender}: {person.species}
26 </Typography>
27 </Link>
28 </article>
29 );
30 })}
31 </div>
32 );
33}