Skip to content

An AI-powered search engine with a generative UI

Update deprecated useChat import and isLoading usage

Yoshiki Miura212d0493cd98
diff --git a/components/related-questions.tsx b/components/related-questions.tsx
index e7cfd628..3d72dcdd 100644
--- a/components/related-questions.tsx
+++ b/components/related-questions.tsx
@@ -1,8 +1,8 @@
'use client'
import { CHAT_ID } from '@/lib/constants'
+import { useChat } from '@ai-sdk/react'
import { JSONValue } from 'ai'
-import { useChat } from 'ai/react'
import { ArrowRight } from 'lucide-react'
import React from 'react'
import { CollapsibleMessage } from './collapsible-message'
@@ -30,9 +30,10 @@ export const RelatedQuestions: React.FC<RelatedQuestionsProps> = ({
isOpen,
onOpenChange
}) => {
- const { isLoading } = useChat({
+ const { status } = useChat({
id: CHAT_ID
})
+ const isLoading = status === 'submitted' || status === 'streaming'
if (!annotations) {
return null
diff --git a/components/search-section.tsx b/components/search-section.tsx
index aaed52e8..caf9ddfc 100644
--- a/components/search-section.tsx
+++ b/components/search-section.tsx
@@ -2,8 +2,8 @@
import { CHAT_ID } from '@/lib/constants'
import type { SearchResults as TypeSearchResults } from '@/lib/types'
+import { useChat } from '@ai-sdk/react'
import { ToolInvocation } from 'ai'
-import { useChat } from 'ai/react'
import { CollapsibleMessage } from './collapsible-message'
import { SearchSkeleton } from './default-skeleton'
import { SearchResults } from './search-results'
@@ -21,9 +21,11 @@ export function SearchSection({
isOpen,
onOpenChange
}: SearchSectionProps) {
- const { isLoading } = useChat({
+ const { status } = useChat({
id: CHAT_ID
})
+ const isLoading = status === 'submitted' || status === 'streaming'
+
const isToolLoading = tool.state === 'call'
const searchResults: TypeSearchResults =
tool.state === 'result' ? tool.result : undefined