mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-20 09:01:19 +00:00
23
apps/waitlist-website/app/chat/use-fake-streaming.ts
Normal file
23
apps/waitlist-website/app/chat/use-fake-streaming.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { useEffect, useMemo, useState } from "react"
|
||||
|
||||
export function useFakeStreaming(fullContent: string) {
|
||||
const [currentContent, setCurrentContent] = useState("")
|
||||
const [isStreaming, setIsStreaming] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
const words = fullContent.split(" ")
|
||||
|
||||
let i = 0
|
||||
const id = setInterval(() => {
|
||||
if (i > words.length) {
|
||||
setIsStreaming(false)
|
||||
clearInterval(id)
|
||||
} else {
|
||||
setCurrentContent(words.slice(0, i).join(" ") + " ")
|
||||
i++
|
||||
}
|
||||
}, 20)
|
||||
}, [fullContent])
|
||||
|
||||
return useMemo(() => ({ currentContent, isStreaming }), [currentContent, isStreaming])
|
||||
}
|
||||
Reference in New Issue
Block a user