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 "@tanstack/react-query";
5import fetch from "./fetch";
6β
7export default function Characters() {
8 const { status, data } = useQuery({
9 queryKey: ["characters"],
10 queryFn: () => fetch("https://rickandmortyapi.com/api/character/"),
11 });
12β
13 if (status === "loading") return <p>Loading...</p>;
14 if (status === "error") return <p>Error :(</p>;
15β
16 console.info(data);
17β
18 return (
19 <div>
20 <Typography variant="h2">Characters</Typography>
21 {data.results.map((person) => {
22 return (
23 <article key={person.id} style={{ margin: "16px 0 0" }}>
24 <Link component={RouterLink} to={`/characters/${person.id}`}>
25 <Typography variant="h6">
26 {person.name} - {person.gender}: {person.species}
27 </Typography>
28 </Link>
29 </article>
30 );
31 })}
32 </div>
33 );
34}