markdown-streaming-demo
simple-ai/markdown-streaming-demoFreeExample
simple-ai publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by simple-ai on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://simple-ai.dev/r/markdown-streaming-demo.jsonSource
1"use client";23import { useEffect, useState } from "react";4import { Button } from "@/components/ui/button";5import { MarkdownContent } from "../ui/markdown-content";67export default function MarkdownStreamingDemo() {8 const [content, setContent] = useState("");9 const [isStreaming, setIsStreaming] = useState(false);10 const fullContent = `# The Lost Key11## A Tale of Mystery1213* Sarah woke up to find her favorite golden key missing from its usual spot14* She remembered using it last night to lock her diary15* The search began:16 * Under the bed - nothing but dust17 * In her coat pockets - empty18 * On her desk - just scattered papers1920> "Sometimes what we're looking for is right where we least expect it"2122* As she made her bed, something shiny caught her eye23* The key had slipped between the pages of her book24* With a smile, she realized she'd been using it as a bookmark2526*The End*`;2728 useEffect(() => {29 // Typically you'd use a streaming API to get the content, this is just a demo30 if (!isStreaming) {31 return;32 }3334 let currentIndex = 0;35 const words = fullContent.split(" ");3637 const streamInterval = setInterval(() => {38 if (currentIndex >= words.length) {39 clearInterval(streamInterval);40 setIsStreaming(false);41 return;42 }4344 const nextChunk = words.slice(0, currentIndex + 3).join(" ");45 setContent(nextChunk);46 currentIndex += 3;47 }, 70);4849 return () => clearInterval(streamInterval);50 }, [isStreaming]);5152 const handleStart = () => {53 setContent("");54 setIsStreaming(true);55 };5657 return (58 <div className="space-y-4 w-full max-h-[400px] overflow-y-auto">59 <div className="flex gap-2">60 <Button onClick={handleStart} disabled={isStreaming}>61 {content ? "Restart" : "Start"} Streaming62 </Button>63 </div>64 <div className="p-4 w-full min-h-[200px] border rounded-md overflow-y-auto">65 <MarkdownContent content={content} />66 </div>67 </div>68 );69}
Files it writes
More from simple-ai
All 77 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| chat-input-demo-mentionschat-input-demo-mentions | simple-ai | Examples | Free | no deps | |
| chat-input-demo-simplechat-input-demo-simple | simple-ai | Examples | Free | no deps | |
| chat-input-with-addonschat-input-with-addons | simple-ai | Examples | Free | no deps | |
| chat-message-area-demochat-message-area-demo | simple-ai | Examples | Free | no deps | |
| chat-message-area-demo-alignmentchat-message-area-demo-alignment | simple-ai | Examples | Free | no deps | |
| chat-message-area-demo-streamingchat-message-area-demo-streaming | simple-ai | Examples | Free | no deps | |
| chat-message-demochat-message-demo | simple-ai | Examples | Free | no deps | |
| chat-message-demo-avatar-imagechat-message-demo-avatar-image | simple-ai | Examples | Free | no deps |
