# Loader URL: /components/loader --- title: Loader description: A spinning loader component for indicating loading states in AI applications. path: elements/components/loader --- The `Loader` component provides a spinning animation to indicate loading states in your AI applications. It includes both a customizable wrapper component and the underlying icon for flexible usage. ## Installation ## Usage ```tsx import { Loader } from "@/components/ai-elements/loader"; ``` ```tsx ``` ## Usage with AI SDK Build a simple chat app that displays a loader before the response starts streaming by using `status === "submitted"`. Add the following component to your frontend: ```tsx title="app/page.tsx" "use client"; import { Conversation, ConversationContent, ConversationScrollButton } from "@/components/ai-elements/conversation"; import { Message, MessageContent } from "@/components/ai-elements/message"; import { Input, PromptInputTextarea, PromptInputSubmit } from "@/components/ai-elements/prompt-input"; import { Loader } from "@/components/ai-elements/loader"; import { useState } from "react"; import { useChat } from "@ai-sdk/react"; const LoaderDemo = () => { const [input, setInput] = useState(""); const { messages, sendMessage, status } = useChat(); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (input.trim()) { sendMessage({ text: input }); setInput(""); } }; return (
{messages.map((message) => ( {message.parts.map((part, i) => { switch (part.type) { case "text": return
{part.text}
; default: return null; } })}
))} {status === "submitted" && }
setInput(e.currentTarget.value)} className="pr-12" />
); }; export default LoaderDemo; ``` Add the following route to your backend: ```ts title="app/api/chat/route.ts" import { streamText, UIMessage, convertToModelMessages } from "ai"; // Allow streaming responses up to 30 seconds export const maxDuration = 30; export async function POST(req: Request) { const { model, messages }: { messages: UIMessage[]; model: string } = await req.json(); const result = streamText({ model: "openai/gpt-4o", messages: convertToModelMessages(messages), }); return result.toUIMessageStreamResponse(); } ``` ## Features - Clean, modern spinning animation using CSS animations - Configurable size with the `size` prop - Customizable styling with CSS classes - Built-in `animate-spin` animation with proper centering - Exports both `AILoader` wrapper and `LoaderIcon` for flexible usage - Supports all standard HTML div attributes - TypeScript support with proper type definitions - Optimized SVG icon with multiple opacity levels for smooth animation - Uses `currentColor` for proper theme integration - Responsive and accessible design ## Examples ### Different Sizes ### Custom Styling ## Props ### `` ', }, }} />