Showing 1–9 of 9

TSsrc/lib/fetch-json.ts10 lines
1export async function fetchJson<T>(2  url: string,3  init?: RequestInit4): Promise<T> {5  const response = await fetch(url, init);6  if (!response.ok) {7    throw new Error(`HTTP ${response.status}`);8  }9  return response.json() as Promise<T>;10}
$ npm install @tanstack/react-query
$ pnpm add @tanstack/react-query
$ yarn add @tanstack/react-query
$ bun add @tanstack/react-query
src/config/site.ts+3−2

12 export const siteConfig = {

13− name: "Pixel UI",

14− theme: "light",

13+ name: "Pixel Patterns",

14+ theme: "dark",

15+ locale: "en-US",

16 };

GET/api/v1/users/42200 OK142 ms
{
  "id": 42,
  "name": "Ada Lovelace",
  "roles": ["admin", "editor"],
  "verified": true,
  "lastLogin": null
}

Run npm run dev and open localhost:3000. Press ⌘ K to search, or Shift + ? for all shortcuts. Config lives in next.config.mjs.

✕ Avoid
useEffect(() => {
  setTotal(
    items.reduce(sum, 0)
  );
}, [items]);
✓ Prefer
const total = useMemo(
  () => items.reduce(sum, 0),
  [items]
);