4466ba436b
## Description This PR ensures that the default prettier config is used for examples and templates. This config is compatible with `prettier@3` as well (upgrading prettier is bigger change that can be a future PR). ## Changes - Updated `.prettierrc.json` in root with `"trailingComma": "es5"` (will be needed upgrading to prettier@3) - Added `examples/.prettierrc.json` with default config (this will change every example) - Added `packages/create-next-app/templates/.prettierrc.json` with default config (this will change every template) ## Related - Fixes #54402 - Closes #54409
60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
import { useRouter } from "next/router";
|
|
import useSWR from "swr";
|
|
import type { Person, ResponseError } from "../../interfaces";
|
|
|
|
const fetcher = async (url: string) => {
|
|
const res = await fetch(url);
|
|
const data = await res.json();
|
|
|
|
if (res.status !== 200) {
|
|
throw new Error(data.message);
|
|
}
|
|
return data;
|
|
};
|
|
|
|
export default function PersonPage() {
|
|
const { query } = useRouter();
|
|
const { data, error, isLoading, isValidating } = useSWR<
|
|
Person,
|
|
ResponseError
|
|
>(() => (query.id ? `/api/people/${query.id}` : null), fetcher);
|
|
|
|
if (error) return <div>{error.message}</div>;
|
|
if (isLoading) return <div>Loading...</div>;
|
|
if (!data) return null;
|
|
|
|
return (
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Height</th>
|
|
<th>Mass</th>
|
|
<th>Hair color</th>
|
|
<th>Skin color</th>
|
|
<th>Eye color</th>
|
|
<th>Gender</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
{isValidating ? (
|
|
<td colSpan={7} align="center">
|
|
Validating...
|
|
</td>
|
|
) : (
|
|
<>
|
|
<td>{data.name}</td>
|
|
<td>{data.height}</td>
|
|
<td>{data.mass}</td>
|
|
<td>{data.hair_color}</td>
|
|
<td>{data.skin_color}</td>
|
|
<td>{data.eye_color}</td>
|
|
<td>{data.gender}</td>
|
|
</>
|
|
)}
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
);
|
|
}
|