{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "complex-component", "title": "Complex Component", "description": "A complex component showing hooks, libs and components.", "registryDependencies": [ "card" ], "files": [ { "path": "registry/new-york/blocks/complex-component/page.tsx", "content": "import { cache } from \"react\";\nimport { PokemonCard } from \"@/registry/new-york/blocks/complex-component/components/pokemon-card\";\nimport { getPokemonList } from \"@/registry/new-york/blocks/complex-component/lib/pokemon\";\n\nconst getCachedPokemonList = cache(getPokemonList);\n\nexport default async function Page() {\n\tconst pokemons = await getCachedPokemonList({ limit: 12 });\n\n\tif (!pokemons) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t
\n\t\t\t
\n\t\t\t\t{pokemons.results.map((p) => (\n\t\t\t\t\t\n\t\t\t\t))}\n\t\t\t
\n\t\t
\n\t);\n}\n", "type": "registry:page", "target": "app/pokemon/page.tsx" }, { "path": "registry/new-york/blocks/complex-component/components/pokemon-card.tsx", "content": "import { cache } from \"react\";\nimport { PokemonImage } from \"@/registry/new-york/blocks/complex-component/components/pokemon-image\";\nimport { getPokemon } from \"@/registry/new-york/blocks/complex-component/lib/pokemon\";\nimport { Card, CardContent } from \"@/registry/new-york/ui/card\";\n\nconst cachedGetPokemon = cache(getPokemon);\n\nexport async function PokemonCard({ name }: { name: string }) {\n\tconst pokemon = await cachedGetPokemon(name);\n\n\tif (!pokemon) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t\n\t\t\t\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t
\n\t\t\t\t
{pokemon.name}
\n\t\t\t
\n\t\t
\n\t);\n}\n", "type": "registry:component" }, { "path": "registry/new-york/blocks/complex-component/components/pokemon-image.tsx", "content": "\"use client\";\n\nimport Image from \"next/image\";\nimport { usePokemonImage } from \"@/registry/new-york/blocks/complex-component/hooks/use-pokemon\";\n\nexport function PokemonImage({\n\tname,\n\tnumber,\n}: {\n\tname: string;\n\tnumber: number;\n}) {\n\tconst imageUrl = usePokemonImage(number);\n\n\tif (!imageUrl) {\n\t\treturn null;\n\t}\n\n\treturn {name};\n}\n", "type": "registry:component" }, { "path": "registry/new-york/blocks/complex-component/lib/pokemon.ts", "content": "import { z } from \"zod\";\n\nexport async function getPokemonList({ limit = 10 }: { limit?: number }) {\n\ttry {\n\t\tconst response = await fetch(\n\t\t\t`https://pokeapi.co/api/v2/pokemon?limit=${limit}`,\n\t\t);\n\t\treturn z\n\t\t\t.object({\n\t\t\t\tresults: z.array(z.object({ name: z.string() })),\n\t\t\t})\n\t\t\t.parse(await response.json());\n\t} catch (error) {\n\t\tconsole.error(error);\n\t\treturn null;\n\t}\n}\n\nexport async function getPokemon(name: string) {\n\ttry {\n\t\tconst response = await fetch(`https://pokeapi.co/api/v2/pokemon/${name}`);\n\n\t\tif (!response.ok) {\n\t\t\tthrow new Error(\"Failed to fetch pokemon\");\n\t\t}\n\n\t\treturn z\n\t\t\t.object({\n\t\t\t\tname: z.string(),\n\t\t\t\tid: z.number(),\n\t\t\t\tsprites: z.object({\n\t\t\t\t\tfront_default: z.string(),\n\t\t\t\t}),\n\t\t\t\tstats: z.array(\n\t\t\t\t\tz.object({\n\t\t\t\t\t\tbase_stat: z.number(),\n\t\t\t\t\t\tstat: z.object({\n\t\t\t\t\t\t\tname: z.string(),\n\t\t\t\t\t\t}),\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t})\n\t\t\t.parse(await response.json());\n\t} catch (error) {\n\t\tconsole.error(error);\n\t\treturn null;\n\t}\n}\n", "type": "registry:lib" }, { "path": "registry/new-york/blocks/complex-component/hooks/use-pokemon.ts", "content": "\"use client\";\n\n// Totally unnecessary hook, but it's a good example of how to use a hook in a custom registry.\n\nexport function usePokemonImage(number: number) {\n\treturn `https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/${number}.png`;\n}\n", "type": "registry:hook" } ], "type": "registry:component" }