Download react-query/examples/react/rick-morty/src/Episodes.jsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 931 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/react/rick-morty/src/Episodes.jsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/react/rick-morty/src/Episodes.jsx
-
curl -L -o Episodes.jsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/examples/react/rick-morty/src/Episodes.jsx
931 Bytes
| import React from 'react' | |
| import { Typography, Link } from '@mui/material' | |
| import { Link as RouterLink } from 'react-router-dom' | |
| import { useQuery } from '@tanstack/react-query' | |
| import fetch from './fetch' | |
| export default function Episodes() { | |
| const { data, status } = useQuery({ | |
| queryKey: ['episodes'], | |
| queryFn: () => fetch('https://rickandmortyapi.com/api/episode'), | |
| }) | |
| if (status === 'pending') { | |
| return <p>Loading...</p> | |
| } | |
| if (status === 'error') { | |
| return <p>Error :(</p> | |
| } | |
| return ( | |
| <div> | |
| <Typography variant="h2">Episodes</Typography> | |
| {data.results.map((episode) => ( | |
| <article key={episode.id}> | |
| <Link component={RouterLink} to={`/episodes/${episode.id}`}> | |
| <Typography variant="h6"> | |
| {episode.episode} - {episode.name} <em>{episode.airDate}</em> | |
| </Typography> | |
| </Link> | |
| </article> | |
| ))} | |
| </div> | |
| ) | |
| } | |