forked from TanStack/query
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCharacters.js
33 lines (29 loc) · 975 Bytes
/
Characters.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React from "react";
import { Typography, Link } from "@material-ui/core";
import { Link as RouterLink } from "react-router-dom";
import { useQuery } from "react-query";
import fetch from "./fetch";
export default function Characters() {
const { status, data } = useQuery("characters", () =>
fetch("https://rickandmortyapi.com/api/character/")
);
if (status === "loading") return <p>Loading...</p>;
if (status === "error") return <p>Error :(</p>;
console.info(data);
return (
<div>
<Typography variant="h2">Characters</Typography>
{data.results.map(person => {
return (
<article key={person.id} style={{ margin: "16px 0 0" }}>
<Link component={RouterLink} to={`/characters/${person.id}`}>
<Typography variant="h6">
{person.name} - {person.gender}: {person.species}
</Typography>
</Link>
</article>
);
})}
</div>
);
}