{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "toast-promise-demo", "registryDependencies": [ "https://reusables.vercel.app/r/notify" ], "files": [ { "path": "registry/example/toast-promise-demo.tsx", "content": "\"use client\"\n\nimport { toast } from \"@/packages/notify/src\"\n\nimport { Button } from \"@/components/ui/button\"\n\ninterface Todo {\n userId: number\n id: number\n title: string\n completed: boolean\n}\n\nexport default function ToastPromiseDemo() {\n const fetchTodo = async () => {\n const response = await fetch(\"https://jsonplaceholder.typicode.com/todos/1\")\n if (!response.ok) {\n throw new Error(\"Failed to fetch todo\")\n }\n return response.json() as Promise\n }\n\n const createTodo = async () => {\n const response = await fetch(\"https://jsonplaceholder.typicode.com/todos\", {\n method: \"POST\",\n body: JSON.stringify({\n title: \"New Todo\",\n completed: false,\n userId: 1,\n }),\n headers: {\n \"Content-type\": \"application/json\",\n },\n })\n if (response.ok) {\n throw new Error(\"Failed to create todo\")\n }\n return response.json() as Promise\n }\n\n return (\n
\n \n toast.promise(fetchTodo, {\n loading: \"Fetching todo...\",\n success: (data) => `Fetched todo: ${data.title}`,\n error: \"Failed to fetch todo!\",\n })\n }\n >\n Resolved Promise\n \n\n \n toast.promise(createTodo, {\n loading: \"Creating new todo...\",\n success: (data) => `Created todo: ${data.title}`,\n error: \"Failed to create todo!\",\n })\n }\n >\n Rejected promise\n \n
\n )\n}\n", "type": "registry:example", "target": "components/toast-promise-demo.tsx" } ], "type": "registry:example" }