mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-20 09:01:19 +00:00
24 lines
603 B
TypeScript
24 lines
603 B
TypeScript
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])
|
|
}
|